hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1777768 - in /httpcomponents/httpclient/trunk: httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/ httpclient5-win/src/examples/org/apache/hc/client5/http/examples/client/win/ httpclient5/src/examples/org/apache/hc/clien...
Date Sat, 07 Jan 2017 11:38:46 GMT
Author: olegk
Date: Sat Jan  7 11:38:46 2017
New Revision: 1777768

URL: http://svn.apache.org/viewvc?rev=1777768&view=rev
Log:
Moved connection pool construction logic out of HttpClientBuilder into a separate builder class

Added:
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java   (with props)
Modified:
    httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestStaleWhileRevalidationReleasesConnection.java
    httpcomponents/httpclient/trunk/httpclient5-win/src/examples/org/apache/hc/client5/http/examples/client/win/ClientWinAuth.java
    httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java
    httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomSSL.java
    httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestFutureRequestExecutionService.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/localserver/LocalServerTestBase.java

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestStaleWhileRevalidationReleasesConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestStaleWhileRevalidationReleasesConnection.java?rev=1777768&r1=1777767&r2=1777768&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestStaleWhileRevalidationReleasesConnection.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestStaleWhileRevalidationReleasesConnection.java Sat Jan  7 11:38:46 2017
@@ -36,8 +36,8 @@ import java.util.Locale;
 import org.apache.hc.client5.http.cache.CacheResponseStatus;
 import org.apache.hc.client5.http.cache.HttpCacheContext;
 import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager;
 import org.apache.hc.client5.http.impl.sync.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.sync.HttpClientBuilder;
 import org.apache.hc.client5.http.methods.HttpGet;
 import org.apache.hc.client5.http.protocol.ClientProtocolException;
 import org.apache.hc.core5.http.ClassicHttpRequest;
@@ -96,20 +96,17 @@ public class TestStaleWhileRevalidationR
                 .setSharedCache(true)
                 .build();
 
-        final HttpClientBuilder clientBuilder = CachingHttpClientBuilder.create().setCacheConfig(cacheConfig);
-        clientBuilder.setMaxConnTotal(1);
-        clientBuilder.setMaxConnPerRoute(1);
-
         final RequestConfig config = RequestConfig.custom()
                 .setSocketTimeout(10000)
                 .setConnectTimeout(10000)
                 .setConnectionRequestTimeout(1000)
                 .build();
 
-        clientBuilder.setDefaultRequestConfig(config);
-
-
-        client = clientBuilder.build();
+        client = CachingHttpClientBuilder.create()
+                .setCacheConfig(cacheConfig)
+                .setDefaultRequestConfig(config)
+                .setConnectionManager(new BasicHttpClientConnectionManager())
+                .build();
     }
 
     @After

Modified: httpcomponents/httpclient/trunk/httpclient5-win/src/examples/org/apache/hc/client5/http/examples/client/win/ClientWinAuth.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-win/src/examples/org/apache/hc/client5/http/examples/client/win/ClientWinAuth.java?rev=1777768&r1=1777767&r2=1777768&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-win/src/examples/org/apache/hc/client5/http/examples/client/win/ClientWinAuth.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-win/src/examples/org/apache/hc/client5/http/examples/client/win/ClientWinAuth.java Sat Jan  7 11:38:46 2017
@@ -28,8 +28,8 @@
 package org.apache.hc.client5.http.examples.client.win;
 
 import org.apache.hc.client5.http.impl.sync.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.sync.CloseableHttpResponse;
 import org.apache.hc.client5.http.impl.win.WinHttpClients;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
 import org.apache.hc.client5.http.methods.HttpGet;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java?rev=1777768&r1=1777767&r2=1777768&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java Sat Jan  7 11:38:46 2017
@@ -31,16 +31,20 @@ import java.net.URL;
 import org.apache.hc.client5.http.config.CookieSpecs;
 import org.apache.hc.client5.http.cookie.CookieSpecProvider;
 import org.apache.hc.client5.http.impl.cookie.RFC6265CookieSpecProvider;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
 import org.apache.hc.client5.http.impl.sync.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.sync.HttpClients;
 import org.apache.hc.client5.http.impl.sync.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.sync.HttpClients;
