hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1784138 [3/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
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MainClientExec.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MainClientExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MainClientExec.java Thu Feb 23 14:32:24 2017
@@ -31,6 +31,7 @@ import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 import org.apache.hc.client5.http.ConnectionKeepAliveStrategy;
 import org.apache.hc.client5.http.HttpRoute;
@@ -39,10 +40,11 @@ import org.apache.hc.client5.http.auth.A
 import org.apache.hc.client5.http.auth.ChallengeType;
 import org.apache.hc.client5.http.config.RequestConfig;
 import org.apache.hc.client5.http.impl.auth.HttpAuthenticator;
-import org.apache.hc.client5.http.impl.io.ConnectionShutdownException;
+import org.apache.hc.client5.http.impl.ConnectionShutdownException;
 import org.apache.hc.client5.http.impl.routing.BasicRouteDirector;
-import org.apache.hc.client5.http.io.ConnectionRequest;
+import org.apache.hc.client5.http.io.ConnectionEndpoint;
 import org.apache.hc.client5.http.io.HttpClientConnectionManager;
+import org.apache.hc.client5.http.io.LeaseRequest;
 import org.apache.hc.client5.http.methods.HttpExecutionAware;
 import org.apache.hc.client5.http.methods.RoutedHttpRequest;
 import org.apache.hc.client5.http.protocol.AuthenticationStrategy;
@@ -54,6 +56,7 @@ import org.apache.hc.core5.annotation.Co
 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.ConnectionRequestTimeoutException;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpException;
@@ -64,7 +67,6 @@ import org.apache.hc.core5.http.HttpResp
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
-import org.apache.hc.core5.http.io.HttpClientConnection;
 import org.apache.hc.core5.http.io.entity.BufferedHttpEntity;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
@@ -162,22 +164,24 @@ public class MainClientExec implements C
 
         Object userToken = context.getUserToken();
 
-        final ConnectionRequest connRequest = connManager.requestConnection(route, userToken);
+        final LeaseRequest leaseRequest = connManager.lease(route, userToken);
         if (execAware != null) {
             if (execAware.isAborted()) {
-                connRequest.cancel();
+                leaseRequest.cancel();
                 throw new RequestAbortedException("Request aborted");
             } else {
-                execAware.setCancellable(connRequest);
+                execAware.setCancellable(leaseRequest);
             }
         }
 
         final RequestConfig config = context.getRequestConfig();
 
-        final HttpClientConnection managedConn;
+        final ConnectionEndpoint endpoint;
         try {
             final int timeout = config.getConnectionRequestTimeout();
-            managedConn = connRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS);
+            endpoint = leaseRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS);
+        } catch(final TimeoutException ex) {
+            throw new ConnectionRequestTimeoutException(ex.getMessage());
         } catch(final InterruptedException interrupted) {
             Thread.currentThread().interrupt();
             throw new RequestAbortedException("Request aborted", interrupted);
@@ -189,12 +193,12 @@ public class MainClientExec implements C
             throw new RequestAbortedException("Request execution failed", cause);
         }
 
-        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, managedConn);
+        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, endpoint);
 
-        final ConnectionHolder connHolder = new ConnectionHolder(this.log, this.connManager, managedConn);
+        final EndpointHolder endpointHolder = new EndpointHolder(this.log, this.connManager, endpoint);
         try {
             if (execAware != null) {
-                execAware.setCancellable(connHolder);
+                execAware.setCancellable(endpointHolder);
             }
 
             final AuthExchange targetAuthExchange = context.getAuthExchange(route.getTargetHost());
@@ -213,10 +217,12 @@ public class MainClientExec implements C
                     throw new RequestAbortedException("Request aborted");
                 }
 
