diff --git a/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java b/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java index 5f8386ba2..2a2ab820a 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java @@ -156,8 +156,9 @@ class InternalHttpClient extends AbstractBasicHttpClient { HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request); wrapper.setParams(params); wrapper.setVirtualHost(virtualHost); - HttpRoute route = determineRoute(target, wrapper, context); - return this.execChain.execute(route, wrapper, setupContext(context), execListner); + HttpContext localcontext = setupContext(context); + HttpRoute route = determineRoute(target, wrapper, localcontext); + return this.execChain.execute(route, wrapper, localcontext, execListner); } catch (HttpException httpException) { throw new ClientProtocolException(httpException); } diff --git a/httpclient/src/main/java/org/apache/http/impl/client/exec/MainClientExec.java b/httpclient/src/main/java/org/apache/http/impl/client/exec/MainClientExec.java index 77f1edd96..ab754a4ea 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/exec/MainClientExec.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/exec/MainClientExec.java @@ -62,6 +62,7 @@ import org.apache.http.conn.routing.BasicRouteDirector; import org.apache.http.conn.routing.HttpRoute; import org.apache.http.conn.routing.HttpRouteDirector; import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.impl.client.HttpAuthenticator; import org.apache.http.impl.client.RequestAbortedException; @@ -453,6 +454,15 @@ public class MainClientExec implements ClientExecChain { } while (step > HttpRouteDirector.COMPLETE); } + private SchemeRegistry getSchemeRegistry(final HttpContext context) { + SchemeRegistry reg = (SchemeRegistry) context.getAttribute( + ClientContext.SCHEME_REGISTRY); + if (reg == null) { + reg = this.connManager.getSchemeRegistry(); + } + return reg; + } + /** * Creates a tunnel to the target server. * The connection must be established to the (last) proxy. @@ -476,8 +486,8 @@ public class MainClientExec implements ClientExecChain { String host = target.getHostName(); int port = target.getPort(); if (port < 0) { - Scheme scheme = connManager.getSchemeRegistry(). - getScheme(target.getSchemeName()); + SchemeRegistry registry = getSchemeRegistry(context); + Scheme scheme = registry.getScheme(target.getSchemeName()); port = scheme.getDefaultPort(); } diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java index 19d40b64a..b94e00020 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java @@ -43,6 +43,7 @@ import org.apache.http.params.HttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.protocol.HttpContext; +import org.apache.http.client.protocol.ClientContext; import org.apache.http.conn.ConnectTimeoutException; import org.apache.http.conn.HttpHostConnectException; import org.apache.http.conn.HttpInetSocketAddress; @@ -137,6 +138,15 @@ public class DefaultClientConnectionOperator implements ClientConnectionOperator return new DefaultClientConnection(); } + private SchemeRegistry getSchemeRegistry(final HttpContext context) { + SchemeRegistry reg = (SchemeRegistry) context.getAttribute( + ClientContext.SCHEME_REGISTRY); + if (reg == null) { + reg = this.schemeRegistry; + } + return reg; + } + public void openConnection( final OperatedClientConnection conn, final HttpHost target, @@ -156,7 +166,8 @@ public class DefaultClientConnectionOperator implements ClientConnectionOperator throw new IllegalStateException("Connection must not be open"); } - Scheme schm = schemeRegistry.getScheme(target.getSchemeName()); + SchemeRegistry registry = getSchemeRegistry(context); + Scheme schm = registry.getScheme(target.getSchemeName()); SchemeSocketFactory sf = schm.getSchemeSocketFactory(); InetAddress[] addresses = resolveHostname(target.getHostName()); @@ -219,7 +230,8 @@ public class DefaultClientConnectionOperator implements ClientConnectionOperator throw new IllegalStateException("Connection must be open"); } - final Scheme schm = schemeRegistry.getScheme(target.getSchemeName()); + SchemeRegistry registry = getSchemeRegistry(context); + Scheme schm = registry.getScheme(target.getSchemeName()); if (!(schm.getSchemeSocketFactory() instanceof SchemeLayeredSocketFactory)) { throw new IllegalArgumentException ("Target scheme (" + schm.getName() + diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java index 4d0c2d177..4960c9aee 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java @@ -37,6 +37,7 @@ import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.protocol.HttpContext; +import org.apache.http.client.protocol.ClientContext; import org.apache.http.conn.routing.HttpRoute; import org.apache.http.conn.routing.HttpRoutePlanner; import org.apache.http.conn.scheme.Scheme; @@ -79,6 +80,15 @@ public class DefaultHttpRoutePlanner implements HttpRoutePlanner { schemeRegistry = schreg; } + private SchemeRegistry getSchemeRegistry(final HttpContext context) { + SchemeRegistry reg = (SchemeRegistry) context.getAttribute( + ClientContext.SCHEME_REGISTRY); + if (reg == null) { + reg = this.schemeRegistry; + } + return reg; + } + public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) @@ -110,7 +120,8 @@ public class DefaultHttpRoutePlanner implements HttpRoutePlanner { final Scheme schm; try { - schm = schemeRegistry.getScheme(target.getSchemeName()); + SchemeRegistry registry = getSchemeRegistry(context); + schm = registry.getScheme(target.getSchemeName()); } catch (IllegalStateException ex) { throw new HttpException(ex.getMessage()); }