+import org.apache.hc.client5.http.io.HttpClientConnectionManager;
 import org.apache.hc.client5.http.methods.HttpGet;
 import org.apache.hc.client5.http.psl.PublicSuffixMatcher;
 import org.apache.hc.client5.http.psl.PublicSuffixMatcherLoader;
 import org.apache.hc.client5.http.ssl.DefaultHostnameVerifier;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
 import org.apache.hc.core5.http.config.Lookup;
 import org.apache.hc.core5.http.config.RegistryBuilder;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.ssl.SSLContexts;
 
 /**
  * This example demonstrates how to use a custom public suffix list.
@@ -57,17 +61,20 @@ public class ClientCustomPublicSuffixLis
         // Please use the publicsuffix.org URL to download the list no more than once per day !!!
         // Please consider making a local copy !!!
 
-        DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher);
-
         RFC6265CookieSpecProvider cookieSpecProvider = new RFC6265CookieSpecProvider(publicSuffixMatcher);
         Lookup<CookieSpecProvider> cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
                 .register(CookieSpecs.DEFAULT, cookieSpecProvider)
                 .register(CookieSpecs.STANDARD, cookieSpecProvider)
                 .register(CookieSpecs.STANDARD_STRICT, cookieSpecProvider)
                 .build();
-
+        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
+                SSLContexts.createDefault(),
+                new DefaultHostnameVerifier(publicSuffixMatcher));
+        HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
+                .setSSLSocketFactory(sslsf)
+                .build();
         try (CloseableHttpClient httpclient = HttpClients.custom()
-                .setSSLHostnameVerifier(hostnameVerifier)
+                .setConnectionManager(cm)
                 .setDefaultCookieSpecRegistry(cookieSpecRegistry)
                 .build()) {
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomSSL.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomSSL.java?rev=1777768&r1=1777767&r2=1777768&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomSSL.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomSSL.java Sat Jan  7 11:38:46 2017
@@ -30,9 +30,11 @@ import java.io.File;
 
 import javax.net.ssl.SSLContext;
 
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
 import org.apache.hc.client5.http.impl.sync.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.sync.HttpClients;
 import org.apache.hc.client5.http.impl.sync.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.sync.HttpClients;
+import org.apache.hc.client5.http.io.HttpClientConnectionManager;
 import org.apache.hc.client5.http.methods.HttpGet;
 import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
 import org.apache.hc.client5.http.ssl.TrustSelfSignedStrategy;
@@ -51,14 +53,17 @@ public class ClientCustomSSL {
                 .loadTrustMaterial(new File("my.keystore"), "nopassword".toCharArray(),
                         new TrustSelfSignedStrategy())
                 .build();
-        // Allow TLSv1 protocol only
+        // Allow TLSv1.2 protocol only
         SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                 sslcontext,
-                new String[] { "TLSv1" },
+                new String[] { "TLSv1.2" },
                 null,
                 SSLConnectionSocketFactory.getDefaultHostnameVerifier());
-        try (CloseableHttpClient httpclient = HttpClients.custom()
+        HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
                 .setSSLSocketFactory(sslsf)
+                .build();
+        try (CloseableHttpClient httpclient = HttpClients.custom()
+                .setConnectionManager(cm)
                 .build()) {
 
             HttpGet httpget = new HttpGet("https://httpbin.org/");

Modified: httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java?rev=1777768&r1=1777767&r2=1777768&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientWithRequestFuture.java Sat Jan  7 11:38:46 2017
@@ -32,10 +32,12 @@ import java.util.concurrent.ExecutorServ
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
 import org.apache.hc.client5.http.impl.sync.CloseableHttpClient;
 import org.apache.hc.client5.http.impl.sync.FutureRequestExecutionService;
 import org.apache.hc.client5.http.impl.sync.HttpClientBuilder;
 import org.apache.hc.client5.http.impl.sync.HttpRequestFutureTask;
+import org.apache.hc.client5.http.io.HttpClientConnectionManager;
 import org.apache.hc.client5.http.methods.HttpGet;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.core5.concurrent.FutureCallback;
@@ -47,9 +49,13 @@ public class ClientWithRequestFuture {
 
     public static void main(String[] args) throws Exception {
         // the simplest way to create a HttpAsyncClientWithFuture
-        CloseableHttpClient httpclient = HttpClientBuilder.create()
+        HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
                 .setMaxConnPerRoute(5)
-                .setMaxConnTotal(5).build();
+                .setMaxConnTotal(5)
+                .build();
+        CloseableHttpClient httpclient = HttpClientBuilder.create()
+                .setConnectionManager(cm)
+                .build();
         ExecutorService execService = Executors.newFixedThreadPool(5);
         try (FutureRequestExecutionService requestExecService = new FutureRequestExecutionService(
                 httpclient, execService)) {

Added: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java?rev=1777768&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java (added)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java Sat Jan  7 11:38:46 2017
@@ -0,0 +1,211 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.impl.io;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hc.client5.http.DnsResolver;
+import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
+import org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory;
+import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
+import org.apache.hc.core5.http.config.ConnectionConfig;
+import org.apache.hc.core5.http.config.RegistryBuilder;
+import org.apache.hc.core5.http.config.SocketConfig;
+import org.apache.hc.core5.util.TextUtils;
+
+/**
+ * Builder for {@link PoolingHttpClientConnectionManager} instances.
+ * <p>
+ * When a particular component is not explicitly set this class will
+ * use its default implementation. System properties will be taken
+ * into account when configuring the default implementations when
+ * {@link #useSystemProperties()} method is called prior to calling
+ * {@link #build()}.
+ * </p>
+ * <ul>
+ *  <li>ssl.TrustManagerFactory.algorithm</li>
+ *  <li>javax.net.ssl.trustStoreType</li>
+ *  <li>javax.net.ssl.trustStore</li>
+ *  <li>javax.net.ssl.trustStoreProvider</li>
+ *  <li>javax.net.ssl.trustStorePassword</li>
+ *  <li>ssl.KeyManagerFactory.algorithm</li>
+ *  <li>javax.net.ssl.keyStoreType</li>
+ *  <li>javax.net.ssl.keyStore</li>
+ *  <li>javax.net.ssl.keyStoreProvider</li>
+ *  <li>javax.net.ssl.keyStorePassword</li>
+ *  <li>https.protocols</li>
+ *  <li>https.cipherSuites</li>
+ * </ul>
+ *
+ * @since 5.0
+ */
+public class PoolingHttpClientConnectionManagerBuilder {
+
+    private LayeredConnectionSocketFactory sslSocketFactory;
+    private DnsResolver dnsResolver;
+
+    private SocketConfig defaultSocketConfig;
+    private ConnectionConfig defaultConnectionConfig;
+
+    private boolean systemProperties;
+
+    private int maxConnTotal = 0;
+    private int maxConnPerRoute = 0;
+
+    private long connTimeToLive = -1;
+    private TimeUnit connTimeToLiveTimeUnit = TimeUnit.MILLISECONDS;
+    private int validateAfterInactivity = 2000;
+
+    public static PoolingHttpClientConnectionManagerBuilder create() {
+        return new PoolingHttpClientConnectionManagerBuilder();
+    }
+
+    PoolingHttpClientConnectionManagerBuilder() {
+        super();
+    }
+
+    /**
+     * Assigns {@link LayeredConnectionSocketFactory} instance for SSL connections.
+     */
+    public final PoolingHttpClientConnectionManagerBuilder setSSLSocketFactory(
+            final LayeredConnectionSocketFactory sslSocketFactory) {
+        this.sslSocketFactory = sslSocketFactory;
+        return this;
+    }
+
+    /**
+     * Assigns maximum total connection value.
+     */
+    public final PoolingHttpClientConnectionManagerBuilder setMaxConnTotal(final int maxConnTotal) {
+        this.maxConnTotal = maxConnTotal;
+        return this;
+    }
+
+    /**
+     * Assigns maximum connection per route value.
+     */
+    public final PoolingHttpClientConnectionManagerBuilder setMaxConnPerRoute(final int maxConnPerRoute) {
+        this.maxConnPerRoute = maxConnPerRoute;
+        return this;
+    }
+
+    /**
+     * Assigns default {@link SocketConfig}.
+     */
+    public final PoolingHttpClientConnectionManagerBuilder setDefaultSocketConfig(final SocketConfig config) {
+        this.defaultSocketConfig = config;
+        return this;
+    }
+
+    /**
+     * Assigns default {@link ConnectionConfig}.
+     */
+    public final PoolingHttpClientConnectionManagerBuilder setDefaultConnectionConfig(final ConnectionConfig config) {
+        this.defaultConnectionConfig = config;
+        return this;
+    }
+
+    /**
+     * Sets maximum time to live for persistent connections
+     *
+     * @since 4.4
+     */
+    public final PoolingHttpClientConnectionManagerBuilder setConnectionTimeToLive(final long connTimeToLive, final TimeUnit connTimeToLiveTimeUnit) {
+        this.connTimeToLive = connTimeToLive;
+        this.connTimeToLiveTimeUnit = connTimeToLiveTimeUnit;
+        return this;
+    }
+
+    /**
+     * Sets period after inactivity in milliseconds after which persistent
+     * connections must be checked to ensure they are still valid.
+     *
+     * @see org.apache.hc.core5.http.io.HttpClientConnection#isStale()
+     */
+    public final PoolingHttpClientConnectionManagerBuilder setValidateAfterInactivity(final int validateAfterInactivity) {
+        this.validateAfterInactivity = validateAfterInactivity;
+        return this;
+    }
+
+    /**
+     * Assigns {@link DnsResolver} instance.
+     */
+    public final PoolingHttpClientConnectionManagerBuilder setDnsResolver(final DnsResolver dnsResolver) {
+        this.dnsResolver = dnsResolver;
+        return this;
+    }
+
+    /**
+     * Use system properties when creating and configuring default
+     * implementations.
+     */
+    public final PoolingHttpClientConnectionManagerBuilder useSystemProperties() {
+        this.systemProperties = true;
+        return this;
+    }
+
+    private static String[] split(final String s) {
+        if (TextUtils.isBlank(s)) {
+            return null;
+        }
+        return s.split(" *, *");
+    }
+
+    public PoolingHttpClientConnectionManager build() {
+        @SuppressWarnings("resource")
+        final PoolingHttpClientConnectionManager poolingmgr = new PoolingHttpClientConnectionManager(
+                RegistryBuilder.<ConnectionSocketFactory>create()
+                        .register("http", PlainConnectionSocketFactory.getSocketFactory())
+                        .register("https", sslSocketFactory != null ? sslSocketFactory :
+                                (systemProperties ?
+                                        SSLConnectionSocketFactory.getSystemSocketFactory() :
+                                        SSLConnectionSocketFactory.getSocketFactory()))
+                        .build(),
+                null,
+                null,
+                dnsResolver,
+                connTimeToLive,
+                connTimeToLiveTimeUnit != null ? connTimeToLiveTimeUnit : TimeUnit.MILLISECONDS);
+        poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity);
+        if (defaultSocketConfig != null) {
+            poolingmgr.setDefaultSocketConfig(defaultSocketConfig);
+        }
+        if (defaultConnectionConfig != null) {
+            poolingmgr.setDefaultConnectionConfig(defaultConnectionConfig);
+        }
+        if (maxConnTotal > 0) {
+            poolingmgr.setMaxTotal(maxConnTotal);
+        }
+        if (maxConnPerRoute > 0) {
+            poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute);
+        }
+        return poolingmgr;
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java?rev=1777768&r1=1777767&r2=1777768&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java Sat Jan  7 11:38:46 2017
@@ -38,12 +38,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocketFactory;
-
 import org.apache.hc.client5.http.ConnectionKeepAliveStrategy;
