hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1784138 [1/5] - in /httpcomponents/httpclient/trunk: httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/ httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/ httpclient5/src/examples/org/apache/hc/client5/h...
Date Thu, 23 Feb 2017 14:32:24 GMT
Author: olegk
Date: Thu Feb 23 14:32:24 2017
New Revision: 1784138

URL: http://svn.apache.org/viewvc?rev=1784138&view=rev
Log:
Redesign of classic (blocking) connection management APIs

Added:
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java   (with props)
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnectionShutdownException.java   (contents, props changed)
      - copied, changed from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ConnectionShutdownException.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultThreadFactory.java
      - copied, changed from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingInputStream.java   (contents, props changed)
      - copied, changed from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingOutputStream.java   (contents, props changed)
      - copied, changed from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingOutputStream.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingSocketHolder.java   (contents, props changed)
      - copied, changed from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/Wire.java   (contents, props changed)
      - copied, changed from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/Wire.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BasicResponseHandler.java   (contents, props changed)
      - copied, changed from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/BasicResponseHandler.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/EndpointHolder.java   (contents, props changed)
      - copied, changed from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ConnectionHolder.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionEndpoint.java   (contents, props changed)
      - copied, changed from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ConnectionPoolTimeoutException.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/LeaseRequest.java   (contents, props changed)
      - copied, changed from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionRequest.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/utils/Identifiable.java   (contents, props changed)
      - copied, changed from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/HttpConnectionFactory.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestEndpointHolder.java   (contents, props changed)
      - copied, changed from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestConnectionHolder.java
Removed:
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ConnectionPoolTimeoutException.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/HttpConnectionFactory.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/BasicResponseHandler.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/CPoolProxy.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ConnectionShutdownException.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingInputStream.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingManagedHttpClientConnection.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingOutputStream.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/Wire.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ConnectionHolder.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionReleaseTrigger.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionRequest.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestAbortHandling.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestDefaultHttpResponseParser.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestConnectionHolder.java
Modified:
    httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpRoutePlanner.java
    httpcomponents/httpclient/trunk/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiHttpRoutePlanner.java
    httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultProxyRoutePlanner.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/SystemDefaultRoutePlanner.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/IdleConnectionEvictor.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/InternalHttpClient.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MainClientExec.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalClientExec.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalHttpClient.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ProxyClient.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RedirectExec.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ResponseEntityProxy.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/HttpClientConnectionManager.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ManagedHttpClientConnection.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/routing/HttpRoutePlanner.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/TestExceptions.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestAbstractResponseHandler.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestBasicResponseHandler.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestConnectionAutoRelease.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestConnectionManagement.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestContentCodings.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestStatefulConnManagement.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestBasicHttpClientConnectionManager.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestHttpClientConnectionOperator.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestPoolingHttpClientConnectionManager.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestDefaultProxyRoutePlanner.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestDefaultRoutePlanner.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestSystemDefaultRoutePlanner.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestDefaultBackoffStrategy.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestIdleConnectionEvictor.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestInternalHttpClient.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestMainClientExec.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestMinimalClientExec.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestRedirectExec.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestResponseEntityWrapper.java

Modified: httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpRoutePlanner.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpRoutePlanner.java Thu Feb 23 14:32:24 2017
@@ -34,7 +34,6 @@ import org.apache.hc.client5.http.impl.r
 import org.apache.hc.client5.http.osgi.services.ProxyConfiguration;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.protocol.HttpContext;
 
 /**
@@ -53,7 +52,7 @@ final class OSGiHttpRoutePlanner extends
      * {@inheritDoc}
      */
     @Override