-                if (!managedConn.isOpen()) {
+                if (!endpoint.isConnected()) {
+                    endpointHolder.markNonReusable();
                     this.log.debug("Opening connection " + route);
                     try {
-                        establishRoute(managedConn, route, request, context);
+                        establishRoute(endpoint, route, request, context);
+                        endpointHolder.markReusable();
                     } catch (final TunnelRefusedException ex) {
                         if (this.log.isDebugEnabled()) {
                             this.log.debug(ex.getMessage());
@@ -227,7 +233,7 @@ public class MainClientExec implements C
                 }
                 final int timeout = config.getSocketTimeout();
                 if (timeout >= 0) {
-                    managedConn.setSocketTimeout(timeout);
+                    endpoint.setSocketTimeout(timeout);
                 }
 
                 if (execAware != null && execAware.isAborted()) {
@@ -253,7 +259,7 @@ public class MainClientExec implements C
                             route.getProxyHost(), ChallengeType.PROXY, request, proxyAuthExchange, context);
                 }
 
-                response = requestExecutor.execute(request, managedConn, context);
+                response = endpoint.execute(request, requestExecutor, context);
 
                 // The connection is in or can be brought to a re-usable state.
                 if (reuseStrategy.keepAlive(request, response, context)) {
@@ -268,10 +274,10 @@ public class MainClientExec implements C
                         }
                         this.log.debug("Connection can be kept alive " + s);
                     }
-                    connHolder.setValidFor(duration, TimeUnit.MILLISECONDS);
-                    connHolder.markReusable();
+                    endpointHolder.setValidFor(duration, TimeUnit.MILLISECONDS);
+                    endpointHolder.markReusable();
                 } else {
-                    connHolder.markNonReusable();
+                    endpointHolder.markNonReusable();
                 }
 
                 if (request.getMethod().equalsIgnoreCase("TRACE")) {
@@ -283,10 +289,10 @@ public class MainClientExec implements C
                         targetAuthExchange, proxyAuthExchange, route, request, response, context)) {
                     // Make sure the response body is fully consumed, if present
                     final HttpEntity entity = response.getEntity();
-                    if (connHolder.isReusable()) {
+                    if (endpointHolder.isReusable()) {
                         EntityUtils.consume(entity);
                     } else {
-                        managedConn.close();
+                        endpoint.close();
                         if (proxyAuthExchange.getState() == AuthExchange.State.SUCCESS
                                 && proxyAuthExchange.getAuthScheme() != null
                                 && proxyAuthExchange.getAuthScheme().isConnectionBased()) {
@@ -318,18 +324,18 @@ public class MainClientExec implements C
                 context.setAttribute(HttpClientContext.USER_TOKEN, userToken);
             }
             if (userToken != null) {
-                connHolder.setState(userToken);
+                endpointHolder.setState(userToken);
             }
 
             // check for entity, release connection if possible
             final HttpEntity entity = response.getEntity();
             if (entity == null || !entity.isStreaming()) {
                 // connection not needed and (assumed to be) in re-usable state
-                connHolder.releaseConnection();
+                endpointHolder.releaseConnection();
                 return new CloseableHttpResponse(response, null);
             } else {
-                ResponseEntityProxy.enchance(response, connHolder);
-                return new CloseableHttpResponse(response, connHolder);
+                ResponseEntityProxy.enchance(response, endpointHolder);
+                return new CloseableHttpResponse(response, endpointHolder);
             }
         } catch (final ConnectionShutdownException ex) {
             final InterruptedIOException ioex = new InterruptedIOException(
@@ -337,7 +343,7 @@ public class MainClientExec implements C
             ioex.initCause(ex);
             throw ioex;
         } catch (final HttpException | RuntimeException | IOException ex) {
-            connHolder.abortConnection();
+            endpointHolder.abortConnection();
             throw ex;
         }
     }
@@ -346,7 +352,7 @@ public class MainClientExec implements C
      * Establishes the target route.
      */
     void establishRoute(
-            final HttpClientConnection managedConn,
+            final ConnectionEndpoint endpoint,
             final HttpRoute route,
             final HttpRequest request,
             final HttpClientContext context) throws HttpException, IOException {
@@ -362,23 +368,23 @@ public class MainClientExec implements C
 
             case HttpRouteDirector.CONNECT_TARGET:
                 this.connManager.connect(
-                        managedConn,
-                        route,
+                        endpoint,
                         timeout > 0 ? timeout : 0,
+                        TimeUnit.MILLISECONDS,
                         context);
                 tracker.connectTarget(route.isSecure());
                 break;
             case HttpRouteDirector.CONNECT_PROXY:
                 this.connManager.connect(
-                        managedConn,
-                        route,
+                        endpoint,
                         timeout > 0 ? timeout : 0,
+                        TimeUnit.MILLISECONDS,
                         context);
                 final HttpHost proxy  = route.getProxyHost();
                 tracker.connectProxy(proxy, false);
                 break;
             case HttpRouteDirector.TUNNEL_TARGET: {
-                final boolean secure = createTunnelToTarget(managedConn, route, request, context);
+                final boolean secure = createTunnelToTarget(endpoint, route, request, context);
                 this.log.debug("Tunnel to target created.");
                 tracker.tunnelTarget(secure);
             }   break;
@@ -395,7 +401,7 @@ public class MainClientExec implements C
             }   break;
 
             case HttpRouteDirector.LAYER_PROTOCOL:
-                this.connManager.upgrade(managedConn, route, context);
+                this.connManager.upgrade(endpoint, context);
                 tracker.layerProtocol(route.isSecure());
                 break;
 
@@ -403,7 +409,6 @@ public class MainClientExec implements C
                 throw new HttpException("Unable to establish route: " +
                         "planned = " + route + "; current = " + fact);
             case HttpRouteDirector.COMPLETE:
-                this.connManager.routeComplete(managedConn, route, context);
                 break;
             default:
                 throw new IllegalStateException("Unknown step indicator "
@@ -422,7 +427,7 @@ public class MainClientExec implements C
      * information about the tunnel, that is left to the caller.
      */
     private boolean createTunnelToTarget(
-            final HttpClientConnection managedConn,
+            final ConnectionEndpoint endpoint,
             final HttpRoute route,
             final HttpRequest request,
             final HttpClientContext context) throws HttpException, IOException {
@@ -442,18 +447,18 @@ public class MainClientExec implements C
         this.requestExecutor.preProcess(connect, this.proxyHttpProcessor, context);
 
         while (response == null) {
-            if (!managedConn.isOpen()) {
+            if (!endpoint.isConnected()) {
                 this.connManager.connect(
-                        managedConn,
-                        route,
+                        endpoint,
                         timeout > 0 ? timeout : 0,
+                        TimeUnit.MILLISECONDS,
                         context);
             }
 
             connect.removeHeaders(HttpHeaders.PROXY_AUTHORIZATION);
             this.authenticator.addAuthResponse(proxy, ChallengeType.PROXY, connect, proxyAuthExchange, context);
 
-            response = this.requestExecutor.execute(connect, managedConn, context);
+            response = endpoint.execute(connect, this.requestExecutor, context);
 
             final int status = response.getCode();
             if (status < HttpStatus.SC_SUCCESS) {
@@ -472,7 +477,7 @@ public class MainClientExec implements C
                             final HttpEntity entity = response.getEntity();
                             EntityUtils.consume(entity);
                         } else {
-                            managedConn.close();
+                            endpoint.close();
                         }
                         response = null;
                     }
@@ -489,7 +494,7 @@ public class MainClientExec implements C
                 response.setEntity(new BufferedHttpEntity(entity));
             }
 
-            managedConn.close();
+            endpoint.close();
             throw new TunnelRefusedException("CONNECT refused by proxy: " +
                     new StatusLine(response), response);
         }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalClientExec.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalClientExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalClientExec.java Thu Feb 23 14:32:24 2017
@@ -31,13 +31,16 @@ import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 import org.apache.hc.client5.http.ConnectionKeepAliveStrategy;
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.config.RequestConfig;
-import org.apache.hc.client5.http.impl.io.ConnectionShutdownException;
-import org.apache.hc.client5.http.io.ConnectionRequest;
+import org.apache.hc.client5.http.impl.DefaultConnectionKeepAliveStrategy;
+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.LeaseRequest;
 import org.apache.hc.client5.http.methods.HttpExecutionAware;
 import org.apache.hc.client5.http.methods.RoutedHttpRequest;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
@@ -45,11 +48,12 @@ import org.apache.hc.client5.http.protoc
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.ConnectionRequestTimeoutException;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
-import org.apache.hc.core5.http.io.HttpClientConnection;
 import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
@@ -86,20 +90,16 @@ public class MinimalClientExec implement
             final HttpClientConnectionManager connManager,
             final ConnectionReuseStrategy reuseStrategy,
             final ConnectionKeepAliveStrategy keepAliveStrategy) {
-        Args.notNull(requestExecutor, "HTTP request executor");
-        Args.notNull(connManager, "Client connection manager");
-        Args.notNull(reuseStrategy, "Connection reuse strategy");
-        Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
+        this.requestExecutor = Args.notNull(requestExecutor, "Request executor");
+        this.connManager = Args.notNull(connManager, "Connection manager");
+        this.reuseStrategy = reuseStrategy != null ? reuseStrategy : DefaultConnectionReuseStrategy.INSTANCE;
+        this.keepAliveStrategy = keepAliveStrategy != null ? keepAliveStrategy : DefaultConnectionKeepAliveStrategy.INSTANCE;
         this.httpProcessor = new DefaultHttpProcessor(
                 new RequestContent(),
                 new RequestTargetHost(),
                 new RequestClientConnControl(),
                 new RequestUserAgent(VersionInfo.getSoftwareInfo(
                         "Apache-HttpClient", "org.apache.hc.client5", getClass())));
-        this.requestExecutor    = requestExecutor;
-        this.connManager        = connManager;
-        this.reuseStrategy      = reuseStrategy;
-        this.keepAliveStrategy  = keepAliveStrategy;
     }
 
     @Override
@@ -111,7 +111,7 @@ public class MinimalClientExec implement
         Args.notNull(context, "HTTP context");
 
         final HttpRoute route = request.getRoute();
-        final ConnectionRequest connRequest = connManager.requestConnection(route, null);
+        final LeaseRequest connRequest = connManager.lease(route, null);
         if (execAware != null) {
             if (execAware.isAborted()) {
                 connRequest.cancel();
@@ -122,10 +122,12 @@ public class MinimalClientExec implement
 
         final RequestConfig config = context.getRequestConfig();
 
-        final HttpClientConnection managedConn;
+        final ConnectionEndpoint endpoint;
         try {
             final int timeout = config.getConnectionRequestTimeout();
-            managedConn = connRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS);
+            endpoint = connRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS);
+        } catch(final TimeoutException ex) {
+            throw new ConnectionRequestTimeoutException(ex.getMessage());
         } catch(final InterruptedException interrupted) {
             Thread.currentThread().interrupt();
             throw new RequestAbortedException("Request aborted", interrupted);
@@ -137,57 +139,54 @@ public class MinimalClientExec implement
             throw new RequestAbortedException("Request execution failed", cause);
         }
 
-        final ConnectionHolder connHolder = new ConnectionHolder(log, connManager, managedConn);
+        final EndpointHolder endpointHolder = new EndpointHolder(log, connManager, endpoint);
         try {
             if (execAware != null) {
                 if (execAware.isAborted()) {
-                    connHolder.close();
+                    endpointHolder.close();
                     throw new RequestAbortedException("Request aborted");
                 }
-                execAware.setCancellable(connHolder);
+                execAware.setCancellable(endpointHolder);
             }
-
-            if (!managedConn.isOpen()) {
+            if (!endpoint.isConnected()) {
                 final int timeout = config.getConnectTimeout();
                 this.connManager.connect(
-                    managedConn,
-                    route,
-                    timeout > 0 ? timeout : 0,
-                    context);
-                this.connManager.routeComplete(managedConn, route, context);
+                        endpoint,
+                        timeout > 0 ? timeout : 0,
+                        TimeUnit.MILLISECONDS,
+                        context);
             }
             final int timeout = config.getSocketTimeout();
             if (timeout >= 0) {
-                managedConn.setSocketTimeout(timeout);
+                endpoint.setSocketTimeout(timeout);
             }
 
             context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
-            context.setAttribute(HttpCoreContext.HTTP_CONNECTION, managedConn);
             context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
 
             httpProcessor.process(request, request.getEntity(), context);
-            final ClassicHttpResponse response = requestExecutor.execute(request, managedConn, context);
+            final ClassicHttpResponse response = endpoint.execute(request, requestExecutor, context);
             httpProcessor.process(response, response.getEntity(), context);
 
             // The connection is in or can be brought to a re-usable state.
             if (reuseStrategy.keepAlive(request, response, context)) {
                 // Set the idle duration of this connection
                 final long duration = keepAliveStrategy.getKeepAliveDuration(response, context);
-                connHolder.setValidFor(duration, TimeUnit.MILLISECONDS);
-                connHolder.markReusable();
+                endpointHolder.setValidFor(duration, TimeUnit.MILLISECONDS);
+                endpointHolder.markReusable();
             } else {
-                connHolder.markNonReusable();
+                endpointHolder.markNonReusable();
             }
 
             // check for entity, release connection if possible
             final HttpEntity entity = response.getEntity();
             if (entity == null || !entity.isStreaming()) {
                 // connection not needed and (assumed to be) in re-usable state
-                connHolder.releaseConnection();
+                endpointHolder.releaseConnection();
                 return new CloseableHttpResponse(response, null);
             } else {
-                ResponseEntityProxy.enchance(response, connHolder);
-                return new CloseableHttpResponse(response, connHolder);
+                ResponseEntityProxy.enchance(response, endpointHolder);
+                return new CloseableHttpResponse(response, endpointHolder);
             }
         } catch (final ConnectionShutdownException ex) {
             final InterruptedIOException ioex = new InterruptedIOException(
@@ -195,7 +194,7 @@ public class MinimalClientExec implement
             ioex.initCause(ex);
             throw ioex;
         } catch (final HttpException | RuntimeException | IOException ex) {
-            connHolder.abortConnection();
+            endpointHolder.abortConnection();
             throw ex;
         }
     }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalHttpClient.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/MinimalHttpClient.java Thu Feb 23 14:32:24 2017
@@ -110,8 +110,8 @@ class MinimalHttpClient extends Closeabl
     }
 
     @Override
-    public void close() {
-        this.connManager.shutdown();
+    public void close() throws IOException {
+        this.connManager.close();
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ProxyClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ProxyClient.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ProxyClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ProxyClient.java Thu Feb 23 14:32:24 2017
@@ -30,7 +30,6 @@ package org.apache.hc.client5.http.impl.
 import java.io.IOException;
 import java.net.Socket;
 
-import org.apache.hc.client5.http.HttpConnectionFactory;
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.RouteInfo.LayerType;
 import org.apache.hc.client5.http.RouteInfo.TunnelType;
@@ -66,6 +65,7 @@ import org.apache.hc.core5.http.config.L
 import org.apache.hc.core5.http.config.RegistryBuilder;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
+import org.apache.hc.core5.http.io.HttpConnectionFactory;
 import org.apache.hc.core5.http.io.entity.BufferedHttpEntity;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
@@ -83,7 +83,7 @@ import org.apache.hc.core5.util.Args;
  */
 public class ProxyClient {
 
-    private final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory;
+    private final HttpConnectionFactory<ManagedHttpClientConnection> connFactory;
     private final ConnectionConfig connectionConfig;
     private final RequestConfig requestConfig;
     private final HttpProcessor httpProcessor;
@@ -98,7 +98,7 @@ public class ProxyClient {
      * @since 4.3
      */
     public ProxyClient(
-            final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
+            final HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
             final ConnectionConfig connectionConfig,
             final RequestConfig requestConfig) {
         super();
@@ -148,8 +148,7 @@ public class ProxyClient {
                 this.requestConfig.getLocalAddress(),
                 proxy, false, TunnelType.TUNNELLED, LayerType.PLAIN);
 
-        final ManagedHttpClientConnection conn = this.connFactory.create(
-                route, this.connectionConfig);
+        final ManagedHttpClientConnection conn = this.connFactory.createConnection(null);
         final HttpContext context = new BasicHttpContext();
         ClassicHttpResponse response;
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RedirectExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RedirectExec.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RedirectExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RedirectExec.java Thu Feb 23 14:32:24 2017
@@ -146,7 +146,7 @@ public class RedirectExec implements Cli
                         }
                     }
 
-                    currentRoute = this.routePlanner.determineRoute(newTarget, redirect, context);
+                    currentRoute = this.routePlanner.determineRoute(newTarget, context);
                     if (this.log.isDebugEnabled()) {
                         this.log.debug("Redirecting to '" + redirectUri + "' via " + currentRoute);
                     }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ResponseEntityProxy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ResponseEntityProxy.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ResponseEntityProxy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ResponseEntityProxy.java Thu Feb 23 14:32:24 2017
@@ -45,35 +45,35 @@ import org.apache.hc.core5.http.io.entit
  */
 class ResponseEntityProxy extends HttpEntityWrapper implements EofSensorWatcher {
 
-    private final ConnectionHolder connHolder;
+    private final EndpointHolder endpointHolder;
 
-    public static void enchance(final ClassicHttpResponse response, final ConnectionHolder connHolder) {
+    public static void enchance(final ClassicHttpResponse response, final EndpointHolder connHolder) {
         final HttpEntity entity = response.getEntity();
         if (entity != null && entity.isStreaming() && connHolder != null) {
             response.setEntity(new ResponseEntityProxy(entity, connHolder));
         }
     }
 
-    ResponseEntityProxy(final HttpEntity entity, final ConnectionHolder connHolder) {
+    ResponseEntityProxy(final HttpEntity entity, final EndpointHolder endpointHolder) {
         super(entity);
-        this.connHolder = connHolder;
+        this.endpointHolder = endpointHolder;
     }
 
     private void cleanup() throws IOException {
-        if (this.connHolder != null) {
-            this.connHolder.close();
+        if (this.endpointHolder != null) {
+            this.endpointHolder.close();
         }
     }
 
     private void abortConnection() {
-        if (this.connHolder != null) {
-            this.connHolder.abortConnection();
+        if (this.endpointHolder != null) {
+            this.endpointHolder.abortConnection();
         }
     }
 
     public void releaseConnection() {
-        if (this.connHolder != null) {
-            this.connHolder.releaseConnection();
+        if (this.endpointHolder != null) {
+            this.endpointHolder.releaseConnection();
         }
     }
 
@@ -123,7 +123,7 @@ class ResponseEntityProxy extends HttpEn
     @Override
     public boolean streamClosed(final InputStream wrapped) throws IOException {
         try {
-            final boolean open = connHolder != null && !connHolder.isReleased();
+            final boolean open = endpointHolder != null && !endpointHolder.isReleased();
             // this assumes that closing the stream will
             // consume the remainder of the response body:
             try {

Copied: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionEndpoint.java (from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ConnectionPoolTimeoutException.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionEndpoint.java?p2=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionEndpoint.java&p1=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ConnectionPoolTimeoutException.java&r1=1784071&r2=1784138&rev=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ConnectionPoolTimeoutException.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionEndpoint.java Thu Feb 23 14:32:24 2017
@@ -25,33 +25,36 @@
  *
  */
 
-package org.apache.hc.client5.http;
+package org.apache.hc.client5.http.io;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+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.impl.io.HttpRequestExecutor;
+import org.apache.hc.core5.http.protocol.HttpContext;
 
 /**
- * A timeout while waiting for an available connection
- * from a connection manager.
- *
+ * Client connection endpoint that can be used to execute message exchanges.
  *
- * @since 4.0
+ * @since 5.0
  */
-public class ConnectionPoolTimeoutException extends ConnectTimeoutException {
+@Contract(threading = ThreadingBehavior.SAFE)
+public abstract class ConnectionEndpoint implements Closeable {
+
+    public abstract ClassicHttpResponse execute(
+            ClassicHttpRequest request,
+            HttpRequestExecutor executor,
+            HttpContext context) throws IOException, HttpException;
+
+    public abstract boolean isConnected();
 
-    private static final long serialVersionUID = -7898874842020245128L;
+    public abstract void setSocketTimeout(int timeout);
 
-    /**
-     * Creates a ConnectTimeoutException with a {@code null} detail message.
-     */
-    public ConnectionPoolTimeoutException() {
-        super();
-    }
-
-    /**
-     * Creates a ConnectTimeoutException with the specified detail message.
-     *
-     * @param message The exception detail message
-     */
-    public ConnectionPoolTimeoutException(final String message) {
-        super(message);
-    }
+    public abstract void shutdown() throws IOException;
 
 }

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

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

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

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/HttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/HttpClientConnectionManager.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/HttpClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/HttpClientConnectionManager.java Thu Feb 23 14:32:24 2017
@@ -26,11 +26,11 @@
  */
 package org.apache.hc.client5.http.io;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.core5.http.io.HttpClientConnection;
 import org.apache.hc.core5.http.protocol.HttpContext;
 
 /**
@@ -40,137 +40,77 @@ import org.apache.hc.core5.http.protocol
  * HTTP connections, manage persistent connections and synchronize access to
  * persistent connections making sure that only one thread of execution can
  * have access to a connection at a time.
- * </p>
  * <p>
  * Implementations of this interface must be thread-safe. Access to shared
  * data must be synchronized as methods of this interface may be executed
  * from multiple threads.
- * </p>
  *
  * @since 4.3
  */
-public interface HttpClientConnectionManager {
+public interface HttpClientConnectionManager extends Closeable {
 
     /**
-     * Returns a new {@link ConnectionRequest}, from which a
-     * {@link HttpClientConnection} can be obtained or the request can be
-     * aborted.
+     * Returns a {@link LeaseRequest} object which can be used to obtain
+     * a {@link ConnectionEndpoint} to cancel the request by calling
+     * {@link LeaseRequest#cancel()}.
      * <p>
-     * Please note that newly allocated connections can be returned
-     * in the closed state. The consumer of that connection is responsible
-     * for fully establishing the route the to the connection target
-     * by calling {@link #connect(HttpClientConnection, HttpRoute, int, HttpContext)}  connect} in order to connect
-     * directly to the target or to the first proxy hop, optionally calling
-     * {@link #upgrade(HttpClientConnection, HttpRoute, HttpContext)}  upgrade} method to upgrade
-     * the connection after having executed {@code CONNECT} method to
-     * all intermediate proxy hops and and finally calling {@link #routeComplete(HttpClientConnection, HttpRoute,
-     * HttpContext)} routeComplete} to mark the route
-     *  as fully completed.
-     * </p>
+     * Please note that newly allocated endpoints can be leased
+     * {@link ConnectionEndpoint#isConnected() disconnected}. The consumer of the endpoint
+     * is responsible for fully establishing the route to the endpoint target
+     * by calling {@link #connect(ConnectionEndpoint, long, TimeUnit, HttpContext)}
+     * in order to connect directly to the target or to the first proxy hop,
+     * and optionally calling {@link #upgrade(ConnectionEndpoint, HttpContext)} method
+     * to upgrade the underlying transport to Transport Layer Security after having
+     * executed a {@code CONNECT} method to all intermediate proxy hops.
      *
      * @param route HTTP route of the requested connection.
      * @param state expected state of the connection or {@code null}
      *              if the connection is not expected to carry any state.
      */
-    ConnectionRequest requestConnection(HttpRoute route, Object state);
+    LeaseRequest lease(HttpRoute route, Object state);
 
     /**
-     * Releases the connection back to the manager making it potentially
+     * Releases the endpoint back to the manager making it potentially
      * re-usable by other consumers. Optionally, the maximum period
      * of how long the manager should keep the connection alive can be
      * defined using {@code validDuration} and {@code timeUnit}
      * parameters.
      *
-     * @param conn      the managed connection to release.
+     * @param endpoint      the managed endpoint.
+     * @param newState      the new connection state of {@code null} if state-less.
      * @param validDuration the duration of time this connection is valid for reuse.
      * @param timeUnit the time unit.
      *
      * @see #closeExpired()
      */
-    void releaseConnection(
-            HttpClientConnection conn, Object newState, long validDuration, TimeUnit timeUnit);
+    void release(ConnectionEndpoint endpoint, Object newState, long validDuration, TimeUnit timeUnit);
 
     /**
-     * Connects the underlying connection socket to the connection target in case
+     * Connects the endpoint to the initial hop (connection target in case
      * of a direct route or to the first proxy hop in case of a route via a proxy
-     * (or multiple proxies).
+     * or multiple proxies).
      *
-     * @param conn the managed connection.
-     * @param route the route of the connection.
-     * @param connectTimeout connect timeout in milliseconds.
+     * @param endpoint      the managed endpoint.
+     * @param connectTimeout connect timeout.
+     * @param timeUnit the time unit.
      * @param context the actual HTTP context.
      * @throws IOException
      */
     void connect(
-            HttpClientConnection conn,
-            HttpRoute route,
-            int connectTimeout,
+            ConnectionEndpoint endpoint,
+            long connectTimeout,
+            TimeUnit timeUnit,
             HttpContext context) throws IOException;
 
     /**
-     * Upgrades the underlying connection socket to TLS/SSL (or another layering
-     * protocol) after having executed {@code CONNECT} method to all
-     * intermediate proxy hops
+     * Upgrades the endpoint's underlying transport to Transport Layer Security.
      *
-     * @param conn the managed connection.
-     * @param route the route of the connection.
+     * @param endpoint      the managed endpoint.
      * @param context the actual HTTP context.
      * @throws IOException
      */
     void upgrade(
-            HttpClientConnection conn,
-            HttpRoute route,
-            HttpContext context) throws IOException;
-
-    /**
-     * Marks the connection as fully established with all its intermediate
-     * hops completed.
-     *
-     * @param conn the managed connection.
-     * @param route the route of the connection.
-     * @param context the actual HTTP context.
-     * @throws IOException
-     */
-    void routeComplete(
-            HttpClientConnection conn,
-            HttpRoute route,
+            ConnectionEndpoint endpoint,
             HttpContext context) throws IOException;
 
-    /**
-     * Closes idle connections in the pool.
-     * <p>
-     * Open connections in the pool that have not been used for the
-     * timespan given by the argument will be closed.
-     * Currently allocated connections are not subject to this method.
-     * Times will be checked with milliseconds precision
-     * </p>
-     * <p>
-     * All expired connections will also be closed.
-     * </p>
-     *
-     * @param idletime  the idle time of connections to be closed
-     * @param tunit     the unit for the {@code idletime}
-     *
-     * @see #closeExpired()
-     */
-    void closeIdle(long idletime, TimeUnit tunit);
-
-    /**
-     * Closes all expired connections in the pool.
-     * <p>
-     * Open connections in the pool that have not been used for
-     * the timespan defined when the connection was released will be closed.
-     * Currently allocated connections are not subject to this method.
-     * Times will be checked with milliseconds precision.
-     * </p>
-     */
-    void closeExpired();
-
-    /**
-     * Shuts down this connection manager and releases allocated resources.
-     * This includes closing all connections, whether they are currently
-     * used or not.
-     */
-    void shutdown();
-
 }

Copied: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/LeaseRequest.java (from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionRequest.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/LeaseRequest.java?p2=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/LeaseRequest.java&p1=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionRequest.java&r1=1784071&r2=1784138&rev=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionRequest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/LeaseRequest.java Thu Feb 23 14:32:24 2017
@@ -29,21 +29,20 @@ package org.apache.hc.client5.http.io;
 
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
-import org.apache.hc.client5.http.ConnectionPoolTimeoutException;
 import org.apache.hc.core5.concurrent.Cancellable;
-import org.apache.hc.core5.http.io.HttpClientConnection;
 
 /**
- * Represents a request for a {@link HttpClientConnection} whose life cycle
+ * Represents a request for a {@link ConnectionEndpoint} whose life cycle
  * is managed by a connection manager.
  *
- * @since 4.3
+ * @since 5.0
  */
-public interface ConnectionRequest extends Cancellable {
+public interface LeaseRequest extends Cancellable {
 
     /**
-     * Obtains a connection within a given time.
+     * Returns {@link ConnectionEndpoint} within a given time.
      * This method will block until a connection becomes available,
      * the timeout expires, or the connection manager is shut down.
      * Timeouts are handled with millisecond precision.
@@ -59,12 +58,12 @@ public interface ConnectionRequest exten
      * @return  a connection that can be used to communicate
      *          along the given route
      *
-     * @throws ConnectionPoolTimeoutException
+     * @throws TimeoutException
      *         in case of a timeout
      * @throws InterruptedException
      *         if the calling thread is interrupted while waiting
      */
-    HttpClientConnection get(long timeout, TimeUnit tunit)
-        throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException;
+    ConnectionEndpoint get(long timeout, TimeUnit tunit)
+            throws InterruptedException, ExecutionException, TimeoutException;
 
-}
+}
\ No newline at end of file

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

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

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

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ManagedHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ManagedHttpClientConnection.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ManagedHttpClientConnection.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ManagedHttpClientConnection.java Thu Feb 23 14:32:24 2017
@@ -45,12 +45,6 @@ import org.apache.hc.core5.http.io.HttpC
 public interface ManagedHttpClientConnection extends HttpClientConnection {
 
     /**
-     * Returns connection ID which is expected to be unique
-     * for the life span of the connection manager.
-     */
-    String getId();
-
-    /**
      * Binds this connection to the given socket. The connection
      * is considered open if it is bound and the underlying socket
      * is connection to a remote host.

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/routing/HttpRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/routing/HttpRoutePlanner.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/routing/HttpRoutePlanner.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/routing/HttpRoutePlanner.java Thu Feb 23 14:32:24 2017
@@ -48,13 +48,9 @@ import org.apache.hc.core5.http.protocol
 public interface HttpRoutePlanner {
 
     /**
-     * Determines the route for a request.
+     * Determines the route for the given host.
      *
      * @param target    the target host for the request.
-     *                  Implementations may accept {@code null}
-     *                  if they can still determine a route, for example
-     *                  to a default target or by inspecting the request.
-     * @param request   the request to execute
      * @param context   the context to use for the subsequent execution.
      *                  Implementations may accept {@code null}.
      *
@@ -62,8 +58,19 @@ public interface HttpRoutePlanner {
      *
      * @throws HttpException    in case of a problem
      */
-    HttpRoute determineRoute(HttpHost target,
-                             HttpRequest request,
-                             HttpContext context) throws HttpException;
+    HttpRoute determineRoute(HttpHost target, HttpContext context) throws HttpException;
+
+    /**
+     * Determines the target host for the given request.
+     *
+     * @param request   the request to be executed
+     * @param context   the context to use for the subsequent execution.
+     *                  Implementations may accept {@code null}.
+     *
+     * @return  the route that the request should take
+     *
+     * @throws HttpException    in case of a problem
+     */
+    HttpHost determineTargetHost(HttpRequest request, HttpContext context) throws HttpException;
 
 }

Copied: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/utils/Identifiable.java (from r1784071, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/HttpConnectionFactory.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/utils/Identifiable.java?p2=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/utils/Identifiable.java&p1=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/HttpConnectionFactory.java&r1=1784071&r2=1784138&rev=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/HttpConnectionFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/utils/Identifiable.java Thu Feb 23 14:32:24 2017
@@ -24,18 +24,16 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.client5.http;
 
-import org.apache.hc.core5.http.HttpConnection;
-import org.apache.hc.core5.http.config.ConnectionConfig;
+package org.apache.hc.client5.http.utils;
 
 /**
- * Generic {@link HttpConnection} factory.
+ * Object with a unique identifier.
  *
- * @since 4.3
+ * @since 5.0
  */
-public interface HttpConnectionFactory<T, C extends HttpConnection> {
+public interface Identifiable {
 
-    C create(T route, ConnectionConfig config);
+    String getId();
 
 }

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

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

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

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/TestExceptions.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/TestExceptions.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/TestExceptions.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/TestExceptions.java Thu Feb 23 14:32:24 2017
@@ -115,15 +115,4 @@ public class TestExceptions {
         Assert.assertEquals("Connect to localhost [/1.2.3.4, /5.6.7.8] refused", ctx.getMessage());
     }
 
-    @Test
-    public void testConnectionPoolTimeoutException() {
-        final String msg = "sample exception message";
-        ConnectionPoolTimeoutException cptx = new ConnectionPoolTimeoutException(msg);
-        Assert.assertFalse(!cptx.toString().contains(msg));
-        Assert.assertSame(msg, cptx.getMessage());
-
-        cptx = new ConnectionPoolTimeoutException();
-        Assert.assertNull(cptx.getMessage());
-    }
-
 }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestAbstractResponseHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestAbstractResponseHandler.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestAbstractResponseHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestAbstractResponseHandler.java Thu Feb 23 14:32:24 2017
@@ -31,6 +31,7 @@ import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.hc.client5.http.impl.sync.AbstractResponseHandler;
+import org.apache.hc.client5.http.impl.sync.BasicResponseHandler;
 import org.apache.hc.client5.http.protocol.HttpResponseException;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpEntity;

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestBasicResponseHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestBasicResponseHandler.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestBasicResponseHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestBasicResponseHandler.java Thu Feb 23 14:32:24 2017
@@ -29,6 +29,7 @@ package org.apache.hc.client5.http.impl;
 
 import java.io.InputStream;
 
+import org.apache.hc.client5.http.impl.sync.BasicResponseHandler;
 import org.apache.hc.client5.http.protocol.HttpResponseException;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpEntity;

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestConnectionAutoRelease.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestConnectionAutoRelease.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestConnectionAutoRelease.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestConnectionAutoRelease.java Thu Feb 23 14:32:24 2017
@@ -31,10 +31,11 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
-import org.apache.hc.client5.http.ConnectionPoolTimeoutException;
 import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.io.ConnectionRequest;
+import org.apache.hc.client5.http.io.ConnectionEndpoint;
+import org.apache.hc.client5.http.io.LeaseRequest;
 import org.apache.hc.client5.http.localserver.LocalServerTestBase;
 import org.apache.hc.client5.http.methods.HttpGet;
 import org.apache.hc.core5.http.ClassicHttpRequest;
@@ -44,13 +45,11 @@ import org.apache.hc.core5.http.HttpExce
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.MalformedChunkCodingException;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnection;
-import org.apache.hc.core5.http.io.HttpClientConnection;
 import org.apache.hc.core5.http.io.HttpRequestHandler;
 import org.apache.hc.core5.http.io.entity.BasicHttpEntity;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
-import org.apache.hc.core5.pool.PoolStats;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -62,19 +61,18 @@ public class TestConnectionAutoRelease e
         this.connManager.setMaxTotal(1);
 
         // Zero connections in the pool
-        PoolStats stats = this.connManager.getTotalStats();
-        Assert.assertEquals(0, stats.getAvailable());
+        Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
 
         final HttpHost target = start();
         // Get some random data
         final HttpGet httpget = new HttpGet("/random/20000");
         final ClassicHttpResponse response = this.httpclient.execute(target, httpget);
 
-        ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
+        final LeaseRequest connreq1 = this.connManager.lease(new HttpRoute(target), null);
         try {
-            connreq.get(250, TimeUnit.MILLISECONDS);
+            connreq1.get(250, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
-        } catch (final ConnectionPoolTimeoutException expected) {
+        } catch (final TimeoutException expected) {
         }
 
         final HttpEntity e = response.getEntity();
@@ -82,14 +80,13 @@ public class TestConnectionAutoRelease e
         EntityUtils.consume(e);
 
         // Expect one connection in the pool
-        stats = this.connManager.getTotalStats();
-        Assert.assertEquals(1, stats.getAvailable());
+        Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
 
         // Make sure one connection is available
-        connreq = this.connManager.requestConnection(new HttpRoute(target), null);
-        final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);
+        final LeaseRequest connreq2 = this.connManager.lease(new HttpRoute(target), null);
+        final ConnectionEndpoint endpoint = connreq2.get(250, TimeUnit.MILLISECONDS);
 
-        this.connManager.releaseConnection(conn, null, -1, null);
+        this.connManager.release(endpoint, null, -1, null);
     }
 
     @Test
@@ -98,19 +95,18 @@ public class TestConnectionAutoRelease e
         this.connManager.setMaxTotal(1);
 
         // Zero connections in the pool
-        PoolStats stats = this.connManager.getTotalStats();
-        Assert.assertEquals(0, stats.getAvailable());
+        Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
 
         final HttpHost target = start();
         // Get some random data
         final HttpGet httpget = new HttpGet("/random/20000");
         final ClassicHttpResponse response = this.httpclient.execute(target, httpget);
 
-        ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
+        final LeaseRequest connreq1 = this.connManager.lease(new HttpRoute(target), null);
         try {
-            connreq.get(250, TimeUnit.MILLISECONDS);
+            connreq1.get(250, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
-        } catch (final ConnectionPoolTimeoutException expected) {
+        } catch (final TimeoutException expected) {
         }
 
         final HttpEntity e = response.getEntity();
@@ -119,14 +115,13 @@ public class TestConnectionAutoRelease e
         e.writeTo(outsteam);
 
         // Expect one connection in the pool
-        stats = this.connManager.getTotalStats();
-        Assert.assertEquals(1, stats.getAvailable());
+        Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
 
         // Make sure one connection is available
-        connreq = this.connManager.requestConnection(new HttpRoute(target), null);
-        final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);
+        final LeaseRequest connreq2 = this.connManager.lease(new HttpRoute(target), null);
+        final ConnectionEndpoint endpoint = connreq2.get(250, TimeUnit.MILLISECONDS);
 
-        this.connManager.releaseConnection(conn, null, -1, null);
+        this.connManager.release(endpoint, null, -1, null);
     }
 
     @Test
@@ -135,8 +130,7 @@ public class TestConnectionAutoRelease e
         this.connManager.setMaxTotal(1);
 
         // Zero connections in the pool
-        final PoolStats stats = this.connManager.getTotalStats();
-        Assert.assertEquals(0, stats.getAvailable());
+        Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
 
         final HttpHost target = start();
 
@@ -144,11 +138,11 @@ public class TestConnectionAutoRelease e
         final HttpGet httpget = new HttpGet("/random/20000");
         final ClassicHttpResponse response = this.httpclient.execute(target, httpget);
 
-        ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
+        final LeaseRequest connreq1 = this.connManager.lease(new HttpRoute(target), null);
         try {
-            connreq.get(250, TimeUnit.MILLISECONDS);
+            connreq1.get(250, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
-        } catch (final ConnectionPoolTimeoutException expected) {
+        } catch (final TimeoutException expected) {
         }
 
         final HttpEntity e = response.getEntity();
@@ -159,10 +153,10 @@ public class TestConnectionAutoRelease e
         Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
 
         // Make sure one connection is available
-        connreq = this.connManager.requestConnection(new HttpRoute(target), null);
-        final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);
+        final LeaseRequest connreq2 = this.connManager.lease(new HttpRoute(target), null);
+        final ConnectionEndpoint endpoint = connreq2.get(250, TimeUnit.MILLISECONDS);
 
-        this.connManager.releaseConnection(conn, null, -1, null);
+        this.connManager.release(endpoint, null, -1, null);
     }
 
     @Test
@@ -212,11 +206,11 @@ public class TestConnectionAutoRelease e
         final HttpGet httpget = new HttpGet("/dropdead");
         final ClassicHttpResponse response = this.httpclient.execute(target, httpget);
 
-        ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
+        final LeaseRequest connreq1 = this.connManager.lease(new HttpRoute(target), null);
         try {
-            connreq.get(250, TimeUnit.MILLISECONDS);
+            connreq1.get(250, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
-        } catch (final ConnectionPoolTimeoutException expected) {
+        } catch (final TimeoutException expected) {
         }
 
         final HttpEntity e = response.getEntity();
@@ -233,10 +227,10 @@ public class TestConnectionAutoRelease e
         Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
 
         // Make sure one connection is available
-        connreq = this.connManager.requestConnection(new HttpRoute(target), null);
-        final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);
+        final LeaseRequest connreq2 = this.connManager.lease(new HttpRoute(target), null);
+        final ConnectionEndpoint endpoint = connreq2.get(250, TimeUnit.MILLISECONDS);
 
-        this.connManager.releaseConnection(conn, null, -1, null);
+        this.connManager.release(endpoint, null, -1, null);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestConnectionManagement.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestConnectionManagement.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestConnectionManagement.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestConnectionManagement.java Thu Feb 23 14:32:24 2017
@@ -28,27 +28,23 @@
 package org.apache.hc.client5.http.impl.integration;
 
 import java.util.Collections;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
-import org.apache.hc.client5.http.ConnectionPoolTimeoutException;
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
-import org.apache.hc.client5.http.io.ConnectionRequest;
-import org.apache.hc.client5.http.io.HttpClientConnectionManager;
+import org.apache.hc.client5.http.io.ConnectionEndpoint;
+import org.apache.hc.client5.http.io.LeaseRequest;
 import org.apache.hc.client5.http.localserver.LocalServerTestBase;
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
-import org.apache.hc.core5.http.io.HttpClientConnection;
-import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 import org.apache.hc.core5.http.protocol.BasicHttpContext;
 import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
 import org.apache.hc.core5.http.protocol.HttpContext;
-import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.http.protocol.RequestConnControl;
 import org.apache.hc.core5.http.protocol.RequestContent;
@@ -62,22 +58,6 @@ import org.junit.Test;
  */
 public class TestConnectionManagement extends LocalServerTestBase {
 
-    private static HttpClientConnection getConnection(
-            final HttpClientConnectionManager mgr,
-            final HttpRoute route,
-            final long timeout,
-            final TimeUnit unit) throws ConnectionPoolTimeoutException, ExecutionException, InterruptedException {
-        final ConnectionRequest connRequest = mgr.requestConnection(route, null);
-        return connRequest.get(timeout, unit);
-    }
-
-    private static HttpClientConnection getConnection(
-            final HttpClientConnectionManager mgr,
-            final HttpRoute route) throws ConnectionPoolTimeoutException, ExecutionException, InterruptedException {
-        final ConnectionRequest connRequest = mgr.requestConnection(route, null);
-        return connRequest.get(0, TimeUnit.MILLISECONDS);
-    }
-
     /**
      * Tests releasing and re-using a connection after a response is read.
      */
@@ -91,79 +71,60 @@ public class TestConnectionManagement ex
         final int      rsplen = 8;
         final String      uri = "/random/" + rsplen;
 
-        final ClassicHttpRequest request = new BasicClassicHttpRequest("GET", uri);
+        final ClassicHttpRequest request = new BasicClassicHttpRequest("GET", target, uri);
         final HttpContext context = new BasicHttpContext();
 
-        HttpClientConnection conn = getConnection(this.connManager, route);
-        this.connManager.connect(conn, route, 0, context);
-        this.connManager.routeComplete(conn, route, context);
+        final LeaseRequest leaseRequest1 = this.connManager.lease(route, null);
+        final ConnectionEndpoint endpoint1 = leaseRequest1.get(0, TimeUnit.MILLISECONDS);
 
-        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
+        this.connManager.connect(endpoint1, 0, TimeUnit.MILLISECONDS, context);
 
         final HttpProcessor httpProcessor = new DefaultHttpProcessor(
                 new RequestTargetHost(), new RequestContent(), new RequestConnControl());
 
         final HttpRequestExecutor exec = new HttpRequestExecutor();
         exec.preProcess(request, httpProcessor, context);
-        ClassicHttpResponse response = exec.execute(request, conn, context);
-
-        Assert.assertEquals("wrong status in first response",
-                     HttpStatus.SC_OK,
-                     response.getCode());
-        byte[] data = EntityUtils.toByteArray(response.getEntity());
-        Assert.assertEquals("wrong length of first response entity",
-                     rsplen, data.length);
-        // ignore data, but it must be read
+        try (final ClassicHttpResponse response1 = endpoint1.execute(request, exec, context)) {
+            Assert.assertEquals(HttpStatus.SC_OK, response1.getCode());
+        }
 
         // check that there is no auto-release by default
         try {
             // this should fail quickly, connection has not been released
-            getConnection(this.connManager, route, 10L, TimeUnit.MILLISECONDS);
-            Assert.fail("ConnectionPoolTimeoutException should have been thrown");
-        } catch (final ConnectionPoolTimeoutException e) {
+            final LeaseRequest leaseRequest2 = this.connManager.lease(route, null);
+            leaseRequest2.get(10, TimeUnit.MILLISECONDS);
+            Assert.fail("TimeoutException expected");
+        } catch (final TimeoutException ex) {
             // expected
         }
 
-        conn.close();
-        this.connManager.releaseConnection(conn, null, -1, null);
-        conn = getConnection(this.connManager, route);
-        Assert.assertFalse("connection should have been closed", conn.isOpen());
-
-        this.connManager.connect(conn, route, 0, context);
-        this.connManager.routeComplete(conn, route, context);
+        endpoint1.close();
+        this.connManager.release(endpoint1, null, -1, null);
+        final LeaseRequest leaseRequest2 = this.connManager.lease(route, null);
+        final ConnectionEndpoint endpoint2 = leaseRequest2.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertFalse(endpoint2.isConnected());
 
-        // repeat the communication, no need to prepare the request again
-        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
-        response = exec.execute(request, conn, context);
+        this.connManager.connect(endpoint2, 0, TimeUnit.MILLISECONDS, context);
 
-        Assert.assertEquals("wrong status in second response",
-                     HttpStatus.SC_OK,
-                     response.getCode());
-        data = EntityUtils.toByteArray(response.getEntity());
-        Assert.assertEquals("wrong length of second response entity",
-                     rsplen, data.length);
-        // ignore data, but it must be read
+        try (final ClassicHttpResponse response2 = endpoint2.execute(request, exec, context)) {
+            Assert.assertEquals(HttpStatus.SC_OK, response2.getCode());
+        }
 
         // release connection after marking it for re-use
         // expect the next connection obtained to be open
-        this.connManager.releaseConnection(conn, null, -1, null);
-        conn = getConnection(this.connManager, route);
-        Assert.assertTrue("connection should have been open", conn.isOpen());
+        this.connManager.release(endpoint2, null, -1, null);
 
-        // repeat the communication, no need to prepare the request again
-        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
-        response = exec.execute(request, conn, context);
+        final LeaseRequest leaseRequest3 = this.connManager.lease(route, null);
+        final ConnectionEndpoint endpoint3 = leaseRequest3.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertTrue(endpoint3.isConnected());
 
-        Assert.assertEquals("wrong status in third response",
-                     HttpStatus.SC_OK,
-                     response.getCode());
-        data = EntityUtils.toByteArray(response.getEntity());
-        Assert.assertEquals("wrong length of third response entity",
-                     rsplen, data.length);
-        // ignore data, but it must be read
+        // repeat the communication, no need to prepare the request again
+        try (final ClassicHttpResponse response3 = endpoint3.execute(request, exec, context)) {
+            Assert.assertEquals(HttpStatus.SC_OK, response3.getCode());
+        }
 
-        this.connManager.releaseConnection(conn, null, -1, null);
-        this.connManager.shutdown();
+        this.connManager.release(endpoint3, null, -1, null);
+        this.connManager.close();
     }
 
     /**
@@ -179,96 +140,71 @@ public class TestConnectionManagement ex
         final int      rsplen = 8;
         final String      uri = "/random/" + rsplen;
 
-        final ClassicHttpRequest request = new BasicClassicHttpRequest("GET", uri);
+        final ClassicHttpRequest request = new BasicClassicHttpRequest("GET", target, uri);
         final HttpContext context = new BasicHttpContext();
 
-        HttpClientConnection conn = getConnection(this.connManager, route);
-        this.connManager.connect(conn, route, 0, context);
-        this.connManager.routeComplete(conn, route, context);
-
-        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
+        final LeaseRequest leaseRequest1 = this.connManager.lease(route, null);
+        final ConnectionEndpoint endpoint1 = leaseRequest1.get(0, TimeUnit.MILLISECONDS);
+        this.connManager.connect(endpoint1, 0, TimeUnit.MILLISECONDS, context);
 
         final HttpProcessor httpProcessor = new DefaultHttpProcessor(
                 new RequestTargetHost(), new RequestContent(), new RequestConnControl());
 
         final HttpRequestExecutor exec = new HttpRequestExecutor();
         exec.preProcess(request, httpProcessor, context);
-        ClassicHttpResponse response = exec.execute(request, conn, context);
-
-        Assert.assertEquals("wrong status in first response",
-                     HttpStatus.SC_OK,
-                     response.getCode());
-        byte[] data = EntityUtils.toByteArray(response.getEntity());
-        Assert.assertEquals("wrong length of first response entity",
-                     rsplen, data.length);
-        // ignore data, but it must be read
+        try (final ClassicHttpResponse response1 = endpoint1.execute(request, exec, context)) {
+            Assert.assertEquals(HttpStatus.SC_OK, response1.getCode());
+        }
 
         // check that there is no auto-release by default
         try {
             // this should fail quickly, connection has not been released
-            getConnection(this.connManager, route, 10L, TimeUnit.MILLISECONDS);
-            Assert.fail("ConnectionPoolTimeoutException should have been thrown");
-        } catch (final ConnectionPoolTimeoutException e) {
+            final LeaseRequest leaseRequest2 = this.connManager.lease(route, null);
+            leaseRequest2.get(10, TimeUnit.MILLISECONDS);
+            Assert.fail("TimeoutException expected");
+        } catch (final TimeoutException ex) {
             // expected
         }
 
-        conn.close();
-        this.connManager.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
-        conn = getConnection(this.connManager, route);
-        Assert.assertFalse("connection should have been closed", conn.isOpen());
+        endpoint1.close();
+        this.connManager.release(endpoint1, null, 100, TimeUnit.MILLISECONDS);
 
-        // repeat the communication, no need to prepare the request again
-        this.connManager.connect(conn, route, 0, context);
-        this.connManager.routeComplete(conn, route, context);
+        final LeaseRequest leaseRequest2 = this.connManager.lease(route, null);
+        final ConnectionEndpoint endpoint2 = leaseRequest2.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertFalse(endpoint2.isConnected());
 
-        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
-        response = exec.execute(request, conn, context);
+        this.connManager.connect(endpoint2, 0, TimeUnit.MILLISECONDS, context);
 
-        Assert.assertEquals("wrong status in second response",
-                     HttpStatus.SC_OK,
-                     response.getCode());
-        data = EntityUtils.toByteArray(response.getEntity());
-        Assert.assertEquals("wrong length of second response entity",
-                     rsplen, data.length);
-        // ignore data, but it must be read
-
-        this.connManager.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
-        conn = getConnection(this.connManager, route);
-        Assert.assertTrue("connection should have been open", conn.isOpen());
+        try (final ClassicHttpResponse response2 = endpoint2.execute(request, exec, context)) {
+            Assert.assertEquals(HttpStatus.SC_OK, response2.getCode());
+        }
 
-        // repeat the communication, no need to prepare the request again
-        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
-        response = exec.execute(request, conn, context);
+        this.connManager.release(endpoint2, null, 100, TimeUnit.MILLISECONDS);
 
-        Assert.assertEquals("wrong status in third response",
-                     HttpStatus.SC_OK,
-                     response.getCode());
-        data = EntityUtils.toByteArray(response.getEntity());
-        Assert.assertEquals("wrong length of third response entity",
-                     rsplen, data.length);
-        // ignore data, but it must be read
+        final LeaseRequest leaseRequest3 = this.connManager.lease(route, null);
+        final ConnectionEndpoint endpoint3 = leaseRequest3.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertTrue(endpoint3.isConnected());
+
+        // repeat the communication, no need to prepare the request again
+        try (final ClassicHttpResponse response3 = endpoint3.execute(request, exec, context)) {
+            Assert.assertEquals(HttpStatus.SC_OK, response3.getCode());
+        }
 
-        this.connManager.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
+        this.connManager.release(endpoint3, null, 100, TimeUnit.MILLISECONDS);
         Thread.sleep(150);
-        conn = getConnection(this.connManager, route);
-        Assert.assertTrue("connection should have been closed", !conn.isOpen());
 
-        // repeat the communication, no need to prepare the request again
-        this.connManager.connect(conn, route, 0, context);
-        this.connManager.routeComplete(conn, route, context);
+        final LeaseRequest leaseRequest4 = this.connManager.lease(route, null);
+        final ConnectionEndpoint endpoint4 = leaseRequest4.get(0, TimeUnit.MILLISECONDS);
+        Assert.assertFalse(endpoint4.isConnected());
 
-        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
-        response = exec.execute(request, conn, context);
+        // repeat the communication, no need to prepare the request again
+        this.connManager.connect(endpoint4, 0, TimeUnit.MILLISECONDS, context);
 
-        Assert.assertEquals("wrong status in third response",
-                     HttpStatus.SC_OK,
-                     response.getCode());
-        data = EntityUtils.toByteArray(response.getEntity());
-        Assert.assertEquals("wrong length of fourth response entity",
-                     rsplen, data.length);
-        // ignore data, but it must be read
+        try (final ClassicHttpResponse response4 = endpoint4.execute(request, exec, context)) {
+            Assert.assertEquals(HttpStatus.SC_OK, response4.getCode());
+        }
 
-        this.connManager.shutdown();
+        this.connManager.close();
     }
 
     @Test
@@ -280,15 +216,15 @@ public class TestConnectionManagement ex
         final HttpRoute route = new HttpRoute(target, null, false);
         final HttpContext context = new BasicHttpContext();
 
-        final HttpClientConnection conn = getConnection(this.connManager, route);
-        this.connManager.connect(conn, route, 0, context);
-        this.connManager.routeComplete(conn, route, context);
+        final LeaseRequest leaseRequest1 = this.connManager.lease(route, null);
+        final ConnectionEndpoint endpoint1 = leaseRequest1.get(0, TimeUnit.MILLISECONDS);
+        this.connManager.connect(endpoint1, 0, TimeUnit.MILLISECONDS, context);
 
         Assert.assertEquals(Collections.singleton(route), this.connManager.getRoutes());
         Assert.assertEquals(1, this.connManager.getTotalStats().getLeased());
         Assert.assertEquals(1, this.connManager.getStats(route).getLeased());
 
-        this.connManager.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
+        this.connManager.release(endpoint1, null, 100, TimeUnit.MILLISECONDS);
 
         // Released, still active.
         Assert.assertEquals(Collections.singleton(route), this.connManager.getRoutes());
@@ -311,7 +247,7 @@ public class TestConnectionManagement ex
         Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
         Assert.assertEquals(0, this.connManager.getStats(route).getAvailable());
 
-        this.connManager.shutdown();
+        this.connManager.close();
     }
 
     @Test
@@ -327,15 +263,15 @@ public class TestConnectionManagement ex
         final HttpRoute route = new HttpRoute(target, null, false);
         final HttpContext context = new BasicHttpContext();
 
-        final HttpClientConnection conn = getConnection(this.connManager, route);
-        this.connManager.connect(conn, route, 0, context);
-        this.connManager.routeComplete(conn, route, context);
+        final LeaseRequest leaseRequest1 = this.connManager.lease(route, null);
+        final ConnectionEndpoint endpoint1 = leaseRequest1.get(0, TimeUnit.MILLISECONDS);
+        this.connManager.connect(endpoint1, 0, TimeUnit.MILLISECONDS, context);
 
         Assert.assertEquals(Collections.singleton(route), this.connManager.getRoutes());
         Assert.assertEquals(1, this.connManager.getTotalStats().getLeased());
         Assert.assertEquals(1, this.connManager.getStats(route).getLeased());
         // Release, let remain idle for forever
-        this.connManager.releaseConnection(conn, null, -1, TimeUnit.MILLISECONDS);
+        this.connManager.release(endpoint1, null, 0, TimeUnit.MILLISECONDS);
 
         // Released, still active.
         Assert.assertEquals(Collections.singleton(route), this.connManager.getRoutes());
@@ -358,64 +294,7 @@ public class TestConnectionManagement ex
         Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
         Assert.assertEquals(0, this.connManager.getStats(route).getAvailable());
 
-        this.connManager.shutdown();
-    }
-
-    /**
-     * Tests releasing connection from #abort method called from the
-     * main execution thread while there is no blocking I/O operation.
-     */
-    @Test
-    public void testReleaseConnectionOnAbort() throws Exception {
-
-        this.connManager.setMaxTotal(1);
-
-        final HttpHost target = start();
-        final HttpRoute route = new HttpRoute(target, null, false);
-        final int      rsplen = 8;
-        final String      uri = "/random/" + rsplen;
-        final HttpContext context = new BasicHttpContext();
-
-        final ClassicHttpRequest request =
-            new BasicClassicHttpRequest("GET", uri);
-
-        HttpClientConnection conn = getConnection(this.connManager, route);
-        this.connManager.connect(conn, route, 0, context);
-        this.connManager.routeComplete(conn, route, context);
-
-        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
-
-        final HttpProcessor httpProcessor = new DefaultHttpProcessor(
-                new RequestTargetHost(), new RequestContent(), new RequestConnControl());
-
-        final HttpRequestExecutor exec = new HttpRequestExecutor();
-        exec.preProcess(request, httpProcessor, context);
-        final ClassicHttpResponse response = exec.execute(request, conn, context);
-
-        Assert.assertEquals("wrong status in first response",
-                     HttpStatus.SC_OK,
-                     response.getCode());
-
-        // check that there are no connections available
-        try {
-            // this should fail quickly, connection has not been released
-            getConnection(this.connManager, route, 100L, TimeUnit.MILLISECONDS);
-            Assert.fail("ConnectionPoolTimeoutException should have been thrown");
-        } catch (final ConnectionPoolTimeoutException e) {
-            // expected
-        }
-
-        // abort the connection
-        Assert.assertTrue(conn instanceof HttpClientConnection);
-        conn.shutdown();
-        this.connManager.releaseConnection(conn, null, -1, null);
-
-        // the connection is expected to be released back to the manager
-        conn = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
-        Assert.assertFalse("connection should have been closed", conn.isOpen());
-
-        this.connManager.releaseConnection(conn, null, -1, null);
-        this.connManager.shutdown();
+        this.connManager.close();
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestContentCodings.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestContentCodings.java?rev=1784138&r1=1784137&r2=1784138&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestContentCodings.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestContentCodings.java Thu Feb 23 14:32:24 2017
@@ -41,7 +41,7 @@ import java.util.concurrent.Executors;
 import java.util.zip.Deflater;
 import java.util.zip.GZIPOutputStream;
 
-import org.apache.hc.client5.http.impl.BasicResponseHandler;
+import org.apache.hc.client5.http.impl.sync.BasicResponseHandler;
 import org.apache.hc.client5.http.impl.sync.CloseableHttpClient;
 import org.apache.hc.client5.http.localserver.LocalServerTestBase;
 import org.apache.hc.client5.http.methods.HttpGet;



Mime
View raw message