}
public synchronized void layerProtocol(
final HttpContext context, final HttpParams params) throws IOException {
assertValid();
OperatedClientConnection conn = getWrappedConnection();
RouteTracker tracker = this.entry.getTracker();
if (!tracker.isConnected()) {
throw new IllegalStateException("Connection not open");
}
if (!tracker.isTunnelled()) {
throw new IllegalStateException("Protocol layering without a tunnel not supported");
}
if (tracker.isLayered()) {
throw new IllegalStateException("Multiple protocol layering not supported");
}
HttpHost target = tracker.getTargetHost();
Scheme scheme = this.manager.getSchemeRegistry().getScheme(target);
LayeringStrategy layeringStrategy = scheme.getLayeringStrategy();
if (layeringStrategy == null) {
throw new IllegalStateException(scheme.getName() +
" scheme does not provider support for protocol layering");
}
IOSession iosession = this.entry.getIOSession();
SSLIOSession ssliosession = (SSLIOSession) layeringStrategy.layer(iosession);
ssliosession.bind(SSLMode.CLIENT, params);
conn.upgrade(ssliosession);
tracker.layerProtocol(layeringStrategy.isSecure());
}