-    protected HttpHost determineProxy(final HttpHost target, final HttpRequest request, final HttpContext context) throws HttpException {
+    protected HttpHost determineProxy(final HttpHost target, final HttpContext context) throws HttpException {
         HttpHost proxyHost = null;
         for (final ProxyConfiguration proxyConfiguration : proxyConfigurations) {
             if (proxyConfiguration.isEnabled()) {

Modified: httpcomponents/httpclient/trunk/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiHttpRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiHttpRoutePlanner.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiHttpRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiHttpRoutePlanner.java Thu Feb 23 14:32:24 2017
@@ -51,41 +51,41 @@ public class TestOSGiHttpRoutePlanner {
     public void testDeterminProxy() throws Exception {
         OSGiHttpRoutePlanner planner = new OSGiHttpRoutePlanner(singletonList(pc1));
 
-        HttpHost proxy = planner.determineProxy(new HttpHost("localhost", 8090), null, null);
+        HttpHost proxy = planner.determineProxy(new HttpHost("localhost", 8090), null);
         assertNull(proxy);
 
-        proxy = planner.determineProxy(new HttpHost("there", 9090), null, null);
+        proxy = planner.determineProxy(new HttpHost("there", 9090), null);
         assertNotNull(proxy);
         assertTrue(proxy.getHostName().equals("proxy1"));
 
-        proxy = planner.determineProxy(new HttpHost("10.2.144.23", 4554), null, null);
+        proxy = planner.determineProxy(new HttpHost("10.2.144.23", 4554), null);
         assertNotNull(proxy);
         assertTrue(proxy.getHostName().equals("proxy1"));
 
         final InetAddress addr = InetAddress.getByName("localhost");
-        proxy = planner.determineProxy(new HttpHost(addr, 4554), null, null);
+        proxy = planner.determineProxy(new HttpHost(addr, 4554), null);
         assertNull(proxy);
 
-        proxy = planner.determineProxy(new HttpHost("hc.apache.org", 4554), null, null);
+        proxy = planner.determineProxy(new HttpHost("hc.apache.org", 4554), null);
         assertNull(proxy);
 
 
         // test with more than one registration of proxyConfiguration
         planner = new OSGiHttpRoutePlanner(asList(pc1, pc2));
-        proxy = planner.determineProxy(new HttpHost("localhost", 8090), null, null);
+        proxy = planner.determineProxy(new HttpHost("localhost", 8090), null);
         assertNull(proxy);
 
-        proxy = planner.determineProxy(new HttpHost("there", 9090), null, null);
+        proxy = planner.determineProxy(new HttpHost("there", 9090), null);
         assertNotNull(proxy);
         assertTrue(proxy.getHostName().equals("proxy1")); // the first one
 
-        proxy = planner.determineProxy(new HttpHost(addr, 4554), null, null);
+        proxy = planner.determineProxy(new HttpHost(addr, 4554), null);
         assertNull(proxy);
 
-        proxy = planner.determineProxy(new HttpHost("hc.apache.org", 4554), null, null);
+        proxy = planner.determineProxy(new HttpHost("hc.apache.org", 4554), null);
         assertNull(proxy);
 
-        proxy = planner.determineProxy(new HttpHost("docs.oracle.com", 4554), null, null);
+        proxy = planner.determineProxy(new HttpHost("docs.oracle.com", 4554), null);
         assertNull(proxy);
     }
 
@@ -93,11 +93,11 @@ public class TestOSGiHttpRoutePlanner {
     public void testMasking() throws Exception {
         final OSGiHttpRoutePlanner planner = new OSGiHttpRoutePlanner(singletonList(pc2));
 
-        HttpHost proxy = planner.determineProxy(new HttpHost("12.34.34.2", 4554), null, null);
+        HttpHost proxy = planner.determineProxy(new HttpHost("12.34.34.2", 4554), null);
         assertNotNull(proxy);
         assertTrue(proxy.getHostName().equals("proxy2"));
 
-        proxy = planner.determineProxy(new HttpHost("12.34.34.8", 4554), null, null);
+        proxy = planner.determineProxy(new HttpHost("12.34.34.8", 4554), null);
         assertNotNull(proxy);
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java Thu Feb 23 14:32:24 2017
@@ -36,7 +36,6 @@ import java.util.Arrays;
 import javax.net.ssl.SSLContext;
 
 import org.apache.hc.client5.http.DnsResolver;
-import org.apache.hc.client5.http.HttpConnectionFactory;
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.SystemDefaultDnsResolver;
 import org.apache.hc.client5.http.auth.CredentialsProvider;
@@ -45,15 +44,13 @@ import org.apache.hc.client5.http.config
 import org.apache.hc.client5.http.config.RequestConfig;
 import org.apache.hc.client5.http.cookie.BasicCookieStore;
 import org.apache.hc.client5.http.cookie.CookieStore;
-import org.apache.hc.client5.http.impl.io.DefaultHttpResponseParserFactory;
-import org.apache.hc.client5.http.impl.io.LenientHttpResponseParser;
 import org.apache.hc.client5.http.impl.io.ManagedHttpClientConnectionFactory;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
 import org.apache.hc.client5.http.impl.sync.BasicCredentialsProvider;
 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.sync.HttpClients;
 import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
-import org.apache.hc.client5.http.impl.sync.CloseableHttpResponse;
 import org.apache.hc.client5.http.methods.HttpGet;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
@@ -71,6 +68,9 @@ import org.apache.hc.core5.http.config.R
 import org.apache.hc.core5.http.config.SocketConfig;
 import org.apache.hc.core5.http.impl.io.DefaultClassicHttpResponseFactory;
 import org.apache.hc.core5.http.impl.io.DefaultHttpRequestWriterFactory;
+import org.apache.hc.core5.http.impl.io.DefaultHttpResponseParser;
+import org.apache.hc.core5.http.impl.io.DefaultHttpResponseParserFactory;
+import org.apache.hc.core5.http.io.HttpConnectionFactory;
 import org.apache.hc.core5.http.io.HttpMessageParser;
 import org.apache.hc.core5.http.io.HttpMessageParserFactory;
 import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
@@ -107,18 +107,30 @@ public class ClientConfiguration {
                     }
 
                 };
-                return new LenientHttpResponseParser(lineParser, DefaultClassicHttpResponseFactory.INSTANCE, h1Config);
+                return new DefaultHttpResponseParser(lineParser, DefaultClassicHttpResponseFactory.INSTANCE, h1Config);
             }
 
         };
         HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory = new DefaultHttpRequestWriterFactory();
 
+        // Create HTTP/1.1 protocol configuration
+        H1Config h1Config = H1Config.custom()
+                .setMaxHeaderCount(200)
+                .setMaxLineLength(2000)
+                .build();
+        // Create connection configuration
+        ConnectionConfig connectionConfig = ConnectionConfig.custom()
+                .setMalformedInputAction(CodingErrorAction.IGNORE)
+                .setUnmappableInputAction(CodingErrorAction.IGNORE)
+                .setCharset(StandardCharsets.UTF_8)
+                .build();
+
         // Use a custom connection factory to customize the process of
         // initialization of outgoing HTTP connections. Beside standard connection
         // configuration parameters HTTP connection factory can define message
         // parser / writer routines to be employed by individual connections.
-        HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory = new ManagedHttpClientConnectionFactory(
-                H1Config.DEFAULT, requestWriterFactory, responseParserFactory);
+        HttpConnectionFactory<ManagedHttpClientConnection> connFactory = new ManagedHttpClientConnectionFactory(
+                h1Config, connectionConfig, requestWriterFactory, responseParserFactory);
 
         // Client HTTP connection objects when fully initialized can be bound to
         // an arbitrary network socket. The process of network socket initialization,
@@ -161,26 +173,9 @@ public class ClientConfiguration {
         // Configure the connection manager to use socket configuration either
         // by default or for a specific host.
         connManager.setDefaultSocketConfig(socketConfig);
-        connManager.setSocketConfig(new HttpHost("somehost", 80), socketConfig);
         // Validate connections after 1 sec of inactivity
         connManager.setValidateAfterInactivity(1000);
 
-        // Create message constraints
-        H1Config messageConstraints = H1Config.custom()
-            .setMaxHeaderCount(200)
-            .setMaxLineLength(2000)
-            .build();
-        // Create connection configuration
-        ConnectionConfig connectionConfig = ConnectionConfig.custom()
-            .setMalformedInputAction(CodingErrorAction.IGNORE)
-            .setUnmappableInputAction(CodingErrorAction.IGNORE)
-            .setCharset(StandardCharsets.UTF_8)
-            .build();
-        // Configure the connection manager to use connection configuration either
-        // by default or for a specific host.
-        connManager.setDefaultConnectionConfig(connectionConfig);
-        connManager.setConnectionConfig(new HttpHost("somehost", 80), ConnectionConfig.DEFAULT);
-
         // Configure total max or per route limits for persistent connections
         // that can be kept in the pool or leased by the connection manager.
         connManager.setMaxTotal(100);

Added: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java?rev=1784138&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java (added)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java Thu Feb 23 14:32:24 2017
@@ -0,0 +1,70 @@
+/*
+ * ====================================================================
+ * 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;
+
+import org.apache.hc.client5.http.HttpRoute;
+import org.apache.hc.client5.http.utils.Identifiable;
+import org.apache.hc.core5.pool.ConnPoolControl;
+import org.apache.hc.core5.pool.PoolStats;
+
+public final class ConnPoolSupport {
+
+    public static String getId(final Object object) {
+        if (object == null) {
+            return null;
+        }
+        if (object instanceof Identifiable) {
+            return ((Identifiable) object).getId();
+        } else {
+            return Integer.toHexString(System.identityHashCode(object));
+        }
+    }
+
+    public static String formatStats(
+            final Object object,
+            final HttpRoute route,
+            final Object state,
+            final ConnPoolControl<HttpRoute> connPool) {
+        final StringBuilder buf = new StringBuilder();
+        if (object != null) {
+            buf.append("[id: ").append(getId(object)).append("]");
+        }
+        buf.append("[route: ").append(route).append("]");
+        if (state != null) {
+            buf.append("[state: ").append(state).append("]");
+        }
+        final PoolStats totals = connPool.getTotalStats();
+        final PoolStats stats = connPool.getStats(route);
+        buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
+        buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
+        buf.append(" of ").append(stats.getMax()).append("; ");
+        buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
+        buf.append(" of ").append(totals.getMax()).append("]");
+        return buf.toString();
+    }
+
+}

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

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

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

Copied: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnectionShutdownException.java (from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ConnectionShutdownException.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnectionShutdownException.java?p2=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnectionShutdownException.java&p1=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ConnectionShutdownException.java&r1=1784071&r2=1784138&rev=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ConnectionShutdownException.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnectionShutdownException.java Thu Feb 23 14:32:24 2017
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.client5.http.impl.io;
+package org.apache.hc.client5.http.impl;
 
 /**
  * Signals that the connection has been shut down or released back to the

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

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

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

Copied: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultThreadFactory.java (from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultThreadFactory.java?p2=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultThreadFactory.java&p1=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java&r1=1784071&r2=1784138&rev=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LoggingSocketHolder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultThreadFactory.java Thu Feb 23 14:32:24 2017
@@ -24,32 +24,41 @@
  * <http://www.apache.org/>.
  *
  */
+package org.apache.hc.client5.http.impl;
 
-package org.apache.hc.client5.http.impl.io;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicLong;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-
-import org.apache.hc.core5.http.impl.io.SocketHolder;
-
-class LoggingSocketHolder extends SocketHolder {
+/**
+ * @since 5.0
+ */
+public class DefaultThreadFactory implements ThreadFactory {
 
-    private final Wire wire;
+    private final String namePrefix;
+    private final ThreadGroup group;
+    private final AtomicLong count;
+    private final boolean daemon;
+
+    public DefaultThreadFactory(final String namePrefix, final ThreadGroup group, final boolean daemon) {
+        this.namePrefix = namePrefix;
+        this.group = group;
+        this.count = new AtomicLong();
+        this.daemon = daemon;
+    }
 
-    LoggingSocketHolder(final Socket socket, final Wire wire) {
-        super(socket);
-        this.wire = wire;
+    public DefaultThreadFactory(final String namePrefix) {
+        this(namePrefix, null, false);
     }
 
-    @Override
-    protected InputStream getInputStream(final Socket socket) throws IOException {
-        return new LoggingInputStream(super.getInputStream(socket), wire);
+    public DefaultThreadFactory(final String namePrefix, final boolean daemon) {
+        this(namePrefix, null, daemon);
     }
 
     @Override
-    protected OutputStream getOutputStream(final Socket socket) throws IOException {
-        return new LoggingOutputStream(super.getOutputStream(socket), wire);
+    public Thread newThread(final Runnable target) {
+        final Thread thread = new Thread(this.group, target, this.namePrefix + "-"  + this.count.incrementAndGet());
+        thread.setDaemon(this.daemon);
+        return thread;
     }
+
 }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java Thu Feb 23 14:32:24 2017
@@ -27,33 +27,38 @@
 
 package org.apache.hc.client5.http.impl.io;
 
-import java.io.Closeable;
 import java.io.IOException;
-import java.net.InetSocketAddress;
 import java.util.Date;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.hc.client5.http.DnsResolver;
-import org.apache.hc.client5.http.HttpConnectionFactory;
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.SchemePortResolver;
-import org.apache.hc.client5.http.io.ConnectionRequest;
+import org.apache.hc.client5.http.impl.ConnectionShutdownException;
+import org.apache.hc.client5.http.io.ConnectionEndpoint;
 import org.apache.hc.client5.http.io.HttpClientConnectionManager;
 import org.apache.hc.client5.http.io.HttpClientConnectionOperator;
+import org.apache.hc.client5.http.io.LeaseRequest;
 import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
 import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
 import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory;
 import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.config.ConnectionConfig;
 import org.apache.hc.core5.http.config.Lookup;
 import org.apache.hc.core5.http.config.Registry;
 import org.apache.hc.core5.http.config.RegistryBuilder;
 import org.apache.hc.core5.http.config.SocketConfig;
-import org.apache.hc.core5.http.io.HttpClientConnection;
+import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
+import org.apache.hc.core5.http.io.HttpConnectionFactory;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
@@ -80,12 +85,12 @@ import org.apache.logging.log4j.Logger;
  * @since 4.3
  */
 @Contract(threading = ThreadingBehavior.SAFE)
-public class BasicHttpClientConnectionManager implements HttpClientConnectionManager, Closeable {
+public class BasicHttpClientConnectionManager implements HttpClientConnectionManager {
 
     private final Logger log = LogManager.getLogger(getClass());
 
     private final HttpClientConnectionOperator connectionOperator;
-    private final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory;
+    private final HttpConnectionFactory<ManagedHttpClientConnection> connFactory;
 
     private ManagedHttpClientConnection conn;
     private HttpRoute route;
@@ -94,9 +99,8 @@ public class BasicHttpClientConnectionMa
     private long expiry;
     private boolean leased;
     private SocketConfig socketConfig;
-    private ConnectionConfig connConfig;
 
-    private final AtomicBoolean isShutdown;
+    private final AtomicBoolean closed;
 
     private static Registry<ConnectionSocketFactory> getDefaultRegistry() {
         return RegistryBuilder.<ConnectionSocketFactory>create()
@@ -106,14 +110,12 @@ public class BasicHttpClientConnectionMa
     }
 
     public BasicHttpClientConnectionManager(
-        final Lookup<ConnectionSocketFactory> socketFactoryRegistry,
-        final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
-        final SchemePortResolver schemePortResolver,
-        final DnsResolver dnsResolver) {
-      this(
-          new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver),
-          connFactory
-      );
+            final Lookup<ConnectionSocketFactory> socketFactoryRegistry,
+            final HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
+            final SchemePortResolver schemePortResolver,
+            final DnsResolver dnsResolver) {
+      this(new DefaultHttpClientConnectionOperator(
+              socketFactoryRegistry, schemePortResolver, dnsResolver), connFactory);
     }
 
     /**
@@ -121,19 +123,18 @@ public class BasicHttpClientConnectionMa
      */
     public BasicHttpClientConnectionManager(
             final HttpClientConnectionOperator httpClientConnectionOperator,
-            final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory) {
+            final HttpConnectionFactory<ManagedHttpClientConnection> connFactory) {
         super();
         this.connectionOperator = Args.notNull(httpClientConnectionOperator, "Connection operator");
         this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
         this.expiry = Long.MAX_VALUE;
         this.socketConfig = SocketConfig.DEFAULT;
-        this.connConfig = ConnectionConfig.DEFAULT;
-        this.isShutdown = new AtomicBoolean(false);
+        this.closed = new AtomicBoolean(false);
     }
 
     public BasicHttpClientConnectionManager(
             final Lookup<ConnectionSocketFactory> socketFactoryRegistry,
-            final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory) {
+            final HttpConnectionFactory<ManagedHttpClientConnection> connFactory) {
         this(socketFactoryRegistry, connFactory, null, null);
     }
 
@@ -149,7 +150,7 @@ public class BasicHttpClientConnectionMa
     @Override
     protected void finalize() throws Throwable {
         try {
-            shutdown();
+            close();
         } finally { // Make sure we call overridden method even if shutdown barfs
             super.finalize();
         }
@@ -157,7 +158,9 @@ public class BasicHttpClientConnectionMa
 
     @Override
     public void close() {
-        shutdown();
+        if (this.closed.compareAndSet(false, true)) {
+            shutdownConnection();
+        }
     }
 
     HttpRoute getRoute() {
@@ -176,37 +179,30 @@ public class BasicHttpClientConnectionMa
         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;
-    }
-
     @Override
-    public final ConnectionRequest requestConnection(
-            final HttpRoute route,
-            final Object state) {
-        Args.notNull(route, "Route");
-        return new ConnectionRequest() {
+    public LeaseRequest lease(final HttpRoute route, final Object state) {
+        return new LeaseRequest() {
 
             @Override
-            public boolean cancel() {
-                // Nothing to abort, since requests are immediate.
-                return false;
+            public ConnectionEndpoint get(
+                    final long timeout,
+                    final TimeUnit tunit) throws InterruptedException, ExecutionException, TimeoutException {
+                try {
+                    return new InternalConnectionEndpoint(route, getConnection(route, state));
+                } catch (IOException ex) {
+                    throw new ExecutionException(ex.getMessage(), ex);
+                }
             }
 
             @Override
-            public HttpClientConnection get(final long timeout, final TimeUnit tunit) {
-                return BasicHttpClientConnectionManager.this.getConnection(
-                        route, state);
+            public boolean cancel() {
+                return false;
             }
 
         };
     }
 
-    private void closeConnection() {
+    private synchronized void closeConnection() {
         if (this.conn != null) {
             this.log.debug("Closing connection");
             try {
@@ -220,7 +216,7 @@ public class BasicHttpClientConnectionMa
         }
     }
 
-    private void shutdownConnection() {
+    private synchronized void shutdownConnection() {
         if (this.conn != null) {
             this.log.debug("Shutting down connection");
             try {
@@ -243,8 +239,8 @@ public class BasicHttpClientConnectionMa
         }
     }
 
-    synchronized HttpClientConnection getConnection(final HttpRoute route, final Object state) {
-        Asserts.check(!this.isShutdown.get(), "Connection manager has been shut down");
+    synchronized ManagedHttpClientConnection getConnection(final HttpRoute route, final Object state) throws IOException {
+        Asserts.check(!this.closed.get(), "Connection manager has been shut down");
         if (this.log.isDebugEnabled()) {
             this.log.debug("Get connection for route " + route);
         }
@@ -256,23 +252,32 @@ public class BasicHttpClientConnectionMa
         this.state = state;
         checkExpiry();
         if (this.conn == null) {
-            this.conn = this.connFactory.create(route, this.connConfig);
+            this.conn = this.connFactory.createConnection(null);
         }
         this.leased = true;
         return this.conn;
     }
 
+    private InternalConnectionEndpoint cast(final ConnectionEndpoint endpoint) {
+        if (endpoint instanceof InternalConnectionEndpoint) {
+            return (InternalConnectionEndpoint) endpoint;
+        } else {
+            throw new IllegalStateException("Unexpected endpoint class: " + endpoint.getClass());
+        }
+    }
+
     @Override
-    public synchronized void releaseConnection(
-            final HttpClientConnection conn,
+    public synchronized void release(
+            final ConnectionEndpoint endpoint,
             final Object state,
             final long keepalive, final TimeUnit tunit) {
-        Args.notNull(conn, "Connection");
-        Asserts.check(conn == this.conn, "Connection not obtained from this manager");
-        if (this.log.isDebugEnabled()) {
+        Args.notNull(endpoint, "Endpoint");
+        final InternalConnectionEndpoint internalEndpoint = cast(endpoint);
+        final ManagedHttpClientConnection conn = internalEndpoint.detach();
+        if (conn != null && this.log.isDebugEnabled()) {
             this.log.debug("Releasing connection " + conn);
         }
-        if (this.isShutdown.get()) {
+        if (this.closed.get()) {
             return;
         }
         try {
@@ -306,45 +311,47 @@ public class BasicHttpClientConnectionMa
 
     @Override
     public void connect(
-            final HttpClientConnection conn,
-            final HttpRoute route,
-            final int connectTimeout,
+            final ConnectionEndpoint endpoint,
+            final long connectTimeout,
+            final TimeUnit timeUnit,
             final HttpContext context) throws IOException {
-        Args.notNull(conn, "Connection");
-        Args.notNull(route, "HTTP route");
-        Asserts.check(conn == this.conn, "Connection not obtained from this manager");
+        Args.notNull(endpoint, "Endpoint");
+
+        final InternalConnectionEndpoint internalEndpoint = cast(endpoint);
+        if (internalEndpoint.isConnected()) {
+            return;
+        }
+        final HttpRoute route = internalEndpoint.getRoute();
         final HttpHost host;
         if (route.getProxyHost() != null) {
             host = route.getProxyHost();
         } else {
             host = route.getTargetHost();
         }
-        final InetSocketAddress localAddress = route.getLocalSocketAddress();
-        this.connectionOperator.connect(this.conn, host, localAddress,
-                connectTimeout, this.socketConfig, context);
+        this.connectionOperator.connect(
+                internalEndpoint.getConnection(),
+                host,
+                route.getLocalSocketAddress(),
+                (int) (timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS).toMillis(connectTimeout),
+                this.socketConfig,
+                context);
     }
 
     @Override
     public void upgrade(
-            final HttpClientConnection conn,
-            final HttpRoute route,
+            final ConnectionEndpoint endpoint,
             final HttpContext context) throws IOException {
-        Args.notNull(conn, "Connection");
+        Args.notNull(endpoint, "Endpoint");
         Args.notNull(route, "HTTP route");
-        Asserts.check(conn == this.conn, "Connection not obtained from this manager");
-        this.connectionOperator.upgrade(this.conn, route.getTargetHost(), context);
+        final InternalConnectionEndpoint internalEndpoint = cast(endpoint);
+        this.connectionOperator.upgrade(
+                internalEndpoint.getConnection(),
+                internalEndpoint.getRoute().getTargetHost(),
+                context);
     }
 
-    @Override
-    public void routeComplete(
-            final HttpClientConnection conn,
-            final HttpRoute route,
-            final HttpContext context) throws IOException {
-    }
-
-    @Override
     public synchronized void closeExpired() {
-        if (this.isShutdown.get()) {
+        if (this.closed.get()) {
             return;
         }
         if (!this.leased) {
@@ -352,10 +359,9 @@ public class BasicHttpClientConnectionMa
         }
     }
 
-    @Override
     public synchronized void closeIdle(final long idletime, final TimeUnit tunit) {
         Args.notNull(tunit, "Time unit");
-        if (this.isShutdown.get()) {
+        if (this.closed.get()) {
             return;
         }
         if (!this.leased) {
@@ -370,11 +376,75 @@ public class BasicHttpClientConnectionMa
         }
     }
 
-    @Override
-    public synchronized void shutdown() {
-        if (this.isShutdown.compareAndSet(false, true)) {
-            shutdownConnection();
+    class InternalConnectionEndpoint extends ConnectionEndpoint {
+
+        private final HttpRoute route;
+        private final AtomicReference<ManagedHttpClientConnection> connRef;
+
+        public InternalConnectionEndpoint(final HttpRoute route, final ManagedHttpClientConnection conn) {
+            this.route = route;
+            this.connRef = new AtomicReference<>(conn);
+        }
+
+        HttpRoute getRoute() {
+            return route;
+        }
+
+        ManagedHttpClientConnection getConnection() {
+            final ManagedHttpClientConnection conn = this.connRef.get();
+            if (conn == null) {
+                throw new ConnectionShutdownException();
+            }
+            return conn;
+        }
+
+        ManagedHttpClientConnection getValidatedConnection() {
+            final ManagedHttpClientConnection conn = getConnection();
+            Asserts.check(conn.isOpen(), "Endpoint is not connected");
+            return conn;
+        }
+
+        ManagedHttpClientConnection detach() {
+            return this.connRef.getAndSet(null);
         }
+
+        @Override
+        public boolean isConnected() {
+            final ManagedHttpClientConnection conn = getConnection();
+            return conn != null && conn.isOpen();
+        }
+
+        @Override
+        public void shutdown() throws IOException {
+            final ManagedHttpClientConnection conn = detach();
+            if (conn != null) {
+                conn.shutdown();
+            }
+        }
+
+        @Override
+        public void close() throws IOException {
+            final ManagedHttpClientConnection conn = detach();
+            if (conn != null) {
+                conn.close();
+            }
+        }
+
+        @Override
+        public void setSocketTimeout(final int timeout) {
+            getValidatedConnection().setSocketTimeout(timeout);
+        }
+
+        @Override
+        public ClassicHttpResponse execute(
+                final ClassicHttpRequest request,
+                final HttpRequestExecutor requestExecutor,
+                final HttpContext context) throws IOException, HttpException {
+            Args.notNull(request, "HTTP request");
+            Args.notNull(requestExecutor, "Request executor");
+            return requestExecutor.execute(request, getValidatedConnection(), context);
+        }
+
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java Thu Feb 23 14:32:24 2017
@@ -48,6 +48,7 @@ import org.apache.hc.client5.http.socket
 import org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory;
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ConnectionClosedException;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.config.Lookup;
 import org.apache.hc.core5.http.config.SocketConfig;
@@ -191,6 +192,9 @@ public class DefaultHttpClientConnection
         }
         final LayeredConnectionSocketFactory lsf = (LayeredConnectionSocketFactory) sf;
         Socket sock = conn.getSocket();
+        if (sock == null) {
+            throw new ConnectionClosedException("Connection is closed");
+        }
         final int port = this.schemePortResolver.resolve(host);
         sock = lsf.createLayeredSocket(sock, host.getHostName(), port, context);
         conn.bind(sock);

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java Thu Feb 23 14:32:24 2017
@@ -32,35 +32,41 @@ import java.io.InterruptedIOException;
 import java.net.Socket;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CharsetEncoder;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.net.ssl.SSLSession;
 import javax.net.ssl.SSLSocket;
 
+import org.apache.hc.client5.http.impl.logging.LoggingSocketHolder;
 import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
+import org.apache.hc.client5.http.utils.Identifiable;
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ContentLengthStrategy;
-import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnection;
 import org.apache.hc.core5.http.impl.io.SocketHolder;
 import org.apache.hc.core5.http.io.HttpMessageParserFactory;
 import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
-import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.http.message.RequestLine;
+import org.apache.hc.core5.http.message.StatusLine;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 
 /**
  * Default {@link ManagedHttpClientConnection} implementation.
  * @since 4.3
  */
-public class DefaultManagedHttpClientConnection extends DefaultBHttpClientConnection
-        implements ManagedHttpClientConnection, HttpContext {
+public class DefaultManagedHttpClientConnection
+        extends DefaultBHttpClientConnection implements ManagedHttpClientConnection, Identifiable {
 
-    private final String id;
-    private final Map<String, Object> attributes;
+    private final Logger log = LogManager.getLogger(DefaultManagedHttpClientConnection.class);
+    private final Logger headerlog = LogManager.getLogger("org.apache.hc.client5.http.headers");
+    private final Logger wirelog = LogManager.getLogger("org.apache.hc.client5.http.wire");
 
-    private volatile boolean shutdown;
+    private final String id;
+    private final AtomicBoolean closed;
 
     public DefaultManagedHttpClientConnection(
             final String id,
@@ -75,7 +81,7 @@ public class DefaultManagedHttpClientCon
         super(buffersize, chardecoder, charencoder, h1Config, incomingContentStrategy, outgoingContentStrategy,
                 requestWriterFactory, responseParserFactory);
         this.id = id;
-        this.attributes = new ConcurrentHashMap<>();
+        this.closed = new AtomicBoolean();
     }
 
     public DefaultManagedHttpClientConnection(
@@ -90,14 +96,8 @@ public class DefaultManagedHttpClientCon
     }
 
     @Override
-    public void shutdown() throws IOException {
-        this.shutdown = true;
-        super.shutdown();
-    }
-
-    @Override
     public void bind(final SocketHolder socketHolder) throws IOException {
-        if (this.shutdown) {
+        if (this.closed.get()) {
             final Socket socket = socketHolder.getSocket();
             socket.close(); // allow this to throw...
             // ...but if it doesn't, explicitly throw one ourselves.
@@ -123,22 +123,58 @@ public class DefaultManagedHttpClientCon
     }
 
     @Override
-    public void setProtocolVersion(final ProtocolVersion version) {
+    public void close() throws IOException {
+        if (this.closed.compareAndSet(false, true)) {
+            if (this.log.isDebugEnabled()) {
+                this.log.debug(this.id + ": Close connection");
+            }
+            super.close();
+        }
+    }
+
+    @Override
+    public void setSocketTimeout(final int timeout) {
+        if (this.log.isDebugEnabled()) {
+            this.log.debug(this.id + ": set socket timeout to " + timeout);
+        }
+        super.setSocketTimeout(timeout);
     }
 
     @Override
-    public Object getAttribute(final String id) {
-        return this.attributes.get(id);
+    public void shutdown() throws IOException {
+        if (this.closed.compareAndSet(false, true)) {
+            if (this.log.isDebugEnabled()) {
+                this.log.debug(this.id + ": Shutdown connection");
+            }
+            super.shutdown();
+        }
     }
 
     @Override
-    public void setAttribute(final String id, final Object obj) {
-        this.attributes.put(id, obj);
+    public void bind(final Socket socket) throws IOException {
+        super.bind(this.wirelog.isDebugEnabled() ? new LoggingSocketHolder(socket, this.id, this.wirelog) : new SocketHolder(socket));
     }
 
     @Override
-    public Object removeAttribute(final String id) {
-        return this.attributes.remove(id);
+    protected void onResponseReceived(final ClassicHttpResponse response) {
+        if (response != null && this.headerlog.isDebugEnabled()) {
+            this.headerlog.debug(this.id + " << " + new StatusLine(response));
+            final Header[] headers = response.getAllHeaders();
+            for (final Header header : headers) {
+                this.headerlog.debug(this.id + " << " + header.toString());
+            }
+        }
+    }
+
+    @Override
+    protected void onRequestSubmitted(final ClassicHttpRequest request) {
+        if (request != null && this.headerlog.isDebugEnabled()) {
+            this.headerlog.debug(this.id + " >> " + new RequestLine(request));
+            final Header[] headers = request.getAllHeaders();
+            for (final Header header : headers) {
+                this.headerlog.debug(this.id + " >> " + header.toString());
+            }
+        }
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java Thu Feb 23 14:32:24 2017
@@ -27,14 +27,14 @@
 
 package org.apache.hc.client5.http.impl.io;
 
+import java.io.IOException;
+import java.net.Socket;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CharsetEncoder;
 import java.nio.charset.CodingErrorAction;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.apache.hc.client5.http.HttpConnectionFactory;
-import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
@@ -45,43 +45,38 @@ import org.apache.hc.core5.http.config.C
 import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
 import org.apache.hc.core5.http.impl.io.DefaultHttpRequestWriterFactory;
+import org.apache.hc.core5.http.io.HttpConnectionFactory;
 import org.apache.hc.core5.http.io.HttpMessageParserFactory;
 import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 
 /**
  * Factory for {@link ManagedHttpClientConnection} instances.
  * @since 4.3
  */
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
-public class ManagedHttpClientConnectionFactory implements HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> {
+public class ManagedHttpClientConnectionFactory implements HttpConnectionFactory<ManagedHttpClientConnection> {
 
     private static final AtomicLong COUNTER = new AtomicLong();
 
     public static final ManagedHttpClientConnectionFactory INSTANCE = new ManagedHttpClientConnectionFactory();
 
-    private final Logger log = LogManager.getLogger(DefaultManagedHttpClientConnection.class);
-    private final Logger headerlog = LogManager.getLogger("org.apache.hc.client5.http.headers");
-    private final Logger wirelog = LogManager.getLogger("org.apache.hc.client5.http.wire");
-
     private final H1Config h1Config;
+    private final ConnectionConfig connectionConfig;
     private final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory;
     private final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory;
     private final ContentLengthStrategy incomingContentStrategy;
     private final ContentLengthStrategy outgoingContentStrategy;
 
-    /**
-     * @since 4.4
-     */
     public ManagedHttpClientConnectionFactory(
             final H1Config h1Config,
+            final ConnectionConfig connectionConfig,
             final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory,
             final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory,
             final ContentLengthStrategy incomingContentStrategy,
             final ContentLengthStrategy outgoingContentStrategy) {
         super();
         this.h1Config = h1Config != null ? h1Config : H1Config.DEFAULT;
+        this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
         this.requestWriterFactory = requestWriterFactory != null ? requestWriterFactory :
                 DefaultHttpRequestWriterFactory.INSTANCE;
         this.responseParserFactory = responseParserFactory != null ? responseParserFactory :
@@ -94,31 +89,32 @@ public class ManagedHttpClientConnection
 
     public ManagedHttpClientConnectionFactory(
             final H1Config h1Config,
+            final ConnectionConfig connectionConfig,
             final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory,
             final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory) {
-        this(h1Config, requestWriterFactory, responseParserFactory, null, null);
+        this(h1Config, connectionConfig, requestWriterFactory, responseParserFactory, null, null);
     }
 
     public ManagedHttpClientConnectionFactory(
             final H1Config h1Config,
+            final ConnectionConfig connectionConfig,
             final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory) {
-        this(h1Config, null, responseParserFactory);
+        this(h1Config, connectionConfig, null, responseParserFactory);
     }
 
     public ManagedHttpClientConnectionFactory() {
-        this(null, null);
+        this(null, null, null);
     }
 
     @Override
-    public ManagedHttpClientConnection create(final HttpRoute route, final ConnectionConfig config) {
-        final ConnectionConfig cconfig = config != null ? config : ConnectionConfig.DEFAULT;
+    public ManagedHttpClientConnection createConnection(final Socket socket) throws IOException {
         CharsetDecoder chardecoder = null;
         CharsetEncoder charencoder = null;
-        final Charset charset = cconfig.getCharset();
-        final CodingErrorAction malformedInputAction = cconfig.getMalformedInputAction() != null ?
-                cconfig.getMalformedInputAction() : CodingErrorAction.REPORT;
-        final CodingErrorAction unmappableInputAction = cconfig.getUnmappableInputAction() != null ?
-                cconfig.getUnmappableInputAction() : CodingErrorAction.REPORT;
+        final Charset charset = this.connectionConfig.getCharset();
+        final CodingErrorAction malformedInputAction = this.connectionConfig.getMalformedInputAction() != null ?
+                this.connectionConfig.getMalformedInputAction() : CodingErrorAction.REPORT;
+        final CodingErrorAction unmappableInputAction = this.connectionConfig.getUnmappableInputAction() != null ?
+                this.connectionConfig.getUnmappableInputAction() : CodingErrorAction.REPORT;
         if (charset != null) {
             chardecoder = charset.newDecoder();
             chardecoder.onMalformedInput(malformedInputAction);
@@ -128,12 +124,9 @@ public class ManagedHttpClientConnection
             charencoder.onUnmappableCharacter(unmappableInputAction);
         }
         final String id = "http-outgoing-" + Long.toString(COUNTER.getAndIncrement());
-        return new LoggingManagedHttpClientConnection(
+        final DefaultManagedHttpClientConnection conn = new DefaultManagedHttpClientConnection(
                 id,
-                log,
-                headerlog,
-                wirelog,
-                cconfig.getBufferSize(),
+                connectionConfig.getBufferSize(),
                 chardecoder,
                 charencoder,
                 h1Config,
@@ -141,6 +134,10 @@ public class ManagedHttpClientConnection
                 outgoingContentStrategy,
                 requestWriterFactory,
                 responseParserFactory);
+        if (socket != null) {
+            conn.bind(socket);
+        }
+        return conn;
     }
 
 }



Mime
View raw message