-import org.apache.hc.client5.http.DnsResolver;
 import org.apache.hc.client5.http.SchemePortResolver;
 import org.apache.hc.client5.http.SystemDefaultDnsResolver;
 import org.apache.hc.client5.http.auth.AuthSchemeProvider;
@@ -62,7 +57,7 @@ import org.apache.hc.client5.http.impl.a
 import org.apache.hc.client5.http.impl.auth.NTLMSchemeFactory;
 import org.apache.hc.client5.http.impl.auth.SPNegoSchemeFactory;
 import org.apache.hc.client5.http.impl.auth.SystemDefaultCredentialsProvider;
-import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
 import org.apache.hc.client5.http.impl.protocol.DefaultAuthenticationStrategy;
 import org.apache.hc.client5.http.impl.protocol.DefaultRedirectStrategy;
 import org.apache.hc.client5.http.impl.protocol.DefaultUserTokenHandler;
@@ -81,14 +76,7 @@ import org.apache.hc.client5.http.protoc
 import org.apache.hc.client5.http.protocol.ResponseContentEncoding;
 import org.apache.hc.client5.http.protocol.ResponseProcessCookies;
 import org.apache.hc.client5.http.protocol.UserTokenHandler;
-import org.apache.hc.client5.http.psl.PublicSuffixMatcher;
-import org.apache.hc.client5.http.psl.PublicSuffixMatcherLoader;
 import org.apache.hc.client5.http.routing.HttpRoutePlanner;
