hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1414678 [2/4] - in /httpcomponents/httpclient/trunk: fluent-hc/src/main/java/org/apache/http/client/fluent/ httpclient/src/examples/org/apache/http/examples/client/ httpclient/src/main/java/org/apache/http/client/protocol/ httpclient/src/m...
Date Wed, 28 Nov 2012 13:39:48 GMT
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/TargetAuthenticationStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/TargetAuthenticationStrategy.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/TargetAuthenticationStrategy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/TargetAuthenticationStrategy.java Wed Nov 28 13:39:31 2012
@@ -41,6 +41,8 @@ import org.apache.http.client.Authentica
 @Immutable
 public class TargetAuthenticationStrategy extends AuthenticationStrategyImpl {
 
+    public static final TargetAuthenticationStrategy INSTANCE = new TargetAuthenticationStrategy();
+
     public TargetAuthenticationStrategy() {
         super(HttpStatus.SC_UNAUTHORIZED, AUTH.WWW_AUTH, AuthPNames.TARGET_AUTH_PREF);
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java Wed Nov 28 13:39:31 2012
@@ -28,20 +28,15 @@
 package org.apache.http.impl.client.builder;
 
 import java.net.ProxySelector;
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedList;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.HttpResponseInterceptor;
-import org.apache.http.HttpVersion;
 import org.apache.http.annotation.NotThreadSafe;
-import org.apache.http.auth.AuthSchemeFactory;
-import org.apache.http.auth.AuthSchemeRegistry;
+import org.apache.http.auth.AuthSchemeProvider;
 import org.apache.http.client.AuthenticationStrategy;
 import org.apache.http.client.BackoffManager;
 import org.apache.http.client.ConnectionBackoffStrategy;
@@ -61,14 +56,17 @@ import org.apache.http.client.protocol.R
 import org.apache.http.client.protocol.RequestDefaultHeaders;
 import org.apache.http.client.protocol.ResponseContentEncoding;
 import org.apache.http.client.protocol.ResponseProcessCookies;
+import org.apache.http.config.Lookup;
+import org.apache.http.config.RegistryBuilder;
 import org.apache.http.conn.ConnectionKeepAliveStrategy;
 import org.apache.http.conn.HttpClientConnectionManager;
+import org.apache.http.conn.SchemePortResolver;
 import org.apache.http.conn.routing.HttpRoutePlanner;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.cookie.CookieSpecFactory;
-import org.apache.http.cookie.CookieSpecRegistry;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainSocketFactory;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.cookie.CookieSpecProvider;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.NoConnectionReuseStrategy;
 import org.apache.http.impl.auth.BasicSchemeFactory;
@@ -78,34 +76,27 @@ import org.apache.http.impl.auth.NTLMSch
 import org.apache.http.impl.auth.SPNegoSchemeFactory;
 import org.apache.http.impl.client.BasicCookieStore;
 import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
 import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
 import org.apache.http.impl.client.DefaultRedirectStrategy;
 import org.apache.http.impl.client.DefaultUserTokenHandler;
-import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.NoopUserTokenHandler;
 import org.apache.http.impl.client.ProxyAuthenticationStrategy;
 import org.apache.http.impl.client.TargetAuthenticationStrategy;
+import org.apache.http.impl.conn.DefaultRoutePlanner;
+import org.apache.http.impl.conn.DefaultSchemePortResolver;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.impl.conn.DefaultHttpRoutePlanner;
-import org.apache.http.impl.conn.ProxySelectorRoutePlanner;
-import org.apache.http.impl.conn.SchemeRegistryFactory;
+import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
 import org.apache.http.impl.cookie.BestMatchSpecFactory;
 import org.apache.http.impl.cookie.BrowserCompatSpecFactory;
 import org.apache.http.impl.cookie.IgnoreSpecFactory;
 import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
 import org.apache.http.impl.cookie.RFC2109SpecFactory;
 import org.apache.http.impl.cookie.RFC2965SpecFactory;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.params.SyncBasicHttpParams;
-import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.protocol.HttpProcessorBuilder;
 import org.apache.http.protocol.HttpRequestExecutor;
-import org.apache.http.protocol.ImmutableHttpProcessor;
 import org.apache.http.protocol.RequestContent;
 import org.apache.http.protocol.RequestExpectContinue;
 import org.apache.http.protocol.RequestTargetHost;
@@ -136,50 +127,6 @@ import org.apache.http.util.VersionInfo;
  *  <li>http.maxConnections</li>
  * </ul>
  * </p>
- * <p>
- * This class sets up the following parameters if not explicitly set:
- * <ul>
- * <li>Version: HttpVersion.HTTP_1_1</li>
- * <li>ContentCharset: HTTP.DEFAULT_CONTENT_CHARSET</li>
- * <li>NoTcpDelay: true</li>
- * <li>SocketBufferSize: 8192</li>
- * <li>UserAgent: Apache-HttpClient/release (java 1.5)</li>
- * </ul>
- * <p>
- * The following parameters can be used to customize the behavior of {@link HttpClient}
- * produced by this builder:
- * <ul>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#PROTOCOL_VERSION}</li>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#STRICT_TRANSFER_ENCODING}</li>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#USE_EXPECT_CONTINUE}</li>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#WAIT_FOR_CONTINUE}</li>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#USER_AGENT}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#TCP_NODELAY}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_TIMEOUT}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_LINGER}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_REUSEADDR}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#CONNECTION_TIMEOUT}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#STALE_CONNECTION_CHECK}</li>
- *  <li>{@link org.apache.http.conn.params.ConnRoutePNames#FORCED_ROUTE}</li>
- *  <li>{@link org.apache.http.conn.params.ConnRoutePNames#LOCAL_ADDRESS}</li>
- *  <li>{@link org.apache.http.conn.params.ConnRoutePNames#DEFAULT_PROXY}</li>
- *  <li>{@link org.apache.http.cookie.params.CookieSpecPNames#DATE_PATTERNS}</li>
- *  <li>{@link org.apache.http.cookie.params.CookieSpecPNames#SINGLE_COOKIE_HEADER}</li>
- *  <li>{@link org.apache.http.auth.params.AuthPNames#CREDENTIAL_CHARSET}</li>
- *  <li>{@link org.apache.http.client.params.ClientPNames#COOKIE_POLICY}</li>
- *  <li>{@link org.apache.http.client.params.ClientPNames#HANDLE_AUTHENTICATION}</li>
- *  <li>{@link org.apache.http.client.params.ClientPNames#HANDLE_REDIRECTS}</li>
- *  <li>{@link org.apache.http.client.params.ClientPNames#MAX_REDIRECTS}</li>
- *  <li>{@link org.apache.http.client.params.ClientPNames#ALLOW_CIRCULAR_REDIRECTS}</li>
- *  <li>{@link org.apache.http.client.params.ClientPNames#VIRTUAL_HOST}</li>
- *  <li>{@link org.apache.http.client.params.ClientPNames#DEFAULT_HOST}</li>
- *  <li>{@link org.apache.http.client.params.ClientPNames#DEFAULT_HEADERS}</li>
- *  <li>{@link org.apache.http.client.params.ClientPNames#CONN_MANAGER_TIMEOUT}</li>
- * </ul>
  *
  * @since 4.3
  */
@@ -187,34 +134,31 @@ import org.apache.http.util.VersionInfo;
 public class HttpClientBuilder {
 
     private HttpRequestExecutor requestExec;
-    private SchemeLayeredSocketFactory sslSocketFactory;
+    private LayeredConnectionSocketFactory sslSocketFactory;
     private HttpClientConnectionManager connManager;
+    private SchemePortResolver schemePortResolver;
     private ConnectionReuseStrategy reuseStrategy;
     private ConnectionKeepAliveStrategy keepAliveStrategy;
     private AuthenticationStrategy targetAuthStrategy;
     private AuthenticationStrategy proxyAuthStrategy;
     private UserTokenHandler userTokenHandler;
-
     private HttpProcessor httpprocessor;
+
     private LinkedList<HttpRequestInterceptor> requestFirst;
     private LinkedList<HttpRequestInterceptor> requestLast;
     private LinkedList<HttpResponseInterceptor> responseFirst;
     private LinkedList<HttpResponseInterceptor> responseLast;
 
     private HttpRequestRetryHandler retryHandler;
-
     private HttpRoutePlanner routePlanner;
     private RedirectStrategy redirectStrategy;
-
     private ConnectionBackoffStrategy connectionBackoffStrategy;
     private BackoffManager backoffManager;
-
     private ServiceUnavailableRetryStrategy serviceUnavailStrategy;
-    
-    private HttpParams params;
-
-    private Map<String, AuthSchemeFactory> authShemes;
-    private Map<String, CookieSpecFactory> cookieSpecs;
+    private Lookup<AuthSchemeProvider> authSchemeRegistry;
+    private Lookup<CookieSpecProvider> cookieSpecRegistry;
+    private Map<String, AuthSchemeProvider> authShemes;
+    private Map<String, CookieSpecProvider> cookieSpecs;
     private CookieStore cookieStore;
     private CredentialsProvider credentialsProvider;
 
@@ -242,16 +186,24 @@ public class HttpClientBuilder {
         return this;
     }
 
-    public final HttpClientBuilder setSSLSocketFactory(final SchemeLayeredSocketFactory sslSocketFactory) {
+    public final HttpClientBuilder setSSLSocketFactory(
+            final LayeredConnectionSocketFactory sslSocketFactory) {
         this.sslSocketFactory = sslSocketFactory;
         return this;
     }
 
-    public final HttpClientBuilder setConnectionManager(final HttpClientConnectionManager connManager) {
+    public final HttpClientBuilder setConnectionManager(
+            final HttpClientConnectionManager connManager) {
         this.connManager = connManager;
         return this;
     }
 
+    public final HttpClientBuilder setSchemePortResolver(
+            final SchemePortResolver schemePortResolver) {
+        this.schemePortResolver = schemePortResolver;
+        return this;
+    }
+
     public final HttpClientBuilder setMaxConnTotal(int maxConnTotal) {
         this.maxConnTotal = maxConnTotal;
         return this;
@@ -372,11 +324,6 @@ public class HttpClientBuilder {
         return this;
     }
 
-    public final HttpClientBuilder setParams(final HttpParams params) {
-        this.params = params;
-        return this;
-    }
-
     public final HttpClientBuilder setCookieStore(final CookieStore cookieStore) {
         this.cookieStore = cookieStore;
         return this;
@@ -388,21 +335,33 @@ public class HttpClientBuilder {
         return this;
     }
 
+    public final HttpClientBuilder setAuthSchemeRegistry(
+            final Lookup<AuthSchemeProvider> authSchemeRegistry) {
+        this.authSchemeRegistry = authSchemeRegistry;
+        return this;
+    }
+
+    public final HttpClientBuilder setCookieSpecRegistry(
+            final Lookup<CookieSpecProvider> cookieSpecRegistry) {
+        this.cookieSpecRegistry = cookieSpecRegistry;
+        return this;
+    }
+
     public final HttpClientBuilder registerAuthScheme(
-            final String name, final AuthSchemeFactory authSchemeFactory) {
+            final String name, final AuthSchemeProvider authSchemeProvider) {
         if (this.authShemes == null) {
-            this.authShemes = new HashMap<String, AuthSchemeFactory>();
+            this.authShemes = new HashMap<String, AuthSchemeProvider>();
         }
-        this.authShemes.put(name, authSchemeFactory);
+        this.authShemes.put(name, authSchemeProvider);
         return this;
     }
 
     public final HttpClientBuilder registerCookiePolicy(
-            final String name, final CookieSpecFactory cookieSpecFactory) {
+            final String name, final CookieSpecProvider cookieSpecProvider) {
         if (this.cookieSpecs == null) {
-            this.cookieSpecs = new HashMap<String, CookieSpecFactory>();
+            this.cookieSpecs = new HashMap<String, CookieSpecProvider>();
         }
-        this.cookieSpecs.put(name, cookieSpecFactory);
+        this.cookieSpecs.put(name, cookieSpecProvider);
         return this;
     }
 
@@ -447,14 +406,19 @@ public class HttpClientBuilder {
         }
         HttpClientConnectionManager connManager = this.connManager;
         if (connManager == null) {
-            SchemeRegistry schemeRegistry = systemProperties ?
-                    SchemeRegistryFactory.createSystemDefault() :
-                        SchemeRegistryFactory.createDefault();
-            if (sslSocketFactory != null) {
-                schemeRegistry.register(new Scheme("https", 443, sslSocketFactory));
+            LayeredConnectionSocketFactory sslSocketFactory = this.sslSocketFactory;
+            if (sslSocketFactory == null) {
+                if (systemProperties) {
+                    sslSocketFactory = SSLSocketFactory.getSystemSocketFactory();
+                } else {
+                    sslSocketFactory = SSLSocketFactory.getSocketFactory();
+                }
             }
             PoolingHttpClientConnectionManager poolingmgr = new PoolingHttpClientConnectionManager(
-                    schemeRegistry);
+                    RegistryBuilder.<ConnectionSocketFactory>create()
+                        .register("http", PlainSocketFactory.getSocketFactory())
+                        .register("https", sslSocketFactory)
+                        .build());
             if (systemProperties) {
                 String s = System.getProperty("http.keepAlive");
                 if ("true".equalsIgnoreCase(s)) {
@@ -478,34 +442,39 @@ public class HttpClientBuilder {
             if (systemProperties) {
                 String s = System.getProperty("http.keepAlive");
                 if ("true".equalsIgnoreCase(s)) {
-                    reuseStrategy = new DefaultConnectionReuseStrategy();
+                    reuseStrategy = DefaultConnectionReuseStrategy.INSTANCE;
                 } else {
-                    reuseStrategy = new NoConnectionReuseStrategy();
+                    reuseStrategy = NoConnectionReuseStrategy.INSTANCE;
                 }
             } else {
-                reuseStrategy = new DefaultConnectionReuseStrategy();
+                reuseStrategy = DefaultConnectionReuseStrategy.INSTANCE;
             }
         }
         ConnectionKeepAliveStrategy keepAliveStrategy = this.keepAliveStrategy;
         if (keepAliveStrategy == null) {
-            keepAliveStrategy = new DefaultConnectionKeepAliveStrategy();
+            keepAliveStrategy = DefaultConnectionKeepAliveStrategy.INSTANCE;
         }
         AuthenticationStrategy targetAuthStrategy = this.targetAuthStrategy;
         if (targetAuthStrategy == null) {
-            targetAuthStrategy = new TargetAuthenticationStrategy();
+            targetAuthStrategy = TargetAuthenticationStrategy.INSTANCE;
         }
         AuthenticationStrategy proxyAuthStrategy = this.proxyAuthStrategy;
         if (proxyAuthStrategy == null) {
-            proxyAuthStrategy = new ProxyAuthenticationStrategy();
+            proxyAuthStrategy = ProxyAuthenticationStrategy.INSTANCE;
         }
         UserTokenHandler userTokenHandler = this.userTokenHandler;
         if (userTokenHandler == null) {
             if (!connectionStateDisabled) {
-                userTokenHandler = new DefaultUserTokenHandler();
+                userTokenHandler = DefaultUserTokenHandler.INSTANCE;
             } else {
-                userTokenHandler = new NoopUserTokenHandler();
+                userTokenHandler = NoopUserTokenHandler.INSTANCE;
             }
         }
+        SchemePortResolver schemePortResolver = this.schemePortResolver;
+        if (schemePortResolver == null) {
+            schemePortResolver = DefaultSchemePortResolver.INSTANCE;
+        }
+
         ClientExecChain execChain = new MainClientExec(
                 requestExec,
                 connManager,
@@ -519,40 +488,56 @@ public class HttpClientBuilder {
 
         HttpProcessor httpprocessor = this.httpprocessor;
         if (httpprocessor == null) {
-            ListBuilder<HttpRequestInterceptor> reqlb = new ListBuilder<HttpRequestInterceptor>();
-            reqlb.addAll(requestFirst);
-            reqlb.addAll(
+
+            VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client",
+                    HttpClientBuilder.class.getClassLoader());
+            String release = vi != null ? vi.getRelease() : VersionInfo.UNAVAILABLE;
+            String defaultAgent = "Apache-HttpClient/" + release + " (java 1.5)";
+
+            HttpProcessorBuilder b = HttpProcessorBuilder.create();
+            if (requestFirst != null) {
+                for (HttpRequestInterceptor i: requestFirst) {
+                    b.addFirst(i);
+                }
+            }
+            if (responseFirst != null) {
+                for (HttpResponseInterceptor i: responseFirst) {
+                    b.addFirst(i);
+                }
+            }
+            b.addAll(
                     new RequestDefaultHeaders(),
                     new RequestContent(),
                     new RequestTargetHost(),
                     new RequestClientConnControl(),
-                    new RequestUserAgent(),
+                    new RequestUserAgent(defaultAgent),
                     new RequestExpectContinue());
             if (!cookieManagementDisabled) {
-                reqlb.add(new RequestAddCookies());
+                b.add(new RequestAddCookies());
             }
             if (!contentCompressionDisabled) {
-                reqlb.add(new RequestAcceptEncoding());
+                b.add(new RequestAcceptEncoding());
             }
             if (!authCachingDisabled) {
-                reqlb.add(new RequestAuthCache());
+                b.add(new RequestAuthCache());
             }
-            reqlb.addAll(requestLast);
-
-            ListBuilder<HttpResponseInterceptor> reslb = new ListBuilder<HttpResponseInterceptor>();
-            reslb.addAll(responseFirst);
             if (!cookieManagementDisabled) {
-                reslb.add(new ResponseProcessCookies());
+                b.add(new ResponseProcessCookies());
             }
             if (!contentCompressionDisabled) {
-                reslb.add(new ResponseContentEncoding());
+                b.add(new ResponseContentEncoding());
+            }
+            if (requestLast != null) {
+                for (HttpRequestInterceptor i: requestLast) {
+                    b.addLast(i);
+                }
             }
-            reslb.addAll(responseLast);
-            List<HttpRequestInterceptor> reqincps = reqlb.build();
-            List<HttpResponseInterceptor> resincps = reslb.build();
-            httpprocessor = new ImmutableHttpProcessor(
-                    reqincps.toArray(new HttpRequestInterceptor[reqincps.size()]),
-                    resincps.toArray(new HttpResponseInterceptor[resincps.size()]));
+            if (responseLast != null) {
+                for (HttpResponseInterceptor i: responseLast) {
+                    b.addLast(i);
+                }
+            }
+            httpprocessor = b.build();
         }
         execChain = new ProtocolExec(execChain, httpprocessor);
 
@@ -562,7 +547,7 @@ public class HttpClientBuilder {
         if (!automaticRetriesDisabled) {
             HttpRequestRetryHandler retryHandler = this.retryHandler;
             if (retryHandler == null) {
-                retryHandler = new DefaultHttpRequestRetryHandler();
+                retryHandler = DefaultHttpRequestRetryHandler.INSTANCE;
             }
             execChain = new RetryExec(execChain, retryHandler);
         }
@@ -571,17 +556,16 @@ public class HttpClientBuilder {
         HttpRoutePlanner routePlanner = this.routePlanner;
         if (routePlanner == null) {
             if (systemProperties) {
-                routePlanner = new ProxySelectorRoutePlanner(
-                        connManager.getSchemeRegistry(),
-                        ProxySelector.getDefault());
+                routePlanner = new SystemDefaultRoutePlanner(
+                        schemePortResolver, ProxySelector.getDefault());
             } else {
-                routePlanner = new DefaultHttpRoutePlanner(connManager.getSchemeRegistry());
+                routePlanner = new DefaultRoutePlanner(schemePortResolver);
             }
         }
         if (!redirectHandlingDisabled) {
             RedirectStrategy redirectStrategy = this.redirectStrategy;
             if (redirectStrategy == null) {
-                redirectStrategy = new DefaultRedirectStrategy();
+                redirectStrategy = DefaultRedirectStrategy.INSTANCE;
             }
             execChain = new RedirectExec(execChain, routePlanner, redirectStrategy);
         }
@@ -598,35 +582,37 @@ public class HttpClientBuilder {
             execChain = new BackoffStrategyExec(execChain, connectionBackoffStrategy, backoffManager);
         }
 
-        HttpParams params = this.params;
-        if (params == null) {
-            params = new SyncBasicHttpParams();
-            setDefaultHttpParams(params);
-        }
-
-        CookieSpecRegistry cookieSpecRegistry = new CookieSpecRegistry();
-        cookieSpecRegistry.register(CookiePolicy.BEST_MATCH, new BestMatchSpecFactory());
-        cookieSpecRegistry.register(CookiePolicy.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory());
-        cookieSpecRegistry.register(CookiePolicy.NETSCAPE, new NetscapeDraftSpecFactory());
-        cookieSpecRegistry.register(CookiePolicy.RFC_2109, new RFC2109SpecFactory());
-        cookieSpecRegistry.register(CookiePolicy.RFC_2965, new RFC2965SpecFactory());
-        cookieSpecRegistry.register(CookiePolicy.IGNORE_COOKIES, new IgnoreSpecFactory());
-        if (cookieSpecs != null) {
-            for (Map.Entry<String, CookieSpecFactory> entry: cookieSpecs.entrySet()) {
-                cookieSpecRegistry.register(entry.getKey(), entry.getValue());
+        Lookup<AuthSchemeProvider> authSchemeRegistry = this.authSchemeRegistry;
+        if (authSchemeRegistry == null) {
+            RegistryBuilder<AuthSchemeProvider> b = RegistryBuilder.<AuthSchemeProvider>create();
+            b.register(AuthPolicy.BASIC, new BasicSchemeFactory())
+                .register(AuthPolicy.DIGEST, new DigestSchemeFactory())
+                .register(AuthPolicy.NTLM, new NTLMSchemeFactory())
+                .register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory())
+                .register(AuthPolicy.KERBEROS, new KerberosSchemeFactory())
+                .build();
+            if (authShemes != null) {
+                for (Map.Entry<String, AuthSchemeProvider> entry: authShemes.entrySet()) {
+                    b.register(entry.getKey(), entry.getValue());
+                }
             }
+            authSchemeRegistry = b.build();
         }
-
-        AuthSchemeRegistry authSchemeRegistry = new AuthSchemeRegistry();
-        authSchemeRegistry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
-        authSchemeRegistry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
-        authSchemeRegistry.register(AuthPolicy.NTLM, new NTLMSchemeFactory());
-        authSchemeRegistry.register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());
-        authSchemeRegistry.register(AuthPolicy.KERBEROS, new KerberosSchemeFactory());
-        if (authShemes != null) {
-            for (Map.Entry<String, AuthSchemeFactory> entry: authShemes.entrySet()) {
-                authSchemeRegistry.register(entry.getKey(), entry.getValue());
+        Lookup<CookieSpecProvider> cookieSpecRegistry = this.cookieSpecRegistry;
+        if (cookieSpecRegistry == null) {
+            RegistryBuilder<CookieSpecProvider> b = RegistryBuilder.<CookieSpecProvider>create();
+            b.register(CookiePolicy.BEST_MATCH, new BestMatchSpecFactory())
+                .register(CookiePolicy.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
+                .register(CookiePolicy.NETSCAPE, new NetscapeDraftSpecFactory())
+                .register(CookiePolicy.RFC_2109, new RFC2109SpecFactory())
+                .register(CookiePolicy.RFC_2965, new RFC2965SpecFactory())
+                .register(CookiePolicy.IGNORE_COOKIES, new IgnoreSpecFactory());
+            if (cookieSpecs != null) {
+                for (Map.Entry<String, CookieSpecProvider> entry: cookieSpecs.entrySet()) {
+                    b.register(entry.getKey(), entry.getValue());
+                }
             }
+            cookieSpecRegistry = b.build();
         }
 
         CookieStore defaultCookieStore = this.cookieStore;
@@ -646,80 +632,7 @@ public class HttpClientBuilder {
                 cookieSpecRegistry,
                 authSchemeRegistry,
                 defaultCookieStore,
-                defaultCredentialsProvider,
-                params);
-    }
-
-    static class ListBuilder<E> {
-
-        private final LinkedList<E> list;
-        private final Map<Class<?>, E> uniqueClasses;
-
-        ListBuilder() {
-            this.list = new LinkedList<E>();
-            this.uniqueClasses = new HashMap<Class<?>, E>();
-        }
-
-        public void add(final E e) {
-            if (e == null) {
-                return;
-            }
-            E previous = this.uniqueClasses.remove(e.getClass());
-            if (previous != null) {
-                this.list.remove(previous);
-            }
-            this.list.add(e);
-            this.uniqueClasses.put(e.getClass(), e);
-        }
-
-        public void addAll(final Collection<E> c) {
-            if (c == null) {
-                return;
-            }
-            for (E e: c) {
-                add(e);
-            }
-        }
-
-        public void addAll(E... c) {
-            if (c == null) {
-                return;
-            }
-            for (E e: c) {
-                add(e);
-            }
-        }
-
-        public List<E> build() {
-            return new ArrayList<E>(this.list);
-        }
-
-    }
-
-    /**
-     * Saves the default set of HttpParams in the provided parameter.
-     * These are:
-     * <ul>
-     * <li>{@link CoreProtocolPNames#PROTOCOL_VERSION}: 1.1</li>
-     * <li>{@link CoreProtocolPNames#HTTP_CONTENT_CHARSET}: ISO-8859-1</li>
-     * <li>{@link CoreConnectionPNames#TCP_NODELAY}: true</li>
-     * <li>{@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}: 8192</li>
-     * <li>{@link CoreProtocolPNames#USER_AGENT}: Apache-HttpClient/<release> (java 1.5)</li>
-     * </ul>
-     */
-    public static void setDefaultHttpParams(HttpParams params) {
-        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
-        HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name());
-        HttpConnectionParams.setTcpNoDelay(params, true);
-        HttpConnectionParams.setSocketBufferSize(params, 8192);
-
-        // determine the release version from packaged version info
-        final VersionInfo vi = VersionInfo.loadVersionInfo
-            ("org.apache.http.client", HttpClientBuilder.class.getClassLoader());
-        final String release = (vi != null) ?
-            vi.getRelease() : VersionInfo.UNAVAILABLE;
-        HttpProtocolParams.setUserAgent(params,
-                "Apache-HttpClient/" + release + " (java 1.5)");
+                defaultCredentialsProvider);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java Wed Nov 28 13:39:31 2012
@@ -34,7 +34,7 @@ import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.annotation.ThreadSafe;
-import org.apache.http.auth.AuthSchemeRegistry;
+import org.apache.http.auth.AuthSchemeProvider;
 import org.apache.http.auth.AuthState;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.CookieStore;
@@ -43,14 +43,16 @@ import org.apache.http.client.methods.Cl
 import org.apache.http.client.methods.HttpExecutionAware;
 import org.apache.http.client.params.ClientPNames;
 import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.config.Lookup;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.ClientConnectionRequest;
-import org.apache.http.conn.ManagedClientConnection;
 import org.apache.http.conn.HttpClientConnectionManager;
+import org.apache.http.conn.ManagedClientConnection;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.conn.routing.HttpRoutePlanner;
 import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.cookie.CookieSpecRegistry;
+import org.apache.http.cookie.CookieSpecProvider;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.params.DefaultedHttpParams;
 import org.apache.http.params.HttpParams;
@@ -61,15 +63,14 @@ import org.apache.http.protocol.HttpCont
 /**
  * @since 4.3
  */
-@SuppressWarnings("deprecation")
 @ThreadSafe
 class InternalHttpClient extends CloseableHttpClient {
 
     private final ClientExecChain execChain;
     private final HttpClientConnectionManager connManager;
     private final HttpRoutePlanner routePlanner;
-    private final CookieSpecRegistry cookieSpecRegistry;
-    private final AuthSchemeRegistry authSchemeRegistry;
+    private final Lookup<CookieSpecProvider> cookieSpecRegistry;
+    private final Lookup<AuthSchemeProvider> authSchemeRegistry;
     private final CookieStore cookieStore;
     private final CredentialsProvider credentialsProvider;
     private final HttpParams params;
@@ -78,11 +79,10 @@ class InternalHttpClient extends Closeab
             final ClientExecChain execChain,
             final HttpClientConnectionManager connManager,
             final HttpRoutePlanner routePlanner,
-            final CookieSpecRegistry cookieSpecRegistry,
-            final AuthSchemeRegistry authSchemeRegistry,
+            final Lookup<CookieSpecProvider> cookieSpecRegistry,
+            final Lookup<AuthSchemeProvider> authSchemeRegistry,
             final CookieStore cookieStore,
-            final CredentialsProvider credentialsProvider,
-            final HttpParams params) {
+            final CredentialsProvider credentialsProvider) {
         super();
         if (execChain == null) {
             throw new IllegalArgumentException("HTTP client exec chain may not be null");
@@ -100,7 +100,7 @@ class InternalHttpClient extends Closeab
         this.authSchemeRegistry = authSchemeRegistry;
         this.cookieStore = cookieStore;
         this.credentialsProvider = credentialsProvider;
-        this.params = params != null ? params : new SyncBasicHttpParams();
+        this.params = new SyncBasicHttpParams();
     }
 
     private HttpRoute determineRoute(
@@ -118,16 +118,14 @@ class InternalHttpClient extends Closeab
     }
 
     private HttpContext setupContext(final HttpContext localContext) {
-        HttpContext context = localContext != null ? localContext : new BasicHttpContext();
+        HttpClientContext context = HttpClientContext.adapt(
+                localContext != null ? localContext : new BasicHttpContext());
         if (context.getAttribute(ClientContext.TARGET_AUTH_STATE) == null) {
             context.setAttribute(ClientContext.TARGET_AUTH_STATE, new AuthState());
         }
         if (context.getAttribute(ClientContext.PROXY_AUTH_STATE) == null) {
             context.setAttribute(ClientContext.PROXY_AUTH_STATE, new AuthState());
         }
-        if (context.getAttribute(ClientContext.SCHEME_REGISTRY) == null) {
-            context.setAttribute(ClientContext.SCHEME_REGISTRY, this.connManager.getSchemeRegistry());
-        }
         if (context.getAttribute(ClientContext.AUTHSCHEME_REGISTRY) == null) {
             context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
         }
@@ -175,9 +173,10 @@ class InternalHttpClient extends Closeab
     }
 
     public void close() {
-        getConnectionManager().shutdown();
+        connManager.shutdown();
     }
 
+    @SuppressWarnings("deprecation")
     public ClientConnectionManager getConnectionManager() {
 
         return new ClientConnectionManager() {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java Wed Nov 28 13:39:31 2012
@@ -53,6 +53,7 @@ import org.apache.http.client.methods.Cl
 import org.apache.http.client.methods.HttpExecutionAware;
 import org.apache.http.client.params.HttpClientParams;
 import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.client.protocol.RequestClientConnControl;
 import org.apache.http.conn.ConnectionKeepAliveStrategy;
 import org.apache.http.conn.ConnectionRequest;
@@ -61,8 +62,6 @@ import org.apache.http.conn.routing.Basi
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.conn.routing.HttpRouteDirector;
 import org.apache.http.conn.routing.RouteTracker;
-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;
@@ -183,18 +182,22 @@ class MainClientExec implements ClientEx
             throw new IllegalArgumentException("HTTP context may not be null");
         }
 
-        AuthState targetAuthState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
+        HttpClientContext clientContext = HttpClientContext.adapt(context);
+
+        AuthState targetAuthState = clientContext.getTargetAuthState();
         if (targetAuthState == null) {
             targetAuthState = new AuthState();
+            context.setAttribute(ClientContext.TARGET_AUTH_STATE, targetAuthState);
         }
-        AuthState proxyAuthState = (AuthState) context.getAttribute(ClientContext.PROXY_AUTH_STATE);
+        AuthState proxyAuthState = clientContext.getProxyAuthState();
         if (proxyAuthState == null) {
             proxyAuthState = new AuthState();
+            context.setAttribute(ClientContext.PROXY_AUTH_STATE, proxyAuthState);
         }
 
         HttpParams params = request.getParams();
 
-        Object userToken = context.getAttribute(ClientContext.USER_TOKEN);
+        Object userToken = clientContext.getUserToken();
 
         final ConnectionRequest connRequest = connManager.requestConnection(route, userToken);
         if (execAware != null) {
@@ -394,12 +397,12 @@ class MainClientExec implements ClientEx
 
             case HttpRouteDirector.CONNECT_TARGET:
                 this.connManager.connect(
-                        managedConn, route.getTargetHost(), route.getLocalAddress(), context, params);
+                        managedConn, route.getTargetHost(), route.getLocalAddress(), context);
                 tracker.connectTarget(route.isSecure());
                 break;
             case HttpRouteDirector.CONNECT_PROXY:
                 this.connManager.connect(
-                        managedConn, route.getProxyHost(), route.getLocalAddress(), context, params);
+                        managedConn, route.getProxyHost(), route.getLocalAddress(), context);
                 HttpHost proxy  = route.getProxyHost();
                 tracker.connectProxy(proxy, false);
                 break;
@@ -421,7 +424,7 @@ class MainClientExec implements ClientEx
             }   break;
 
             case HttpRouteDirector.LAYER_PROTOCOL:
-                this.connManager.upgrade(managedConn, route.getTargetHost(), context, params);
+                this.connManager.upgrade(managedConn, route.getTargetHost(), context);
                 break;
 
             case HttpRouteDirector.UNREACHABLE:
@@ -438,15 +441,6 @@ class MainClientExec implements ClientEx
         } 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.
@@ -467,20 +461,7 @@ class MainClientExec implements ClientEx
         HttpHost proxy = route.getProxyHost();
         HttpResponse response = null;
 
-        String host = target.getHostName();
-        int port = target.getPort();
-        if (port < 0) {
-            SchemeRegistry registry = getSchemeRegistry(context);
-            Scheme scheme = registry.getScheme(target.getSchemeName());
-            port = scheme.getDefaultPort();
-        }
-
-        StringBuilder buffer = new StringBuilder(host.length() + 6);
-        buffer.append(host);
-        buffer.append(':');
-        buffer.append(Integer.toString(port));
-
-        String authority = buffer.toString();
+        String authority = target.toHostString();
         ProtocolVersion ver = HttpProtocolParams.getVersion(params);
         HttpRequest connect = new BasicHttpRequest("CONNECT", authority, ver);
         connect.setParams(params);
@@ -490,7 +471,7 @@ class MainClientExec implements ClientEx
         for (;;) {
             if (!managedConn.isOpen()) {
                 this.connManager.connect(
-                        managedConn, route.getProxyHost(), route.getLocalAddress(), context, params);
+                        managedConn, route.getProxyHost(), route.getLocalAddress(), context);
             }
 
             connect.removeHeaders(AUTH.PROXY_AUTH_RESP);
@@ -586,8 +567,10 @@ class MainClientExec implements ClientEx
                 target = route.getTargetHost();
             }
             if (target.getPort() < 0) {
-                Scheme scheme = connManager.getSchemeRegistry().getScheme(target);
-                target = new HttpHost(target.getHostName(), scheme.getDefaultPort(), target.getSchemeName());
+                target = new HttpHost(
+                        target.getHostName(),
+                        route.getTargetHost().getPort(),
+                        target.getSchemeName());
             }
             if (this.authenticator.isAuthenticationRequested(target, response,
                     this.targetAuthStrategy, targetAuthState, context)) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java Wed Nov 28 13:39:31 2012
@@ -42,6 +42,7 @@ import org.apache.http.auth.UsernamePass
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpExecutionAware;
 import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.client.utils.URIUtils;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.impl.auth.BasicScheme;
@@ -117,10 +118,13 @@ class ProtocolExec implements ClientExec
         if (context == null) {
             throw new IllegalArgumentException("HTTP context may not be null");
         }
+
+        HttpClientContext clientContext = HttpClientContext.adapt(context);
+
         HttpHost target = route.getTargetHost();
 
         // Get user info from the URI
-        AuthState targetAuthState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
+        AuthState targetAuthState = clientContext.getTargetAuthState();
         if (targetAuthState != null) {
             String userinfo = request.getURI().getUserInfo();
             if (userinfo != null) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java Wed Nov 28 13:39:31 2012
@@ -45,7 +45,7 @@ import org.apache.http.client.methods.Cl
 import org.apache.http.client.methods.HttpExecutionAware;
 import org.apache.http.client.params.ClientPNames;
 import org.apache.http.client.params.HttpClientParams;
-import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.client.utils.URIUtils;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.conn.routing.HttpRoutePlanner;
@@ -106,6 +106,9 @@ class RedirectExec implements ClientExec
         if (context == null) {
             throw new IllegalArgumentException("HTTP context may not be null");
         }
+
+        HttpClientContext clientContext = HttpClientContext.adapt(context);
+
         HttpParams params = request.getParams();
         int maxRedirects = params.getIntParameter(ClientPNames.MAX_REDIRECTS, 100);
         HttpRoute currentRoute = route;
@@ -137,14 +140,12 @@ class RedirectExec implements ClientExec
 
                     // Reset virtual host and auth states if redirecting to another host
                     if (!currentRoute.getTargetHost().equals(newTarget)) {
-                        AuthState targetAuthState = (AuthState) context.getAttribute(
-                                ClientContext.TARGET_AUTH_STATE);
+                        AuthState targetAuthState = clientContext.getTargetAuthState();
                         if (targetAuthState != null) {
                             this.log.debug("Resetting target auth state");
                             targetAuthState.reset();
                         }
-                        AuthState proxyAuthState = (AuthState) context.getAttribute(
-                                ClientContext.PROXY_AUTH_STATE);
+                        AuthState proxyAuthState = clientContext.getProxyAuthState();
                         if (proxyAuthState != null) {
                             AuthScheme authScheme = proxyAuthState.getAuthScheme();
                             if (authScheme != null && authScheme.isConnectionBased()) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java Wed Nov 28 13:39:31 2012
@@ -29,6 +29,7 @@ package org.apache.http.impl.conn;
 
 import java.io.IOException;
 import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.util.Date;
 import java.util.concurrent.TimeUnit;
 
@@ -38,14 +39,21 @@ import org.apache.http.HttpClientConnect
 import org.apache.http.HttpHost;
 import org.apache.http.annotation.GuardedBy;
 import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.config.ConnectionConfig;
+import org.apache.http.config.Lookup;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.config.SocketConfig;
 import org.apache.http.conn.ConnectionRequest;
 import org.apache.http.conn.DnsResolver;
 import org.apache.http.conn.HttpClientConnectionManager;
 import org.apache.http.conn.HttpConnectionFactory;
+import org.apache.http.conn.SchemePortResolver;
 import org.apache.http.conn.SocketClientConnection;
 import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.params.HttpParams;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainSocketFactory;
+import org.apache.http.conn.ssl.SSLSocketFactory;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.LangUtils;
 
@@ -92,26 +100,48 @@ public class BasicHttpClientConnectionMa
     private boolean leased;
 
     @GuardedBy("this")
+    private SocketConfig socketConfig;
+
+    @GuardedBy("this")
+    private ConnectionConfig connConfig;
+
+    @GuardedBy("this")
     private volatile boolean shutdown;
 
+    private static Registry<ConnectionSocketFactory> getDefaultRegistry() {
+        return RegistryBuilder.<ConnectionSocketFactory>create()
+                .register("https", PlainSocketFactory.getSocketFactory())
+                .register("https", SSLSocketFactory.getSocketFactory())
+                .build();
+    }
+
     public BasicHttpClientConnectionManager(
-            final SchemeRegistry schemeRegistry,
-            final DnsResolver dnsResolver,
-            final HttpConnectionFactory<SocketClientConnection> connFactory) {
-        if (schemeRegistry == null) {
-            throw new IllegalArgumentException("Scheme registry may not be null");
-        }
-        this.connectionOperator = new HttpClientConnectionOperator(schemeRegistry, dnsResolver);
+            final Lookup<ConnectionSocketFactory> socketFactoryRegistry,
+            final HttpConnectionFactory<SocketClientConnection> connFactory,
+            final SchemePortResolver schemePortResolver,
+            final DnsResolver dnsResolver) {
+        super();
+        this.connectionOperator = new HttpClientConnectionOperator(
+                socketFactoryRegistry, schemePortResolver, dnsResolver);
         this.connFactory = connFactory != null ? connFactory : DefaultClientConnectionFactory.INSTANCE;
         this.expiry = Long.MAX_VALUE;
+        this.socketConfig = SocketConfig.DEFAULT;
+        this.connConfig = ConnectionConfig.DEFAULT;
     }
 
-    public BasicHttpClientConnectionManager(final SchemeRegistry schemeRegistry) {
-        this(schemeRegistry, null, null);
+    public BasicHttpClientConnectionManager(
+            final Lookup<ConnectionSocketFactory> socketFactoryRegistry,
+            final HttpConnectionFactory<SocketClientConnection> connFactory) {
+        this(socketFactoryRegistry, connFactory, null, null);
+    }
+
+    public BasicHttpClientConnectionManager(
+            final Lookup<ConnectionSocketFactory> socketFactoryRegistry) {
+        this(socketFactoryRegistry, null, null, null);
     }
 
     public BasicHttpClientConnectionManager() {
-        this(SchemeRegistryFactory.createDefault(), null, null);
+        this(getDefaultRegistry(), null, null, null);
     }
 
     @Override
@@ -123,10 +153,6 @@ public class BasicHttpClientConnectionMa
         }
     }
 
-    public SchemeRegistry getSchemeRegistry() {
-        return this.connectionOperator.getSchemeRegistry();
-    }
-
     HttpRoute getRoute() {
         return route;
     }
@@ -135,6 +161,22 @@ public class BasicHttpClientConnectionMa
         return state;
     }
 
+    public synchronized SocketConfig getSocketConfig() {
+        return socketConfig;
+    }
+
+    public synchronized void setSocketConfig(final SocketConfig socketConfig) {
+        this.socketConfig = socketConfig != null ? socketConfig : SocketConfig.DEFAULT;
+    }
+
+    public synchronized ConnectionConfig getConnectionConfig() {
+        return connConfig;
+    }
+
+    public synchronized void setConnectionConfig(final ConnectionConfig connConfig) {
+        this.connConfig = connConfig != null ? connConfig : ConnectionConfig.DEFAULT;
+    }
+
     public final ConnectionRequest requestConnection(
             final HttpRoute route,
             final Object state) {
@@ -210,7 +252,7 @@ public class BasicHttpClientConnectionMa
         this.state = state;
         checkExpiry();
         if (this.conn == null) {
-            this.conn = this.connFactory.create();
+            this.conn = this.connFactory.create(this.connConfig);
         }
         this.leased = true;
         return this.conn;
@@ -266,8 +308,7 @@ public class BasicHttpClientConnectionMa
             final HttpClientConnection conn,
             final HttpHost host,
             final InetAddress local,
-            final HttpContext context,
-            final HttpParams params) throws IOException {
+            final HttpContext context) throws IOException {
         if (conn == null) {
             throw new IllegalArgumentException("Connection may not be null");
         }
@@ -277,14 +318,15 @@ public class BasicHttpClientConnectionMa
         if (conn != this.conn) {
             throw new IllegalArgumentException("Connection not obtained from this manager");
         }
-        this.connectionOperator.connect(this.conn, host, local, context, params);
+        InetSocketAddress localAddress = local != null ? new InetSocketAddress(local, 0) : null;
+        this.connectionOperator.connect(this.conn, host, localAddress,
+                this.connConfig.getConnectTimeout(), this.socketConfig, context);
     }
 
     public void upgrade(
             final HttpClientConnection conn,
             final HttpHost host,
-            final HttpContext context,
-            final HttpParams params) throws IOException {
+            final HttpContext context) throws IOException {
         if (conn == null) {
             throw new IllegalArgumentException("Connection may not be null");
         }
@@ -294,7 +336,7 @@ public class BasicHttpClientConnectionMa
         if (conn != this.conn) {
             throw new IllegalArgumentException("Connection not obtained from this manager");
         }
-        this.connectionOperator.upgrade(this.conn, host, context, params);
+        this.connectionOperator.upgrade(this.conn, host, context);
     }
 
     public synchronized void closeExpiredConnections() {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java Wed Nov 28 13:39:31 2012
@@ -27,7 +27,13 @@
 
 package org.apache.http.impl.conn;
 
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CodingErrorAction;
+
 import org.apache.http.annotation.Immutable;
+import org.apache.http.config.ConnectionConfig;
 import org.apache.http.conn.SocketClientConnection;
 import org.apache.http.conn.HttpConnectionFactory;
 
@@ -39,8 +45,27 @@ public class DefaultClientConnectionFact
 
     public static final DefaultClientConnectionFactory INSTANCE = new DefaultClientConnectionFactory();
 
-    public SocketClientConnection create() {
-        return new SocketClientConnectionImpl(8 * 1024);
+    public SocketClientConnection create(final ConnectionConfig config) {
+        ConnectionConfig cconfig = config != null ? config : ConnectionConfig.DEFAULT;
+        CharsetDecoder chardecoder = null;
+        CharsetEncoder charencoder = null;
+        Charset charset = cconfig.getCharset();
+        CodingErrorAction malformedInputAction = cconfig.getMalformedInputAction() != null ?
+                cconfig.getMalformedInputAction() : CodingErrorAction.REPORT;
+        CodingErrorAction unmappableInputAction = cconfig.getUnmappableInputAction() != null ?
+                cconfig.getUnmappableInputAction() : CodingErrorAction.REPORT;
+        if (charset != null) {
+            chardecoder = charset.newDecoder();
+            chardecoder.onMalformedInput(malformedInputAction);
+            chardecoder.onUnmappableCharacter(unmappableInputAction);
+            charencoder = charset.newEncoder();
+            charencoder.onMalformedInput(malformedInputAction);
+            charencoder.onUnmappableCharacter(unmappableInputAction);
+        }
+        return new SocketClientConnectionImpl(8 * 1024,
+                chardecoder, charencoder,
+                cconfig.getMessageConstraints(),
+                null, null, null, null);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java Wed Nov 28 13:39:31 2012
@@ -60,8 +60,11 @@ import org.apache.http.conn.params.ConnR
  * </ul>
  *
  * @since 4.0
+ *
+ * @deprecated (4.3) use {@link DefaultRoutePlanner}
  */
 @ThreadSafe
+@Deprecated
 public class DefaultHttpRoutePlanner implements HttpRoutePlanner {
 
     /** The scheme registry. */

Copied: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java (from r1414676, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java?p2=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java&r1=1414676&r2=1414678&rev=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java Wed Nov 28 13:39:31 2012
@@ -27,23 +27,17 @@
 
 package org.apache.http.impl.conn;
 
-
 import java.net.InetAddress;
 
-import org.apache.http.annotation.ThreadSafe;
-
 import org.apache.http.HttpException;
 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.annotation.Immutable;
+import org.apache.http.conn.SchemePortResolver;
+import org.apache.http.conn.params.ConnRouteParams;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.conn.routing.HttpRoutePlanner;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-
-import org.apache.http.conn.params.ConnRouteParams;
+import org.apache.http.protocol.HttpContext;
 
 /**
  * Default implementation of an {@link HttpRoutePlanner}. This implementation
@@ -59,76 +53,49 @@ import org.apache.http.conn.params.ConnR
  *  <li>{@link org.apache.http.conn.params.ConnRoutePNames#FORCED_ROUTE}</li>
  * </ul>
  *
- * @since 4.0
+ * @since 4.3
  */
-@ThreadSafe
-public class DefaultHttpRoutePlanner implements HttpRoutePlanner {
+@Immutable
+public class DefaultRoutePlanner implements HttpRoutePlanner {
 
-    /** The scheme registry. */
-    protected final SchemeRegistry schemeRegistry; // class is @ThreadSafe
+    private final SchemePortResolver schemePortResolver;
 
-    /**
-     * Creates a new default route planner.
-     *
-     * @param schreg    the scheme registry
-     */
-    public DefaultHttpRoutePlanner(SchemeRegistry schreg) {
-        if (schreg == null) {
-            throw new IllegalArgumentException
-                ("SchemeRegistry must not be null.");
-        }
-        schemeRegistry = schreg;
+    public DefaultRoutePlanner(final SchemePortResolver schemePortResolver) {
+        super();
+        this.schemePortResolver = schemePortResolver != null ? schemePortResolver :
+            DefaultSchemePortResolver.INSTANCE;
     }
 
-    private SchemeRegistry getSchemeRegistry(final HttpContext context) {
-        SchemeRegistry reg = (SchemeRegistry) context.getAttribute(
-                ClientContext.SCHEME_REGISTRY);
-        if (reg == null) {
-            reg = this.schemeRegistry;
+    public HttpRoute determineRoute(
+            final HttpHost host,
+            final HttpRequest request,
+            final HttpContext context) throws HttpException {
+        if (host == null) {
+            throw new IllegalArgumentException("Target host may not be null");
         }
-        return reg;
-    }
-    
-    public HttpRoute determineRoute(HttpHost target,
-                                    HttpRequest request,
-                                    HttpContext context)
-        throws HttpException {
-
         if (request == null) {
-            throw new IllegalStateException
-                ("Request must not be null.");
+            throw new IllegalArgumentException("Request may not be null");
         }
-
         // If we have a forced route, we can do without a target.
-        HttpRoute route =
-            ConnRouteParams.getForcedRoute(request.getParams());
-        if (route != null)
+        HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
+        if (route != null) {
             return route;
-
+        }
         // If we get here, there is no forced route.
         // So we need a target to compute a route.
+        InetAddress local = ConnRouteParams.getLocalAddress(request.getParams());
+        HttpHost proxy = determineProxy(host, request, context);
 
-        if (target == null) {
-            throw new IllegalStateException
-                ("Target host must not be null.");
-        }
-
-        final InetAddress local =
-            ConnRouteParams.getLocalAddress(request.getParams());
-        final HttpHost proxy =
-            ConnRouteParams.getDefaultProxy(request.getParams());
-
-        final Scheme schm;
-        try {
-            SchemeRegistry registry = getSchemeRegistry(context);
-            schm = registry.getScheme(target.getSchemeName());
-        } catch (IllegalStateException ex) {
-            throw new HttpException(ex.getMessage());
+        HttpHost target;
+        if (host.getPort() <= 0) {
+            target = new HttpHost(
+                    host.getHostName(),
+                    this.schemePortResolver.resolve(host),
+                    host.getSchemeName());
+        } else {
+            target = host;
         }
-        // as it is typically used for TLS/SSL, we assume that
-        // a layered scheme implies a secure connection
-        final boolean secure = schm.isLayered();
-
+        boolean secure = target.getSchemeName().equalsIgnoreCase("https");
         if (proxy == null) {
             route = new HttpRoute(target, local, secure);
         } else {
@@ -137,4 +104,11 @@ public class DefaultHttpRoutePlanner imp
         return route;
     }
 
+    protected HttpHost determineProxy(
+            final HttpHost target,
+            final HttpRequest request,
+            final HttpContext context) throws HttpException {
+        return ConnRouteParams.getDefaultProxy(request.getParams());
+    }
+
 }

Copied: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultSchemePortResolver.java (from r1414676, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultSchemePortResolver.java?p2=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultSchemePortResolver.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java&r1=1414676&r2=1414678&rev=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultSchemePortResolver.java Wed Nov 28 13:39:31 2012
@@ -24,23 +24,34 @@
  * <http://www.apache.org/>.
  *
  */
-
 package org.apache.http.impl.conn;
 
-import org.apache.http.annotation.Immutable;
-import org.apache.http.conn.SocketClientConnection;
-import org.apache.http.conn.HttpConnectionFactory;
+import org.apache.http.HttpHost;
+import org.apache.http.conn.SchemePortResolver;
 
 /**
+ * Default {@link SchemePortResolver}.
+ *
  * @since 4.3
  */
-@Immutable
-public class DefaultClientConnectionFactory implements HttpConnectionFactory<SocketClientConnection> {
+public class DefaultSchemePortResolver implements SchemePortResolver {
 
-    public static final DefaultClientConnectionFactory INSTANCE = new DefaultClientConnectionFactory();
+    public static final DefaultSchemePortResolver INSTANCE = new DefaultSchemePortResolver();
 
-    public SocketClientConnection create() {
-        return new SocketClientConnectionImpl(8 * 1024);
+    public int resolve(final HttpHost host) {
+        if (host == null) {
+            throw new IllegalArgumentException("HTTP host may not be null");
+        }
+        int port = host.getPort();
+        if (port > 0) {
+            return port;
+        } else {
+            if ("https".equalsIgnoreCase(host.getSchemeName())) {
+                return 443;
+            } else {
+                return 80;
+            }
+        }
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java Wed Nov 28 13:39:31 2012
@@ -28,6 +28,9 @@ package org.apache.http.impl.conn;
 
 import java.io.IOException;
 import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
@@ -36,14 +39,17 @@ import java.util.concurrent.TimeoutExcep
 import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpHost;
 import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.config.ConnectionConfig;
+import org.apache.http.config.Lookup;
+import org.apache.http.config.SocketConfig;
 import org.apache.http.conn.ConnectionPoolTimeoutException;
 import org.apache.http.conn.ConnectionRequest;
 import org.apache.http.conn.DnsResolver;
 import org.apache.http.conn.HttpClientConnectionManager;
+import org.apache.http.conn.SchemePortResolver;
 import org.apache.http.conn.SocketClientConnection;
 import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.params.HttpParams;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
 import org.apache.http.pool.ConnPool;
 import org.apache.http.protocol.HttpContext;
 
@@ -61,20 +67,27 @@ abstract class HttpClientConnectionManag
 
     private final ConnPool<HttpRoute, CPoolEntry> pool;
     private final HttpClientConnectionOperator connectionOperator;
+    private final Map<HttpHost, SocketConfig> socketConfigMap;
+    private final Map<HttpHost, ConnectionConfig> connectionConfigMap;
+    private volatile SocketConfig defaultSocketConfig;
+    private volatile ConnectionConfig defaultConnectionConfig;
 
     HttpClientConnectionManagerBase(
             final ConnPool<HttpRoute, CPoolEntry> pool,
-            final SchemeRegistry schemeRegistry,
+            final Lookup<ConnectionSocketFactory> socketFactoryRegistry,
+            final SchemePortResolver schemePortResolver,
             final DnsResolver dnsResolver) {
         super();
         if (pool == null) {
             throw new IllegalArgumentException("Connection pool may nor be null");
         }
-        if (schemeRegistry == null) {
-            throw new IllegalArgumentException("Scheme registry may nor be null");
-        }
         this.pool = pool;
-        this.connectionOperator = new HttpClientConnectionOperator(schemeRegistry, dnsResolver);
+        this.connectionOperator = new HttpClientConnectionOperator(
+                socketFactoryRegistry, schemePortResolver, dnsResolver);
+        this.socketConfigMap = new ConcurrentHashMap<HttpHost, SocketConfig>();
+        this.connectionConfigMap = new ConcurrentHashMap<HttpHost, ConnectionConfig>();
+        this.defaultSocketConfig = SocketConfig.DEFAULT;
+        this.defaultConnectionConfig = ConnectionConfig.DEFAULT;
     }
 
     @Override
@@ -86,10 +99,6 @@ abstract class HttpClientConnectionManag
         }
     }
 
-    public SchemeRegistry getSchemeRegistry() {
-        return this.connectionOperator.getSchemeRegistry();
-    }
-
     protected void onConnectionLeaseRequest(final HttpRoute route, final Object state) {
     }
 
@@ -184,8 +193,7 @@ abstract class HttpClientConnectionManag
             final HttpClientConnection managedConn,
             final HttpHost host,
             final InetAddress local,
-            final HttpContext context,
-            final HttpParams params) throws IOException {
+            final HttpContext context) throws IOException {
         if (managedConn == null) {
             throw new IllegalArgumentException("Connection may not be null");
         }
@@ -194,14 +202,24 @@ abstract class HttpClientConnectionManag
             CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
             conn = entry.getConnection();
         }
-        this.connectionOperator.connect(conn, host, local, context, params);
+        SocketConfig socketConfig = this.socketConfigMap.get(host);
+        if (socketConfig == null) {
+            socketConfig = this.defaultSocketConfig;
+        }
+        ConnectionConfig connConfig = this.connectionConfigMap.get(host);
+        if (connConfig == null) {
+            connConfig = this.defaultConnectionConfig;
+        }
+
+        InetSocketAddress localAddress = local != null ? new InetSocketAddress(local, 0) : null;
+        this.connectionOperator.connect(conn, host, localAddress,
+                connConfig.getConnectTimeout(), socketConfig, context);
     }
 
     public void upgrade(
             final HttpClientConnection managedConn,
             final HttpHost host,
-            final HttpContext context,
-            final HttpParams params) throws IOException {
+            final HttpContext context) throws IOException {
         if (managedConn == null) {
             throw new IllegalArgumentException("Connection may not be null");
         }
@@ -210,7 +228,41 @@ abstract class HttpClientConnectionManag
             CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
             conn = entry.getConnection();
         }
-        this.connectionOperator.upgrade(conn, host, context, params);
+        this.connectionOperator.upgrade(conn, host, context);
+    }
+
+    public SocketConfig getDefaultSocketConfig() {
+        return this.defaultSocketConfig;
+    }
+
+    public void setDefaultSocketConfig(final SocketConfig defaultSocketConfig) {
+        this.defaultSocketConfig = defaultSocketConfig != null ? defaultSocketConfig :
+            SocketConfig.DEFAULT;
+    }
+
+    public ConnectionConfig getDefaultConnectionConfig() {
+        return this.defaultConnectionConfig;
+    }
+
+    public void setDefaultConnectionConfig(final ConnectionConfig defaultConnectionConfig) {
+        this.defaultConnectionConfig = defaultConnectionConfig != null ? defaultConnectionConfig :
+            ConnectionConfig.DEFAULT;
+    }
+
+    public SocketConfig getSocketConfig(final HttpHost host) {
+        return this.socketConfigMap.get(host);
+    }
+
+    public void setSocketConfig(final HttpHost host, final SocketConfig socketConfig) {
+        this.socketConfigMap.put(host, socketConfig);
+    }
+
+    public ConnectionConfig getConnectionConfig(final HttpHost host) {
+        return this.connectionConfigMap.get(host);
+    }
+
+    public void setConnectionConfig(final HttpHost host, final ConnectionConfig connectionConfig) {
+        this.connectionConfigMap.put(host, connectionConfig);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java Wed Nov 28 13:39:31 2012
@@ -37,17 +37,18 @@ import org.apache.commons.logging.LogFac
 import org.apache.http.HttpHost;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.config.Lookup;
+import org.apache.http.config.SocketConfig;
 import org.apache.http.conn.ConnectTimeoutException;
 import org.apache.http.conn.DnsResolver;
 import org.apache.http.conn.HttpClientConnectionManager;
 import org.apache.http.conn.HttpHostConnectException;
-import org.apache.http.conn.HttpInetSocketAddress;
+import org.apache.http.conn.SchemePortResolver;
 import org.apache.http.conn.SocketClientConnection;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SchemeSocketFactory;
-import org.apache.http.params.HttpParams;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainSocketFactory;
 import org.apache.http.protocol.HttpContext;
 
 @Immutable
@@ -55,33 +56,31 @@ class HttpClientConnectionOperator {
 
     private final Log log = LogFactory.getLog(HttpClientConnectionManager.class);
 
-    private final SchemeRegistry schemeRegistry;
+    private final Lookup<ConnectionSocketFactory> socketFactoryRegistry;
+    private final SchemePortResolver schemePortResolver;
     private final DnsResolver dnsResolver;
 
     HttpClientConnectionOperator(
-            final SchemeRegistry schemeRegistry,
+            final Lookup<ConnectionSocketFactory> socketFactoryRegistry,
+            final SchemePortResolver schemePortResolver,
             final DnsResolver dnsResolver) {
         super();
-        if (schemeRegistry == null) {
-            throw new IllegalArgumentException("Scheme registry may nor be null");
+        if (socketFactoryRegistry == null) {
+            throw new IllegalArgumentException("Socket factory registry may nor be null");
         }
-        this.schemeRegistry = schemeRegistry;
-        this.dnsResolver = dnsResolver != null ? dnsResolver : SystemDefaultDnsResolver.INSTANCE;
+        this.socketFactoryRegistry = socketFactoryRegistry;
+        this.schemePortResolver = schemePortResolver != null ? schemePortResolver :
+            DefaultSchemePortResolver.INSTANCE;
+        this.dnsResolver = dnsResolver != null ? dnsResolver :
+            SystemDefaultDnsResolver.INSTANCE;
     }
 
-    public SchemeRegistry getSchemeRegistry() {
-        return this.schemeRegistry;
-    }
-
-    public DnsResolver getDnsResolver() {
-        return this.dnsResolver;
-    }
-
-    private SchemeRegistry getSchemeRegistry(final HttpContext context) {
-        SchemeRegistry reg = (SchemeRegistry) context.getAttribute(
-                ClientContext.SCHEME_REGISTRY);
+    @SuppressWarnings("unchecked")
+    private Lookup<ConnectionSocketFactory> getSocketFactoryRegistry(final HttpContext context) {
+        Lookup<ConnectionSocketFactory> reg = (Lookup<ConnectionSocketFactory>)
+            context.getAttribute(ClientContext.SOCKET_FACTORY_REGISTRY);
         if (reg == null) {
-            reg = this.schemeRegistry;
+            reg = this.socketFactoryRegistry;
         }
         return reg;
     }
@@ -89,33 +88,40 @@ class HttpClientConnectionOperator {
     public void connect(
             final SocketClientConnection conn,
             final HttpHost host,
-            final InetAddress local,
-            final HttpContext context,
-            final HttpParams params) throws IOException {
-        SchemeRegistry registry = getSchemeRegistry(context);
-        Scheme schm = registry.getScheme(host.getSchemeName());
-        SchemeSocketFactory sf = schm.getSchemeSocketFactory();
-
+            final InetSocketAddress localAddress,
+            final int connectTimeout,
+            final SocketConfig socketConfig,
+            final HttpContext context) throws IOException {
+        Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(context);
+        ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
+        if (sf == null) {
+            throw new IOException("Unsupported scheme: " + host.getSchemeName());
+        }
         InetAddress[] addresses = this.dnsResolver.resolve(host.getHostName());
-        int port = schm.resolvePort(host.getPort());
+        int port = this.schemePortResolver.resolve(host);
         for (int i = 0; i < addresses.length; i++) {
             InetAddress address = addresses[i];
             boolean last = i == addresses.length - 1;
 
-            Socket sock = sf.createSocket(params);
+            Socket sock = sf.createSocket(context);
+            sock.setReuseAddress(socketConfig.isSoReuseAddress());
             conn.bind(sock);
 
-            InetSocketAddress remoteAddress = new HttpInetSocketAddress(host, address, port);
-            InetSocketAddress localAddress = null;
-            if (local != null) {
-                localAddress = new InetSocketAddress(local, 0);
-            }
+            InetSocketAddress remoteAddress = new InetSocketAddress(address, port);
             if (this.log.isDebugEnabled()) {
                 this.log.debug("Connecting to " + remoteAddress);
             }
             try {
-                Socket connsock = sf.connectSocket(sock, remoteAddress, localAddress, params);
-                conn.bind(connsock);
+                sock.setSoTimeout(socketConfig.getSoTimeout());
+                sock = sf.connectSocket(
+                        connectTimeout, sock, host, remoteAddress, localAddress, context);
+                sock.setTcpNoDelay(socketConfig.isTcpNoDelay());
+                sock.setKeepAlive(socketConfig.isSoKeepAlive());
+                int linger = socketConfig.getSoLinger();
+                if (linger >= 0) {
+                    sock.setSoLinger(linger > 0, linger);
+                }
+                conn.bind(sock);
                 return;
             } catch (ConnectException ex) {
                 if (last) {
@@ -136,21 +142,22 @@ class HttpClientConnectionOperator {
     public void upgrade(
             final SocketClientConnection conn,
             final HttpHost host,
-            final HttpContext context,
-            final HttpParams params) throws IOException {
-        SchemeRegistry registry = getSchemeRegistry(context);
-        Scheme schm = registry.getScheme(host.getSchemeName());
-        if (!(schm.getSchemeSocketFactory() instanceof SchemeLayeredSocketFactory)) {
+            final HttpContext context) throws IOException {
+        HttpClientContext clientContext = HttpClientContext.adapt(context);
+        Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(clientContext);
+        ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
+        if (sf == null) {
+            sf = PlainSocketFactory.INSTANCE;
+        }
+        if (!(sf instanceof LayeredConnectionSocketFactory)) {
             throw new IllegalArgumentException
-                ("Target scheme (" + schm.getName() +
-                 ") must have layered socket factory.");
+                ("Target scheme (" + host.getSchemeName() + ") must have layered socket factory");
         }
-        SchemeLayeredSocketFactory lsf = (SchemeLayeredSocketFactory) schm.getSchemeSocketFactory();
-        Socket sock;
+        LayeredConnectionSocketFactory lsf = (LayeredConnectionSocketFactory) sf;
+        Socket sock = conn.getSocket();
         try {
-            int port = schm.resolvePort(host.getPort());
-            sock = lsf.createLayeredSocket(
-                    conn.getSocket(), host.getHostName(), port, params);
+            int port = this.schemePortResolver.resolve(host);
+            sock = lsf.createLayeredSocket(sock, host.getHostName(), port, context);
         } catch (ConnectException ex) {
             throw new HttpHostConnectException(host, ex);
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java Wed Nov 28 13:39:31 2012
@@ -33,9 +33,14 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.HttpClientConnection;
 import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
 import org.apache.http.conn.DnsResolver;
+import org.apache.http.conn.SchemePortResolver;
 import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainSocketFactory;
+import org.apache.http.conn.ssl.SSLSocketFactory;
 import org.apache.http.pool.ConnPoolControl;
 import org.apache.http.pool.PoolStats;
 
@@ -64,37 +69,53 @@ public class PoolingHttpClientConnection
 
     private final CPool pool;
 
+    private static Registry<ConnectionSocketFactory> getDefaultRegistry() {
+        return RegistryBuilder.<ConnectionSocketFactory>create()
+                .register("http", PlainSocketFactory.getSocketFactory())
+                .register("https", SSLSocketFactory.getSocketFactory())
+                .build();
+    }
+
     public PoolingHttpClientConnectionManager() {
-        this(SchemeRegistryFactory.createDefault());
+        this(getDefaultRegistry());
+    }
+
+    public PoolingHttpClientConnectionManager(final long timeToLive, final TimeUnit tunit) {
+        this(getDefaultRegistry(), timeToLive, tunit);
     }
 
-    public PoolingHttpClientConnectionManager(final SchemeRegistry schreg) {
-        this(schreg, -1, TimeUnit.MILLISECONDS);
+    public PoolingHttpClientConnectionManager(
+            final Registry<ConnectionSocketFactory> socketFactoryRegistry) {
+        this(socketFactoryRegistry, -1, TimeUnit.MILLISECONDS);
     }
 
     public PoolingHttpClientConnectionManager(
-            final SchemeRegistry schreg, final DnsResolver dnsResolver) {
-        this(schreg, dnsResolver, -1, TimeUnit.MILLISECONDS);
+            final Registry<ConnectionSocketFactory> socketFactoryRegistry,
+            final DnsResolver dnsResolver) {
+        this(socketFactoryRegistry, null, dnsResolver, -1, TimeUnit.MILLISECONDS);
     }
 
     public PoolingHttpClientConnectionManager(
-            final SchemeRegistry schemeRegistry,
+            final Registry<ConnectionSocketFactory> socketFactoryRegistry,
             final long timeToLive, final TimeUnit tunit) {
-        this(new CPool(2, 20, timeToLive, tunit), schemeRegistry, null);
+        this(new CPool(2, 20, timeToLive, tunit), socketFactoryRegistry, null, null);
     }
 
     public PoolingHttpClientConnectionManager(
-            final SchemeRegistry schemeRegistry,
+            final Registry<ConnectionSocketFactory> socketFactoryRegistry,
+            final SchemePortResolver schemePortResolver,
             final DnsResolver dnsResolver,
             final long timeToLive, final TimeUnit tunit) {
-        this(new CPool(2, 20, timeToLive, tunit), schemeRegistry, dnsResolver);
+        this(new CPool(2, 20, timeToLive, tunit),
+                socketFactoryRegistry, schemePortResolver, dnsResolver);
     }
 
     PoolingHttpClientConnectionManager(
             final CPool pool,
-            final SchemeRegistry schemeRegistry,
+            final Registry<ConnectionSocketFactory> socketFactoryRegistry,
+            final SchemePortResolver schemePortResolver,
             final DnsResolver dnsResolver) {
-        super(pool, schemeRegistry, dnsResolver);
+        super(pool, socketFactoryRegistry, schemePortResolver, dnsResolver);
         this.pool = pool;
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java Wed Nov 28 13:39:31 2012
@@ -68,8 +68,11 @@ import org.apache.http.conn.params.ConnR
  * </ul>
  *
  * @since 4.0
+ *
+ * @deprecated (4.3) use {@link SystemDefaultRoutePlanner}
  */
 @NotThreadSafe // e.g [gs]etProxySelector()
+@Deprecated
 public class ProxySelectorRoutePlanner implements HttpRoutePlanner {
 
     /** The scheme registry. */

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SchemeRegistryFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SchemeRegistryFactory.java?rev=1414678&r1=1414677&r2=1414678&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SchemeRegistryFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SchemeRegistryFactory.java Wed Nov 28 13:39:31 2012
@@ -31,11 +31,15 @@ import org.apache.http.conn.scheme.Plain
 import org.apache.http.conn.scheme.Scheme;
 import org.apache.http.conn.scheme.SchemeRegistry;
 import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.builder.HttpClientBuilder;
 
 /**
  * @since 4.1
+ *
+ * @deprecated (4.3) use {@link HttpClientBuilder}.
  */
 @ThreadSafe
+@Deprecated
 public final class SchemeRegistryFactory {
 
     /**



Mime
View raw message