-import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
-import org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory;
-import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory;
-import org.apache.hc.client5.http.ssl.DefaultHostnameVerifier;
-import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
 import org.apache.hc.client5.http.sync.BackoffManager;
 import org.apache.hc.client5.http.sync.ConnectionBackoffStrategy;
 import org.apache.hc.client5.http.sync.HttpRequestRetryHandler;
@@ -100,10 +88,8 @@ import org.apache.hc.core5.http.HttpRequ
 import org.apache.hc.core5.http.HttpRequestInterceptor;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpResponseInterceptor;
-import org.apache.hc.core5.http.config.ConnectionConfig;
 import org.apache.hc.core5.http.config.Lookup;
 import org.apache.hc.core5.http.config.RegistryBuilder;
-import org.apache.hc.core5.http.config.SocketConfig;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
 import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
@@ -113,7 +99,6 @@ import org.apache.hc.core5.http.protocol
 import org.apache.hc.core5.http.protocol.RequestContent;
 import org.apache.hc.core5.http.protocol.RequestTargetHost;
 import org.apache.hc.core5.http.protocol.RequestUserAgent;
-import org.apache.hc.core5.ssl.SSLContexts;
 import org.apache.hc.core5.util.TextUtils;
 import org.apache.hc.core5.util.VersionInfo;
 
@@ -127,23 +112,10 @@ import org.apache.hc.core5.util.VersionI
  * {@link #build()}.
  * </p>
  * <ul>
- *  <li>ssl.TrustManagerFactory.algorithm</li>
- *  <li>javax.net.ssl.trustStoreType</li>
- *  <li>javax.net.ssl.trustStore</li>
- *  <li>javax.net.ssl.trustStoreProvider</li>
- *  <li>javax.net.ssl.trustStorePassword</li>
- *  <li>ssl.KeyManagerFactory.algorithm</li>
- *  <li>javax.net.ssl.keyStoreType</li>
- *  <li>javax.net.ssl.keyStore</li>
- *  <li>javax.net.ssl.keyStoreProvider</li>
- *  <li>javax.net.ssl.keyStorePassword</li>
- *  <li>https.protocols</li>
- *  <li>https.cipherSuites</li>
  *  <li>http.proxyHost</li>
  *  <li>http.proxyPort</li>
  *  <li>http.nonProxyHosts</li>
  *  <li>http.keepAlive</li>
- *  <li>http.maxConnections</li>
  *  <li>http.agent</li>
  * </ul>
  * <p>
@@ -157,9 +129,6 @@ import org.apache.hc.core5.util.VersionI
 public class HttpClientBuilder {
 
     private HttpRequestExecutor requestExec;
-    private HostnameVerifier hostnameVerifier;
-    private LayeredConnectionSocketFactory sslSocketFactory;
-    private SSLContext sslContext;
     private HttpClientConnectionManager connManager;
     private boolean connManagerShared;
     private SchemePortResolver schemePortResolver;
@@ -168,8 +137,6 @@ public class HttpClientBuilder {
     private AuthenticationStrategy targetAuthStrategy;
     private AuthenticationStrategy proxyAuthStrategy;
     private UserTokenHandler userTokenHandler;
-    private HttpProcessor httpprocessor;
-    private DnsResolver dnsResolver;
 
     private LinkedList<HttpRequestInterceptor> requestFirst;
     private LinkedList<HttpRequestInterceptor> requestLast;
@@ -190,8 +157,6 @@ public class HttpClientBuilder {
     private String userAgent;
     private HttpHost proxy;
     private Collection<? extends Header> defaultHeaders;
-    private SocketConfig defaultSocketConfig;
-    private ConnectionConfig defaultConnectionConfig;
     private RequestConfig defaultRequestConfig;
     private boolean evictExpiredConnections;
     private boolean evictIdleConnections;
@@ -206,17 +171,8 @@ public class HttpClientBuilder {
     private boolean authCachingDisabled;
     private boolean connectionStateDisabled;
 
-    private int maxConnTotal = 0;
-    private int maxConnPerRoute = 0;
-
-    private long connTimeToLive = -1;
-    private TimeUnit connTimeToLiveTimeUnit = TimeUnit.MILLISECONDS;
-    private int validateAfterInactivity = 2000;
-
     private List<Closeable> closeables;
 
-    private PublicSuffixMatcher publicSuffixMatcher;
-
     public static HttpClientBuilder create() {
         return new HttpClientBuilder();
     }
@@ -234,141 +190,6 @@ public class HttpClientBuilder {
     }
 
     /**
-     * Assigns {@link javax.net.ssl.HostnameVerifier} instance.
-     * <p>
-     * Please note this value can be overridden by the {@link #setConnectionManager(
-     *HttpClientConnectionManager)} and the {@link #setSSLSocketFactory(
-     *   org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory)} methods.
-     * </p>
-     *
-     *   @since 4.4
-     */
-    public final HttpClientBuilder setSSLHostnameVerifier(final HostnameVerifier hostnameVerifier) {
-        this.hostnameVerifier = hostnameVerifier;
-        return this;
-    }
-
-    /**
-     * Assigns file containing public suffix matcher. Instances of this class can be created
-     * with {@link PublicSuffixMatcherLoader}.
-     *
-     * @see PublicSuffixMatcher
-     * @see PublicSuffixMatcherLoader
-     *
-     *   @since 4.4
-     */
-    public final HttpClientBuilder setPublicSuffixMatcher(final PublicSuffixMatcher publicSuffixMatcher) {
-        this.publicSuffixMatcher = publicSuffixMatcher;
-        return this;
-    }
-
-    /**
-     * Assigns {@link SSLContext} instance.
-     * <p>
-     * Please note this value can be overridden by the {@link #setConnectionManager(
-     *HttpClientConnectionManager)} and the {@link #setSSLSocketFactory(
-     *   org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory)} methods.
-     * </p>
-     */
-    public final HttpClientBuilder setSSLContext(final SSLContext sslContext) {
-        this.sslContext = sslContext;
-        return this;
-    }
-
-    /**
-     * Assigns {@link LayeredConnectionSocketFactory} instance.
-     * <p>
-     * Please note this value can be overridden by the {@link #setConnectionManager(
-     *HttpClientConnectionManager)} method.
-     * </p>
-     */
-    public final HttpClientBuilder setSSLSocketFactory(
-            final LayeredConnectionSocketFactory sslSocketFactory) {
-        this.sslSocketFactory = sslSocketFactory;
-        return this;
-    }
-
-    /**
-     * Assigns maximum total connection value.
-     * <p>
-     * Please note this value can be overridden by the {@link #setConnectionManager(
-     *HttpClientConnectionManager)} method.
-     * </p>
-     */
-    public final HttpClientBuilder setMaxConnTotal(final int maxConnTotal) {
-        this.maxConnTotal = maxConnTotal;
-        return this;
-    }
-
-    /**
-     * Assigns maximum connection per route value.
-     * <p>
-     * Please note this value can be overridden by the {@link #setConnectionManager(
-     *HttpClientConnectionManager)} method.
-     * </p>
-     */
-    public final HttpClientBuilder setMaxConnPerRoute(final int maxConnPerRoute) {
-        this.maxConnPerRoute = maxConnPerRoute;
-        return this;
-    }
-
-    /**
-     * Assigns default {@link SocketConfig}.
-     * <p>
-     * Please note this value can be overridden by the {@link #setConnectionManager(
-     *HttpClientConnectionManager)} method.
-     * </p>
-     */
-    public final HttpClientBuilder setDefaultSocketConfig(final SocketConfig config) {
-        this.defaultSocketConfig = config;
-        return this;
-    }
-
-    /**
-     * Assigns default {@link ConnectionConfig}.
-     * <p>
-     * Please note this value can be overridden by the {@link #setConnectionManager(
-     *HttpClientConnectionManager)} method.
-     * </p>
-     */
-    public final HttpClientBuilder setDefaultConnectionConfig(final ConnectionConfig config) {
-        this.defaultConnectionConfig = config;
-        return this;
-    }
-
-    /**
-     * Sets maximum time to live for persistent connections
-     * <p>
-     * Please note this value can be overridden by the {@link #setConnectionManager(
-     *HttpClientConnectionManager)} method.
-     * </p>
-     *
-     * @since 4.4
-     */
-    public final HttpClientBuilder setConnectionTimeToLive(final long connTimeToLive, final TimeUnit connTimeToLiveTimeUnit) {
-        this.connTimeToLive = connTimeToLive;
-        this.connTimeToLiveTimeUnit = connTimeToLiveTimeUnit;
-        return this;
-    }
-
-    /**
-     * Sets period after inactivity in milliseconds after which persistent
-     * connections must be checked to ensure they are still valid.
-     * <p>
-     * Please note this value can be overridden by the {@link #setConnectionManager(
-     *HttpClientConnectionManager)} method.
-     * </p>
-     *
-     * @see org.apache.hc.core5.http.io.HttpClientConnection#isStale()
-     *
-     * @since 5.0
-     */
-    public final HttpClientBuilder setValidateAfterInactivity(final int validateAfterInactivity) {
-        this.validateAfterInactivity = validateAfterInactivity;
-        return this;
-    }
-
-    /**
      * Assigns {@link HttpClientConnectionManager} instance.
      */
     public final HttpClientBuilder setConnectionManager(
@@ -466,10 +287,6 @@ public class HttpClientBuilder {
 
     /**
      * Assigns {@code User-Agent} value.
-     * <p>
-     * Please note this value can be overridden by the {@link #setHttpProcessor(
-     * org.apache.hc.core5.http.protocol.HttpProcessor)} method.
-     * </p>
      */
     public final HttpClientBuilder setUserAgent(final String userAgent) {
         this.userAgent = userAgent;
@@ -478,10 +295,6 @@ public class HttpClientBuilder {
 
     /**
      * Assigns default request header values.
-     * <p>
-     * Please note this value can be overridden by the {@link #setHttpProcessor(
-     * org.apache.hc.core5.http.protocol.HttpProcessor)} method.
-     * </p>
      */
     public final HttpClientBuilder setDefaultHeaders(final Collection<? extends Header> defaultHeaders) {
         this.defaultHeaders = defaultHeaders;
@@ -490,10 +303,6 @@ public class HttpClientBuilder {
 
     /**
      * Adds this protocol interceptor to the head of the protocol processing list.
-     * <p>
-     * Please note this value can be overridden by the {@link #setHttpProcessor(
-     * org.apache.hc.core5.http.protocol.HttpProcessor)} method.
-     * </p>
      */
     public final HttpClientBuilder addInterceptorFirst(final HttpResponseInterceptor itcp) {
         if (itcp == null) {
@@ -508,10 +317,6 @@ public class HttpClientBuilder {
 
     /**
      * Adds this protocol interceptor to the tail of the protocol processing list.
-     * <p>
-     * Please note this value can be overridden by the {@link #setHttpProcessor(
-     * org.apache.hc.core5.http.protocol.HttpProcessor)} method.
-     * </p>
      */
     public final HttpClientBuilder addInterceptorLast(final HttpResponseInterceptor itcp) {
         if (itcp == null) {
@@ -526,9 +331,6 @@ public class HttpClientBuilder {
 
     /**
      * Adds this protocol interceptor to the head of the protocol processing list.
-     * <p>
-     * Please note this value can be overridden by the {@link #setHttpProcessor(
-     * org.apache.hc.core5.http.protocol.HttpProcessor)} method.
      */
     public final HttpClientBuilder addInterceptorFirst(final HttpRequestInterceptor itcp) {
         if (itcp == null) {
@@ -543,9 +345,6 @@ public class HttpClientBuilder {
 
     /**
      * Adds this protocol interceptor to the tail of the protocol processing list.
-     * <p>
-     * Please note this value can be overridden by the {@link #setHttpProcessor(
-     * org.apache.hc.core5.http.protocol.HttpProcessor)} method.
      */
     public final HttpClientBuilder addInterceptorLast(final HttpRequestInterceptor itcp) {
         if (itcp == null) {
@@ -560,9 +359,6 @@ public class HttpClientBuilder {
 
     /**
      * Disables state (cookie) management.
-     * <p>
-     * Please note this value can be overridden by the {@link #setHttpProcessor(
-     * org.apache.hc.core5.http.protocol.HttpProcessor)} method.
      */
     public final HttpClientBuilder disableCookieManagement() {
         this.cookieManagementDisabled = true;
@@ -571,9 +367,6 @@ public class HttpClientBuilder {
 
     /**
      * Disables automatic content decompression.
-     * <p>
-     * Please note this value can be overridden by the {@link #setHttpProcessor(
-     * org.apache.hc.core5.http.protocol.HttpProcessor)} method.
      */
     public final HttpClientBuilder disableContentCompression() {
         contentCompressionDisabled = true;
@@ -582,9 +375,6 @@ public class HttpClientBuilder {
 
     /**
      * Disables authentication scheme caching.
-     * <p>
-     * Please note this value can be overridden by the {@link #setHttpProcessor(
-     * org.apache.hc.core5.http.protocol.HttpProcessor)} method.
      */
     public final HttpClientBuilder disableAuthCaching() {
         this.authCachingDisabled = true;
@@ -592,14 +382,6 @@ public class HttpClientBuilder {
     }
 
     /**
-     * Assigns {@link HttpProcessor} instance.
-     */
-    public final HttpClientBuilder setHttpProcessor(final HttpProcessor httpprocessor) {
-        this.httpprocessor = httpprocessor;
-        return this;
-    }
-
-    /**
      * Assigns {@link HttpRequestRetryHandler} instance.
      * <p>
      * Please note this value can be overridden by the {@link #disableAutomaticRetries()}
@@ -704,18 +486,6 @@ public class HttpClientBuilder {
     }
 
     /**
-     * Assigns {@link DnsResolver} instance.
-     * <p>
-     * Please note this value can be overridden by the {@link #setConnectionManager(HttpClientConnectionManager)}
-     * method.
-     * </p>
-     */
-    public final HttpClientBuilder setDnsResolver(final DnsResolver dnsResolver) {
-        this.dnsResolver = dnsResolver;
-        return this;
-    }
-
-    /**
      * Assigns default {@link org.apache.hc.client5.http.auth.AuthScheme} registry which will
      * be used for request execution if not explicitly set in the client execution
      * context.
@@ -892,76 +662,13 @@ public class HttpClientBuilder {
     public CloseableHttpClient build() {
         // Create main request executor
         // We copy the instance fields to avoid changing them, and rename to avoid accidental use of the wrong version
-        PublicSuffixMatcher publicSuffixMatcherCopy = this.publicSuffixMatcher;
-        if (publicSuffixMatcherCopy == null) {
-            publicSuffixMatcherCopy = PublicSuffixMatcherLoader.getDefault();
-        }
-
         HttpRequestExecutor requestExecCopy = this.requestExec;
         if (requestExecCopy == null) {
             requestExecCopy = new HttpRequestExecutor();
         }
         HttpClientConnectionManager connManagerCopy = this.connManager;
         if (connManagerCopy == null) {
-            LayeredConnectionSocketFactory sslSocketFactoryCopy = this.sslSocketFactory;
-            if (sslSocketFactoryCopy == null) {
-                final String[] supportedProtocols = systemProperties ? split(
-                        System.getProperty("https.protocols")) : null;
-                final String[] supportedCipherSuites = systemProperties ? split(
-                        System.getProperty("https.cipherSuites")) : null;
-                HostnameVerifier hostnameVerifierCopy = this.hostnameVerifier;
-                if (hostnameVerifierCopy == null) {
-                    hostnameVerifierCopy = new DefaultHostnameVerifier(publicSuffixMatcherCopy);
-                }
-                if (sslContext != null) {
-                    sslSocketFactoryCopy = new SSLConnectionSocketFactory(
-                            sslContext, supportedProtocols, supportedCipherSuites, hostnameVerifierCopy);
-                } else {
-                    if (systemProperties) {
-                        sslSocketFactoryCopy = new SSLConnectionSocketFactory(
-                                (SSLSocketFactory) SSLSocketFactory.getDefault(),
-                                supportedProtocols, supportedCipherSuites, hostnameVerifierCopy);
-                    } else {
-                        sslSocketFactoryCopy = new SSLConnectionSocketFactory(
-                                SSLContexts.createDefault(),
-                                hostnameVerifierCopy);
-                    }
-                }
-            }
-            @SuppressWarnings("resource")
-            final PoolingHttpClientConnectionManager poolingmgr = new PoolingHttpClientConnectionManager(
-                    RegistryBuilder.<ConnectionSocketFactory>create()
-                        .register("http", PlainConnectionSocketFactory.getSocketFactory())
-                        .register("https", sslSocketFactoryCopy)
-                        .build(),
-                    null,
-                    null,
-                    dnsResolver,
-                    connTimeToLive,
-                    connTimeToLiveTimeUnit != null ? connTimeToLiveTimeUnit : TimeUnit.MILLISECONDS);
-            poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity);
-            if (defaultSocketConfig != null) {
-                poolingmgr.setDefaultSocketConfig(defaultSocketConfig);
-            }
-            if (defaultConnectionConfig != null) {
-                poolingmgr.setDefaultConnectionConfig(defaultConnectionConfig);
-            }
-            if (systemProperties) {
-                String s = System.getProperty("http.keepAlive", "true");
-                if ("true".equalsIgnoreCase(s)) {
-                    s = System.getProperty("http.maxConnections", "5");
-                    final int max = Integer.parseInt(s);
-                    poolingmgr.setDefaultMaxPerRoute(max);
-                    poolingmgr.setMaxTotal(2 * max);
-                }
-            }
-            if (maxConnTotal > 0) {
-                poolingmgr.setMaxTotal(maxConnTotal);
-            }
-            if (maxConnPerRoute > 0) {
-                poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute);
-            }
-            connManagerCopy = poolingmgr;
+            connManagerCopy = PoolingHttpClientConnectionManagerBuilder.create().build();
         }
         ConnectionReuseStrategy reuseStrategyCopy = this.reuseStrategy;
         if (reuseStrategyCopy == null) {
@@ -1026,69 +733,64 @@ public class HttpClientBuilder {
 
         execChain = decorateMainExec(execChain);
 
-        HttpProcessor httpprocessorCopy = this.httpprocessor;
-        if (httpprocessorCopy == null) {
-
-            final HttpProcessorBuilder b = HttpProcessorBuilder.create();
-            if (requestFirst != null) {
-                for (final HttpRequestInterceptor i: requestFirst) {
-                    b.addFirst(i);
-                }
-            }
-            if (responseFirst != null) {
-                for (final HttpResponseInterceptor i: responseFirst) {
-                    b.addFirst(i);
-                }
-            }
-            b.addAll(
-                    new RequestDefaultHeaders(defaultHeaders),
-                    new RequestContent(),
-                    new RequestTargetHost(),
-                    new RequestClientConnControl(),
-                    new RequestUserAgent(userAgentCopy),
-                    new RequestExpectContinue());
-            if (!cookieManagementDisabled) {
-                b.add(new RequestAddCookies());
-            }
-            if (!contentCompressionDisabled) {
-                if (contentDecoderMap != null) {
-                    final List<String> encodings = new ArrayList<>(contentDecoderMap.keySet());
-                    Collections.sort(encodings);
-                    b.add(new RequestAcceptEncoding(encodings));
-                } else {
-                    b.add(new RequestAcceptEncoding());
-                }
-            }
-            if (!authCachingDisabled) {
-                b.add(new RequestAuthCache());
-            }
-            if (!cookieManagementDisabled) {
-                b.add(new ResponseProcessCookies());
+        final HttpProcessorBuilder b = HttpProcessorBuilder.create();
+        if (requestFirst != null) {
+            for (final HttpRequestInterceptor i: requestFirst) {
+                b.addFirst(i);
+            }
+        }
+        if (responseFirst != null) {
+            for (final HttpResponseInterceptor i: responseFirst) {
+                b.addFirst(i);
+            }
+        }
+        b.addAll(
+                new RequestDefaultHeaders(defaultHeaders),
+                new RequestContent(),
+                new RequestTargetHost(),
+                new RequestClientConnControl(),
+                new RequestUserAgent(userAgentCopy),
+                new RequestExpectContinue());
+        if (!cookieManagementDisabled) {
+            b.add(new RequestAddCookies());
+        }
+        if (!contentCompressionDisabled) {
+            if (contentDecoderMap != null) {
+                final List<String> encodings = new ArrayList<>(contentDecoderMap.keySet());
+                Collections.sort(encodings);
+                b.add(new RequestAcceptEncoding(encodings));
+            } else {
+                b.add(new RequestAcceptEncoding());
             }
-            if (!contentCompressionDisabled) {
-                if (contentDecoderMap != null) {
-                    final RegistryBuilder<InputStreamFactory> b2 = RegistryBuilder.create();
-                    for (final Map.Entry<String, InputStreamFactory> entry: contentDecoderMap.entrySet()) {
-                        b2.register(entry.getKey(), entry.getValue());
-                    }
-                    b.add(new ResponseContentEncoding(b2.build()));
-                } else {
-                    b.add(new ResponseContentEncoding());
+        }
+        if (!authCachingDisabled) {
+            b.add(new RequestAuthCache());
+        }
+        if (!cookieManagementDisabled) {
+            b.add(new ResponseProcessCookies());
+        }
+        if (!contentCompressionDisabled) {
+            if (contentDecoderMap != null) {
+                final RegistryBuilder<InputStreamFactory> b2 = RegistryBuilder.create();
+                for (final Map.Entry<String, InputStreamFactory> entry: contentDecoderMap.entrySet()) {
+                    b2.register(entry.getKey(), entry.getValue());
                 }
+                b.add(new ResponseContentEncoding(b2.build()));
+            } else {
+                b.add(new ResponseContentEncoding());
             }
-            if (requestLast != null) {
-                for (final HttpRequestInterceptor i: requestLast) {
-                    b.addLast(i);
-                }
+        }
+        if (requestLast != null) {
+            for (final HttpRequestInterceptor i: requestLast) {
+                b.addLast(i);
             }
-            if (responseLast != null) {
-                for (final HttpResponseInterceptor i: responseLast) {
-                    b.addLast(i);
-                }
+        }
+        if (responseLast != null) {
+            for (final HttpResponseInterceptor i: responseLast) {
+                b.addLast(i);
             }
-            httpprocessorCopy = b.build();
         }
-        execChain = new ProtocolExec(execChain, httpprocessorCopy);
+        execChain = new ProtocolExec(execChain, b.build());
 
         execChain = decorateProtocolExec(execChain);
 
@@ -1147,7 +849,7 @@ public class HttpClientBuilder {
         }
         Lookup<CookieSpecProvider> cookieSpecRegistryCopy = this.cookieSpecRegistry;
         if (cookieSpecRegistryCopy == null) {
-            cookieSpecRegistryCopy = CookieSpecRegistries.createDefault(publicSuffixMatcherCopy);
+            cookieSpecRegistryCopy = CookieSpecRegistries.createDefault();
         }
 
         CookieStore defaultCookieStore = this.cookieStore;

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestFutureRequestExecutionService.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestFutureRequestExecutionService.java?rev=1777768&r1=1777767&r2=1777768&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestFutureRequestExecutionService.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestFutureRequestExecutionService.java Sat Jan  7 11:38:46 2017
@@ -39,6 +39,8 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
+import org.apache.hc.client5.http.io.HttpClientConnectionManager;
 import org.apache.hc.client5.http.methods.HttpGet;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.core5.concurrent.FutureCallback;
@@ -66,32 +68,35 @@ public class TestFutureRequestExecutionS
 
     @Before
     public void before() throws Exception {
-            this.localServer = ServerBootstrap.bootstrap()
-                    .registerHandler("/wait", new HttpRequestHandler() {
+        this.localServer = ServerBootstrap.bootstrap()
+                .registerHandler("/wait", new HttpRequestHandler() {
 
-                @Override
-                public void handle(
-                        final ClassicHttpRequest request,
-                        final ClassicHttpResponse response,
-                        final HttpContext context) throws HttpException, IOException {
-                    try {
-                        while(blocked.get()) {
-                            Thread.sleep(10);
-                        }
-                    } catch (final InterruptedException e) {
-                        throw new IllegalStateException(e);
+            @Override
+            public void handle(
+                    final ClassicHttpRequest request,
+                    final ClassicHttpResponse response,
+                    final HttpContext context) throws HttpException, IOException {
+                try {
+                    while(blocked.get()) {
+                        Thread.sleep(10);
                     }
-                    response.setCode(200);
+                } catch (final InterruptedException e) {
+                    throw new IllegalStateException(e);
                 }
-            }).create();
-
-            this.localServer.start();
-            uri = "http://localhost:" + this.localServer.getLocalPort() + "/wait";
-            final CloseableHttpClient httpClient = HttpClientBuilder.create()
-                    .setMaxConnPerRoute(5)
-                    .build();
-            final ExecutorService executorService = Executors.newFixedThreadPool(5);
-            httpAsyncClientWithFuture = new FutureRequestExecutionService(httpClient, executorService);
+                response.setCode(200);
+            }
+        }).create();
+
+        this.localServer.start();
+        uri = "http://localhost:" + this.localServer.getLocalPort() + "/wait";
+        final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
+                .setMaxConnPerRoute(5)
+                .build();
+        final CloseableHttpClient httpClient = HttpClientBuilder.create()
+                .setConnectionManager(cm)
+                .build();
+        final ExecutorService executorService = Executors.newFixedThreadPool(5);
+        httpAsyncClientWithFuture = new FutureRequestExecutionService(httpClient, executorService);
     }
 
     @After

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/localserver/LocalServerTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/localserver/LocalServerTestBase.java?rev=1777768&r1=1777767&r2=1777768&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/localserver/LocalServerTestBase.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/localserver/LocalServerTestBase.java Sat Jan  7 11:38:46 2017
@@ -80,8 +80,8 @@ public abstract class LocalServerTestBas
         }
 
         this.connManager = new PoolingHttpClientConnectionManager();
+        this.connManager.setDefaultSocketConfig(socketConfig);
         this.clientBuilder = HttpClientBuilder.create()
-                .setDefaultSocketConfig(socketConfig)
                 .setConnectionManager(this.connManager);
     }
 



Mime
View raw message