hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1793305 [3/5] - in /httpcomponents/httpclient/trunk: ./ httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/ httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/ httpclient5-fluent/src/main/java/org...
Date Mon, 01 May 2017 10:47:11 GMT
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/AsyncClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/AsyncClientConnectionOperator.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/AsyncClientConnectionOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/AsyncClientConnectionOperator.java Mon May  1 10:47:09 2017
@@ -33,7 +33,6 @@ import java.net.SocketAddress;
 import java.net.SocketException;
 import java.net.UnknownHostException;
 import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.hc.client5.http.ConnectTimeoutException;
@@ -42,17 +41,18 @@ import org.apache.hc.client5.http.HttpHo
 import org.apache.hc.client5.http.SchemePortResolver;
 import org.apache.hc.client5.http.SystemDefaultDnsResolver;
 import org.apache.hc.client5.http.UnsupportedSchemeException;
-import org.apache.hc.client5.http.impl.ComplexFuture;
 import org.apache.hc.client5.http.impl.DefaultSchemePortResolver;
+import org.apache.hc.core5.concurrent.ComplexFuture;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.config.Lookup;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
 import org.apache.hc.core5.reactor.ConnectionInitiator;
-import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.SessionRequest;
 import org.apache.hc.core5.reactor.SessionRequestCallback;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
 import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.TimeValue;
 
 final class AsyncClientConnectionOperator {
 
@@ -73,8 +73,7 @@ final class AsyncClientConnectionOperato
             final ConnectionInitiator connectionInitiator,
             final HttpHost host,
             final SocketAddress localAddress,
-            final long timeout,
-            final TimeUnit timeUnit,
+            final TimeValue connectTimeout,
             final FutureCallback<ManagedAsyncClientConnection> callback) {
         Args.notNull(connectionInitiator, "Connection initiator");
         Args.notNull(host, "Host");
@@ -103,21 +102,21 @@ final class AsyncClientConnectionOperato
                 final InetSocketAddress remoteAddress = new InetSocketAddress(remoteAddresses[index], port);
                 final SessionRequest sessionRequest = connectionInitiator.connect(
                         host,
-                        // TODO: fix after upgrading to HttpCore 5.0a3
-                        // TODO: remoteAddress
+                        remoteAddress,
                         localAddress,
                         null, new SessionRequestCallback() {
 
                             @Override
                             public void completed(final SessionRequest request) {
-                                final IOSession session = request.getSession();
+                                final TlsCapableIOSession session = request.getSession();
                                 final ManagedAsyncClientConnection connection = new ManagedAsyncClientConnection(session);
                                 if (tlsStrategy != null) {
                                     tlsStrategy.upgrade(
                                             connection,
-                                            host.getHostName(),
+                                            host,
                                             session.getLocalAddress(),
-                                            session.getRemoteAddress());
+                                            session.getRemoteAddress(),
+                                            null);
                                 }
                                 future.completed(connection);
                             }
@@ -143,8 +142,7 @@ final class AsyncClientConnectionOperato
 
                         });
                 future.setDependency(sessionRequest);
-                final int connectTimeout = (int) (timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS).toMillis(timeout);
-                sessionRequest.setConnectTimeout(connectTimeout);
+                sessionRequest.setConnectTimeout(connectTimeout.toMillisIntBound());
             }
 
             @Override
@@ -162,10 +160,10 @@ final class AsyncClientConnectionOperato
         if (tlsStrategy != null) {
             tlsStrategy.upgrade(
                     connection,
-                    // TODO: fix after upgrading to HttpCore 5.0a3
-                    host.getHostName(),
+                    host,
                     connection.getLocalAddress(),
-                    connection.getRemoteAddress());
+                    connection.getRemoteAddress(),
+                    null);
         }
 
     }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/ManagedAsyncClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/ManagedAsyncClientConnection.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/ManagedAsyncClientConnection.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/ManagedAsyncClientConnection.java Mon May  1 10:47:09 2017
@@ -35,19 +35,20 @@ import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLSession;
 
 import org.apache.hc.client5.http.impl.ConnPoolSupport;
-import org.apache.hc.client5.http.ssl.H2TlsSupport;
-import org.apache.hc.client5.http.utils.Identifiable;
+import org.apache.hc.core5.http.EndpointDetails;
 import org.apache.hc.core5.http.HttpConnection;
-import org.apache.hc.core5.http.HttpConnectionMetrics;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.reactor.Command;
 import org.apache.hc.core5.reactor.IOEventHandler;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
 import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
 import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.util.Identifiable;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -55,10 +56,10 @@ final class ManagedAsyncClientConnection
 
     private final Logger log = LogManager.getLogger(getClass());
 
-    private final IOSession ioSession;
+    private final TlsCapableIOSession ioSession;
     private final AtomicBoolean closed;
 
-    public ManagedAsyncClientConnection(final IOSession ioSession) {
+    public ManagedAsyncClientConnection(final TlsCapableIOSession ioSession) {
         this.ioSession = ioSession;
         this.closed = new AtomicBoolean();
     }
@@ -69,12 +70,12 @@ final class ManagedAsyncClientConnection
     }
 
     @Override
-    public void shutdown() throws IOException {
+    public void shutdown(final ShutdownType shutdownType) {
         if (this.closed.compareAndSet(false, true)) {
             if (log.isDebugEnabled()) {
-                log.debug(getId() + ": Shutdown connection");
+                log.debug(getId() + ": Shutdown connection " + shutdownType);
             }
-            ioSession.shutdown();
+            ioSession.shutdown(shutdownType);
         }
     }
 
@@ -114,10 +115,10 @@ final class ManagedAsyncClientConnection
     }
 
     @Override
-    public HttpConnectionMetrics getMetrics() {
+    public EndpointDetails getEndpointDetails() {
         final IOEventHandler handler = ioSession.getHandler();
         if (handler instanceof HttpConnection) {
-            return ((HttpConnection) handler).getMetrics();
+            return ((HttpConnection) handler).getEndpointDetails();
         } else {
             return null;
         }
@@ -134,7 +135,7 @@ final class ManagedAsyncClientConnection
     }
 
     @Override
-    public void start(
+    public void startTls(
             final SSLContext sslContext,
             final SSLBufferManagement sslBufferManagement,
             final SSLSessionInitializer initializer,
@@ -142,31 +143,18 @@ final class ManagedAsyncClientConnection
         if (log.isDebugEnabled()) {
             log.debug(getId() + ": start TLS");
         }
-        if (ioSession instanceof TransportSecurityLayer) {
-            final IOEventHandler handler = ioSession.getHandler();
-            final ProtocolVersion protocolVersion;
-            if (handler instanceof HttpConnection) {
-                protocolVersion = ((HttpConnection) handler).getProtocolVersion();
-            } else {
-                protocolVersion = null;
-            }
-            ((TransportSecurityLayer) ioSession).start(
-                    sslContext,
-                    sslBufferManagement,
-                    HttpVersion.HTTP_2.greaterEquals(protocolVersion) ? H2TlsSupport.decorateInitializer(initializer) : initializer,
-                    verifier);
-        } else {
-            throw new UnsupportedOperationException();
-        }
+        ioSession.startTls(sslContext, sslBufferManagement, initializer, verifier);
+    }
+
+    @Override
+    public TlsDetails getTlsDetails() {
+        return ioSession.getTlsDetails();
     }
 
     @Override
     public SSLSession getSSLSession() {
-        if (ioSession instanceof TransportSecurityLayer) {
-            return ((TransportSecurityLayer) ioSession).getSSLSession();
-        } else {
-            return null;
-        }
+        final TlsDetails tlsDetails = ioSession.getTlsDetails();
+        return tlsDetails != null ? tlsDetails.getSSLSession() : null;
     }
 
     public void submitPriorityCommand(final Command command) {

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java Mon May  1 10:47:09 2017
@@ -30,21 +30,19 @@ package org.apache.hc.client5.http.impl.
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
 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.HttpRoute;
 import org.apache.hc.client5.http.SchemePortResolver;
-import org.apache.hc.client5.http.impl.ComplexFuture;
 import org.apache.hc.client5.http.impl.ConnPoolSupport;
 import org.apache.hc.client5.http.impl.ConnectionShutdownException;
 import org.apache.hc.client5.http.nio.AsyncClientConnectionManager;
 import org.apache.hc.client5.http.nio.AsyncConnectionEndpoint;
-import org.apache.hc.client5.http.utils.Identifiable;
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.concurrent.ComplexFuture;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.HttpHost;
@@ -57,6 +55,7 @@ import org.apache.hc.core5.http.nio.ssl.
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.http2.nio.command.PingCommand;
 import org.apache.hc.core5.http2.nio.support.BasicPingHandler;
+import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.pool.ConnPoolControl;
 import org.apache.hc.core5.pool.ConnPoolListener;
 import org.apache.hc.core5.pool.ConnPoolPolicy;
@@ -66,6 +65,8 @@ import org.apache.hc.core5.pool.StrictCo
 import org.apache.hc.core5.reactor.ConnectionInitiator;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
+import org.apache.hc.core5.util.Identifiable;
+import org.apache.hc.core5.util.TimeValue;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -96,19 +97,17 @@ public class PoolingAsyncClientConnectio
     private final StrictConnPool<HttpRoute, ManagedAsyncClientConnection> pool;
     private final AtomicBoolean closed;
 
-    private volatile int validateAfterInactivity;
+    private volatile TimeValue validateAfterInactivity;
 
     public PoolingAsyncClientConnectionManager(
             final Lookup<TlsStrategy> tlsStrategyLookup,
             final SchemePortResolver schemePortResolver,
             final DnsResolver dnsResolver,
-            final long timeToLive,
-            final TimeUnit timeUnit,
+            final TimeValue timeToLive,
             final ConnPoolPolicy policy,
             final ConnPoolListener<HttpRoute> connPoolListener) {
         this.connectionOperator = new AsyncClientConnectionOperator(schemePortResolver, dnsResolver, tlsStrategyLookup);
-        this.pool = new StrictConnPool<>(20, 50, timeToLive, timeUnit,
-                policy != null ? policy : ConnPoolPolicy.LIFO, connPoolListener);
+        this.pool = new StrictConnPool<>(20, 50, timeToLive, policy != null ? policy : ConnPoolPolicy.LIFO, connPoolListener);
         this.closed = new AtomicBoolean(false);
     }
 
@@ -125,7 +124,7 @@ public class PoolingAsyncClientConnectio
     public void close() {
         if (closed.compareAndSet(false, true)) {
             log.debug("Connection manager is shutting down");
-            pool.shutdown();
+            pool.shutdown(ShutdownType.GRACEFUL);
             log.debug("Connection manager shut down");
         }
     }
@@ -142,15 +141,14 @@ public class PoolingAsyncClientConnectio
     public Future<AsyncConnectionEndpoint> lease(
             final HttpRoute route,
             final Object state,
-            final long timeout,
-            final TimeUnit timeUnit,
+            final TimeValue timeout,
             final FutureCallback<AsyncConnectionEndpoint> callback) {
         if (log.isDebugEnabled()) {
             log.debug("Connection request: " + ConnPoolSupport.formatStats(null, route, state, pool));
         }
         final ComplexFuture<AsyncConnectionEndpoint> resultFuture = new ComplexFuture<>(callback);
         final Future<PoolEntry<HttpRoute, ManagedAsyncClientConnection>> leaseFuture = pool.lease(
-                route, state, timeout, timeUnit, new FutureCallback<PoolEntry<HttpRoute, ManagedAsyncClientConnection>>() {
+                route, state, timeout, new FutureCallback<PoolEntry<HttpRoute, ManagedAsyncClientConnection>>() {
 
                     void leaseCompleted(final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry) {
                         resultFuture.completed(new InternalConnectionEndpoint(poolEntry));
@@ -161,9 +159,8 @@ public class PoolingAsyncClientConnectio
 
                     @Override
                     public void completed(final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry) {
-                        final ManagedAsyncClientConnection connection = poolEntry.getConnection();
-                        if (connection != null && validateAfterInactivity > 0 &&
-                                poolEntry.getUpdated() + validateAfterInactivity <= System.currentTimeMillis()) {
+                        if (TimeValue.isPositive(validateAfterInactivity)) {
+                            final ManagedAsyncClientConnection connection = poolEntry.getConnection();
                             final ProtocolVersion protocolVersion = connection.getProtocolVersion();
                             if (HttpVersion.HTTP_2_0.greaterEquals(protocolVersion)) {
                                 connection.submitPriorityCommand(new PingCommand(new BasicPingHandler(new Callback<Boolean>() {
@@ -174,7 +171,7 @@ public class PoolingAsyncClientConnectio
                                             if (log.isDebugEnabled()) {
                                                 log.debug("Connection " + ConnPoolSupport.getId(connection) + " is stale");
                                             }
-                                            poolEntry.discardConnection();
+                                            poolEntry.discardConnection(ShutdownType.IMMEDIATE);
                                         }
                                         leaseCompleted(poolEntry);
                                     }
@@ -199,16 +196,15 @@ public class PoolingAsyncClientConnectio
                     }
 
                 });
+
         resultFuture.setDependency(leaseFuture);
         return resultFuture;
     }
 
     @Override
-    public void release(
-            final AsyncConnectionEndpoint endpoint,
-            final Object state,
-            final long keepAlive, final TimeUnit timeUnit) {
+    public void release(final AsyncConnectionEndpoint endpoint, final Object state, final TimeValue keepAlive) {
         Args.notNull(endpoint, "Managed endpoint");
+        Args.notNull(keepAlive, "Keep-alive time");
         final PoolEntry<HttpRoute, ManagedAsyncClientConnection> entry = cast(endpoint).detach();
         if (entry == null) {
             return;
@@ -217,12 +213,12 @@ public class PoolingAsyncClientConnectio
         boolean reusable = connection != null && connection.isOpen();
         try {
             if (reusable) {
-                final TimeUnit effectiveUnit = timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS;
-                entry.updateConnection(keepAlive, effectiveUnit, state);
+                entry.updateState(state);
+                entry.updateExpiry(keepAlive);
                 if (log.isDebugEnabled()) {
                     final String s;
-                    if (keepAlive > 0) {
-                        s = "for " + (double) effectiveUnit.toMillis(keepAlive) / 1000 + " seconds";
+                    if (TimeValue.isPositive(keepAlive)) {
+                        s = "for " + keepAlive;
                     } else {
                         s = "indefinitely";
                     }
@@ -245,12 +241,12 @@ public class PoolingAsyncClientConnectio
     public Future<AsyncConnectionEndpoint> connect(
             final AsyncConnectionEndpoint endpoint,
             final ConnectionInitiator connectionInitiator,
-            final long timeout,
-            final TimeUnit timeUnit,
+            final TimeValue timeout,
             final HttpContext context,
             final FutureCallback<AsyncConnectionEndpoint> callback) {
         Args.notNull(endpoint, "Endpoint");
         Args.notNull(connectionInitiator, "Connection initiator");
+        Args.notNull(timeout, "Timeout");
         final InternalConnectionEndpoint internalEndpoint = cast(endpoint);
         final ComplexFuture<AsyncConnectionEndpoint> resultFuture = new ComplexFuture<>(callback);
         if (internalEndpoint.isConnected()) {
@@ -267,7 +263,7 @@ public class PoolingAsyncClientConnectio
         }
         final InetSocketAddress localAddress = route.getLocalSocketAddress();
         final Future<ManagedAsyncClientConnection> connectFuture = connectionOperator.connect(
-                connectionInitiator, host, localAddress, timeout, timeUnit, new FutureCallback<ManagedAsyncClientConnection>() {
+                connectionInitiator, host, localAddress, timeout, new FutureCallback<ManagedAsyncClientConnection>() {
 
                     @Override
                     public void completed(final ManagedAsyncClientConnection connection) {
@@ -332,8 +328,8 @@ public class PoolingAsyncClientConnectio
     }
 
     @Override
-    public void closeIdle(final long idletime, final TimeUnit tunit) {
-        pool.closeIdle(idletime, tunit);
+    public void closeIdle(final TimeValue idletime) {
+        pool.closeIdle(idletime);
     }
 
     @Override
@@ -351,19 +347,19 @@ public class PoolingAsyncClientConnectio
         return pool.getStats(route);
     }
 
-    public int getValidateAfterInactivity() {
+    public TimeValue getValidateAfterInactivity() {
         return validateAfterInactivity;
     }
 
     /**
      * Defines period of inactivity in milliseconds after which persistent connections must
-     * be re-validated prior to being {@link #lease(HttpRoute, Object, long, TimeUnit,
+     * be re-validated prior to being {@link #lease(HttpRoute, Object, TimeValue,
      * FutureCallback)} leased} to the consumer. Non-positive value passed
      * to this method disables connection validation. This check helps detect connections
      * that have become stale (half-closed) while kept inactive in the pool.
      */
-    public void setValidateAfterInactivity(final int ms) {
-        validateAfterInactivity = ms;
+    public void setValidateAfterInactivity(final TimeValue validateAfterInactivity) {
+        this.validateAfterInactivity = validateAfterInactivity;
     }
 
     class InternalConnectionEndpoint extends AsyncConnectionEndpoint implements Identifiable {
@@ -404,11 +400,7 @@ public class PoolingAsyncClientConnectio
         public void shutdown() throws IOException {
             final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry = poolEntryRef.get();
             if (poolEntry != null) {
-                final ManagedAsyncClientConnection connection = poolEntry.getConnection();
-                poolEntry.discardConnection();
-                if (connection != null) {
-                    connection.shutdown();
-                }
+                poolEntry.discardConnection(ShutdownType.IMMEDIATE);
             }
         }
 
@@ -416,7 +408,7 @@ public class PoolingAsyncClientConnectio
         public void close() throws IOException {
             final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry = poolEntryRef.get();
             if (poolEntry != null) {
-                poolEntry.discardConnection();
+                poolEntry.discardConnection(ShutdownType.GRACEFUL);
             }
         }
 
@@ -437,7 +429,8 @@ public class PoolingAsyncClientConnectio
 
         @Override
         public void execute(final AsyncClientExchangeHandler exchangeHandler, final HttpContext context) {
-            getValidatedPoolEntry().getConnection().submitCommand(new ExecutionCommand(exchangeHandler, context));
+            final ManagedAsyncClientConnection connection = getValidatedPoolEntry().getConnection();
+            connection.submitCommand(new ExecutionCommand(exchangeHandler, context));
         }
 
     }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java Mon May  1 10:47:09 2017
@@ -27,16 +27,15 @@
 
 package org.apache.hc.client5.http.impl.nio;
 
-import java.util.concurrent.TimeUnit;
-
 import org.apache.hc.client5.http.DnsResolver;
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.SchemePortResolver;
-import org.apache.hc.client5.http.ssl.SSLUpgradeStrategy;
+import org.apache.hc.client5.http.ssl.H2TlsStrategy;
 import org.apache.hc.core5.http.config.RegistryBuilder;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
 import org.apache.hc.core5.pool.ConnPoolListener;
 import org.apache.hc.core5.pool.ConnPoolPolicy;
+import org.apache.hc.core5.util.TimeValue;
 
 /**
  * Builder for {@link PoolingAsyncClientConnectionManager} instances.
@@ -77,9 +76,8 @@ public class PoolingAsyncClientConnectio
     private int maxConnTotal = 0;
     private int maxConnPerRoute = 0;
 
-    private long connTimeToLive = -1;
-    private TimeUnit connTimeToLiveTimeUnit = TimeUnit.MILLISECONDS;
-    private int validateAfterInactivity = 2000;
+    private TimeValue timeToLive;
+    private TimeValue validateAfterInactivity;
 
     public static PoolingAsyncClientConnectionManagerBuilder create() {
         return new PoolingAsyncClientConnectionManagerBuilder();
@@ -149,9 +147,8 @@ public class PoolingAsyncClientConnectio
     /**
      * Sets maximum time to live for persistent connections
      */
-    public final PoolingAsyncClientConnectionManagerBuilder setConnectionTimeToLive(final long connTimeToLive, final TimeUnit connTimeToLiveTimeUnit) {
-        this.connTimeToLive = connTimeToLive;
-        this.connTimeToLiveTimeUnit = connTimeToLiveTimeUnit;
+    public final PoolingAsyncClientConnectionManagerBuilder setConnectionTimeToLive(final TimeValue timeToLive) {
+        this.timeToLive = timeToLive;
         return this;
     }
 
@@ -161,7 +158,7 @@ public class PoolingAsyncClientConnectio
      *
      * @see org.apache.hc.core5.http.io.HttpClientConnection#isStale()
      */
-    public final PoolingAsyncClientConnectionManagerBuilder setValidateAfterInactivity(final int validateAfterInactivity) {
+    public final PoolingAsyncClientConnectionManagerBuilder setValidateAfterInactivity(final TimeValue validateAfterInactivity) {
         this.validateAfterInactivity = validateAfterInactivity;
         return this;
     }
@@ -181,13 +178,12 @@ public class PoolingAsyncClientConnectio
                 RegistryBuilder.<TlsStrategy>create()
                         .register("https", tlsStrategy != null ? tlsStrategy :
                                 (systemProperties ?
-                                        SSLUpgradeStrategy.getSystemDefault() :
-                                        SSLUpgradeStrategy.getDefault()))
+                                        H2TlsStrategy.getSystemDefault() :
+                                        H2TlsStrategy.getDefault()))
                         .build(),
                 schemePortResolver,
                 dnsResolver,
-                connTimeToLive,
-                connTimeToLiveTimeUnit != null ? connTimeToLiveTimeUnit : TimeUnit.MILLISECONDS,
+                timeToLive,
                 connPoolPolicy,
                 connPoolListener);
         poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity);

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/EndpointHolder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/EndpointHolder.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/EndpointHolder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/EndpointHolder.java Mon May  1 10:47:09 2017
@@ -29,7 +29,6 @@ package org.apache.hc.client5.http.impl.
 
 import java.io.Closeable;
 import java.io.IOException;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.hc.client5.http.io.ConnectionEndpoint;
@@ -37,6 +36,8 @@ import org.apache.hc.client5.http.io.Htt
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.concurrent.Cancellable;
+import org.apache.hc.core5.io.ShutdownType;
+import org.apache.hc.core5.util.TimeValue;
 import org.apache.logging.log4j.Logger;
 
 /**
@@ -54,7 +55,7 @@ class EndpointHolder implements Cancella
     private final AtomicBoolean released;
     private volatile boolean reusable;
     private volatile Object state;
-    private volatile long validDuration;
+    private volatile TimeValue validDuration;
 
     public EndpointHolder(
             final Logger log,
@@ -83,15 +84,15 @@ class EndpointHolder implements Cancella
         this.state = state;
     }
 
-    public void setValidFor(final long duration, final TimeUnit tunit) {
-        this.validDuration = (tunit != null ? tunit : TimeUnit.MILLISECONDS).toMillis(duration);
+    public void setValidFor(final TimeValue validDuration) {
+        this.validDuration = validDuration;
     }
 
     private void releaseConnection(final boolean reusable) {
         if (this.released.compareAndSet(false, true)) {
             synchronized (this.endpoint) {
                 if (reusable) {
-                    this.manager.release(this.endpoint, this.state, this.validDuration, TimeUnit.MILLISECONDS);
+                    this.manager.release(this.endpoint, this.state, this.validDuration);
                 } else {
                     try {
                         this.endpoint.close();
@@ -101,7 +102,7 @@ class EndpointHolder implements Cancella
                             this.log.debug(ex.getMessage(), ex);
                         }
                     } finally {
-                        this.manager.release(this.endpoint, null, 0, TimeUnit.MILLISECONDS);
+                        this.manager.release(this.endpoint, null, TimeValue.ZERO_MILLISECONDS);
                     }
                 }
             }
@@ -116,14 +117,10 @@ class EndpointHolder implements Cancella
         if (this.released.compareAndSet(false, true)) {
             synchronized (this.endpoint) {
                 try {
-                    this.endpoint.shutdown();
+                    this.endpoint.shutdown(ShutdownType.IMMEDIATE);
                     log.debug("Connection discarded");
-                } catch (final IOException ex) {
-                    if (this.log.isDebugEnabled()) {
-                        this.log.debug(ex.getMessage(), ex);
-                    }
                 } finally {
-                    this.manager.release(this.endpoint, null, 0, TimeUnit.MILLISECONDS);
+                    this.manager.release(this.endpoint, null, TimeValue.ZERO_MILLISECONDS);
                 }
             }
         }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java Mon May  1 10:47:09 2017
@@ -103,6 +103,7 @@ import org.apache.hc.core5.http.protocol
 import org.apache.hc.core5.http.protocol.RequestTargetHost;
 import org.apache.hc.core5.http.protocol.RequestUserAgent;
 import org.apache.hc.core5.pool.ConnPoolControl;
+import org.apache.hc.core5.util.TimeValue;
 import org.apache.hc.core5.util.VersionInfo;
 
 /**
@@ -163,8 +164,7 @@ public class HttpClientBuilder {
     private RequestConfig defaultRequestConfig;
     private boolean evictExpiredConnections;
     private boolean evictIdleConnections;
-    private long maxIdleTime;
-    private TimeUnit maxIdleTimeUnit;
+    private TimeValue maxIdleTime;
 
     private boolean systemProperties;
     private boolean redirectHandlingDisabled;
@@ -574,19 +574,17 @@ public class HttpClientBuilder {
      * use a shared connection manager.
      *
      * @see #setConnectionManagerShared(boolean)
-     * @see ConnPoolControl#closeIdle(long, TimeUnit)
+     * @see ConnPoolControl#closeIdle(TimeValue)
      *
      * @param maxIdleTime maximum time persistent connections can stay idle while kept alive
      * in the connection pool. Connections whose inactivity period exceeds this value will
      * get closed and evicted from the pool.
-     * @param maxIdleTimeUnit time unit for the above parameter.
      *
      * @since 4.4
      */
-    public final HttpClientBuilder evictIdleConnections(final long maxIdleTime, final TimeUnit maxIdleTimeUnit) {
+    public final HttpClientBuilder evictIdleConnections(final TimeValue maxIdleTime) {
         this.evictIdleConnections = true;
         this.maxIdleTime = maxIdleTime;
-        this.maxIdleTimeUnit = maxIdleTimeUnit;
         return this;
     }
 
@@ -867,8 +865,7 @@ public class HttpClientBuilder {
             if (evictExpiredConnections || evictIdleConnections) {
                 if (connManagerCopy instanceof ConnPoolControl) {
                     final IdleConnectionEvictor connectionEvictor = new IdleConnectionEvictor((ConnPoolControl<?>) connManagerCopy,
-                            maxIdleTime > 0 ? maxIdleTime : 10, maxIdleTimeUnit != null ? maxIdleTimeUnit : TimeUnit.SECONDS,
-                            maxIdleTime, maxIdleTimeUnit);
+                            maxIdleTime, maxIdleTime);
                     closeablesCopy.add(new Closeable() {
 
                         @Override

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/InternalHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/InternalHttpClient.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/InternalHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/InternalHttpClient.java Mon May  1 10:47:09 2017
@@ -156,7 +156,7 @@ class InternalHttpClient extends Closeab
                     RoutedHttpRequest.adapt(request, route), localcontext, execAware);
             return CloseableHttpResponse.adapt(response);
         } catch (final HttpException httpException) {
-            throw new ClientProtocolException(httpException);
+            throw new ClientProtocolException(httpException.getMessage(), httpException);
         }
     }
 

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=1793305&r1=1793304&r2=1793305&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 Mon May  1 10:47:09 2017
@@ -30,7 +30,6 @@ package org.apache.hc.client5.http.impl.
 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;
@@ -72,10 +71,10 @@ import org.apache.hc.core5.http.message.
 import org.apache.hc.core5.http.message.RequestLine;
 import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
-import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.http.protocol.RequestTargetHost;
 import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.TimeValue;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -177,8 +176,8 @@ public class MainClientExec implements C
 
         final ConnectionEndpoint endpoint;
         try {
-            final int timeout = config.getConnectionRequestTimeout();
-            endpoint = leaseRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS);
+            final TimeValue timeout = config.getConnectionRequestTimeout();
+            endpoint = leaseRequest.get(timeout.getDuration(), timeout.getTimeUnit());
         } catch(final TimeoutException ex) {
             throw new ConnectionRequestTimeoutException(ex.getMessage());
         } catch(final InterruptedException interrupted) {
@@ -192,8 +191,6 @@ public class MainClientExec implements C
             throw new RequestAbortedException("Request execution failed", cause);
         }
 
-        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, endpoint);
-
         final EndpointHolder endpointHolder = new EndpointHolder(this.log, this.connManager, endpoint);
         try {
             if (execAware != null) {
@@ -230,9 +227,9 @@ public class MainClientExec implements C
                         break;
                     }
                 }
-                final int timeout = config.getSocketTimeout();
-                if (timeout >= 0) {
-                    endpoint.setSocketTimeout(timeout);
+                final TimeValue timeout = config.getSocketTimeout();
+                if (TimeValue.isPositive(timeout)) {
+                    endpoint.setSocketTimeout(timeout.toMillisIntBound());
                 }
 
                 if (execAware != null && execAware.isAborted()) {
@@ -263,17 +260,17 @@ public class MainClientExec implements C
                 // 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);
+                    final TimeValue duration = keepAliveStrategy.getKeepAliveDuration(response, context);
                     if (this.log.isDebugEnabled()) {
                         final String s;
-                        if (duration > 0) {
-                            s = "for " + duration + " " + TimeUnit.MILLISECONDS;
+                        if (duration != null) {
+                            s = "for " + duration;
                         } else {
                             s = "indefinitely";
                         }
                         this.log.debug("Connection can be kept alive " + s);
                     }
-                    endpointHolder.setValidFor(duration, TimeUnit.MILLISECONDS);
+                    endpointHolder.setValidFor(duration);
                     endpointHolder.markReusable();
                 } else {
                     endpointHolder.markNonReusable();
@@ -356,7 +353,7 @@ public class MainClientExec implements C
             final HttpRequest request,
             final HttpClientContext context) throws HttpException, IOException {
         final RequestConfig config = context.getRequestConfig();
-        final int timeout = config.getConnectTimeout();
+        final TimeValue timeout = config.getConnectTimeout();
         final RouteTracker tracker = new RouteTracker(route);
         int step;
         do {
@@ -366,19 +363,11 @@ public class MainClientExec implements C
             switch (step) {
 
             case HttpRouteDirector.CONNECT_TARGET:
-                this.connManager.connect(
-                        endpoint,
-                        timeout > 0 ? timeout : 0,
-                        TimeUnit.MILLISECONDS,
-                        context);
+                this.connManager.connect(endpoint, timeout, context);
                 tracker.connectTarget(route.isSecure());
                 break;
             case HttpRouteDirector.CONNECT_PROXY:
-                this.connManager.connect(
-                        endpoint,
-                        timeout > 0 ? timeout : 0,
-                        TimeUnit.MILLISECONDS,
-                        context);
+                this.connManager.connect(endpoint, timeout, context);
                 final HttpHost proxy  = route.getProxyHost();
                 tracker.connectProxy(proxy, false);
                 break;
@@ -432,7 +421,6 @@ public class MainClientExec implements C
             final HttpClientContext context) throws HttpException, IOException {
 
         final RequestConfig config = context.getRequestConfig();
-        final int timeout = config.getConnectTimeout();
 
         final HttpHost target = route.getTargetHost();
         final HttpHost proxy = route.getProxyHost();
@@ -440,18 +428,14 @@ public class MainClientExec implements C
         ClassicHttpResponse response = null;
 
         final String authority = target.toHostString();
-        final ClassicHttpRequest connect = new BasicClassicHttpRequest("CONNECT", authority);
+        final ClassicHttpRequest connect = new BasicClassicHttpRequest("CONNECT", target, authority);
         connect.setVersion(HttpVersion.HTTP_1_1);
 
         this.requestExecutor.preProcess(connect, this.proxyHttpProcessor, context);
 
         while (response == null) {
             if (!endpoint.isConnected()) {
-                this.connManager.connect(
-                        endpoint,
-                        timeout > 0 ? timeout : 0,
-                        TimeUnit.MILLISECONDS,
-                        context);
+                this.connManager.connect(endpoint, config.getConnectTimeout(), context);
             }
 
             connect.removeHeaders(HttpHeaders.PROXY_AUTHORIZATION);

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=1793305&r1=1793304&r2=1793305&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 Mon May  1 10:47:09 2017
@@ -30,7 +30,6 @@ package org.apache.hc.client5.http.impl.
 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;
@@ -60,6 +59,7 @@ import org.apache.hc.core5.http.protocol
 import org.apache.hc.core5.http.protocol.RequestTargetHost;
 import org.apache.hc.core5.http.protocol.RequestUserAgent;
 import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.TimeValue;
 import org.apache.hc.core5.util.VersionInfo;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -123,8 +123,8 @@ public class MinimalClientExec implement
 
         final ConnectionEndpoint endpoint;
         try {
-            final int timeout = config.getConnectionRequestTimeout();
-            endpoint = connRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS);
+            final TimeValue timeout = config.getConnectionRequestTimeout();
+            endpoint = connRequest.get(timeout.getDuration(), timeout.getTimeUnit());
         } catch(final TimeoutException ex) {
             throw new ConnectionRequestTimeoutException(ex.getMessage());
         } catch(final InterruptedException interrupted) {
@@ -148,16 +148,11 @@ public class MinimalClientExec implement
                 execAware.setCancellable(endpointHolder);
             }
             if (!endpoint.isConnected()) {
-                final int timeout = config.getConnectTimeout();
-                this.connManager.connect(
-                        endpoint,
-                        timeout > 0 ? timeout : 0,
-                        TimeUnit.MILLISECONDS,
-                        context);
+                this.connManager.connect(endpoint, config.getConnectTimeout(), context);
             }
-            final int timeout = config.getSocketTimeout();
-            if (timeout >= 0) {
-                endpoint.setSocketTimeout(timeout);
+            final TimeValue timeout = config.getSocketTimeout();
+            if (TimeValue.isNonNegative(timeout)) {
+                endpoint.setSocketTimeout(timeout.toMillisIntBound());
             }
 
             context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
@@ -170,8 +165,8 @@ public class MinimalClientExec implement
             // 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);
-                endpointHolder.setValidFor(duration, TimeUnit.MILLISECONDS);
+                final TimeValue duration = keepAliveStrategy.getKeepAliveDuration(response, context);
+                endpointHolder.setValidFor(duration);
                 endpointHolder.markReusable();
             } else {
                 endpointHolder.markNonReusable();

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=1793305&r1=1793304&r2=1793305&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 Mon May  1 10:47:09 2017
@@ -60,7 +60,8 @@ import org.apache.hc.core5.http.HttpEnti
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHeaders;
 import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.config.ConnectionConfig;
+import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.config.Lookup;
 import org.apache.hc.core5.http.config.RegistryBuilder;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
@@ -84,7 +85,6 @@ import org.apache.hc.core5.util.Args;
 public class ProxyClient {
 
     private final HttpConnectionFactory<ManagedHttpClientConnection> connFactory;
-    private final ConnectionConfig connectionConfig;
     private final RequestConfig requestConfig;
     private final HttpProcessor httpProcessor;
     private final HttpRequestExecutor requestExec;
@@ -95,15 +95,15 @@ public class ProxyClient {
     private final ConnectionReuseStrategy reuseStrategy;
 
     /**
-     * @since 4.3
+     * @since 5.0
      */
     public ProxyClient(
             final HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
-            final ConnectionConfig connectionConfig,
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig,
             final RequestConfig requestConfig) {
         super();
-        this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
-        this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
+        this.connFactory = connFactory != null ? connFactory : new ManagedHttpClientConnectionFactory(h1Config, charCodingConfig, null, null);
         this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT;
         this.httpProcessor = new DefaultHttpProcessor(
                 new RequestTargetHost(), new RequestClientConnControl(), new RequestUserAgent());
@@ -125,11 +125,11 @@ public class ProxyClient {
      * @since 4.3
      */
     public ProxyClient(final RequestConfig requestConfig) {
-        this(null, null, requestConfig);
+        this(null, null, null, requestConfig);
     }
 
     public ProxyClient() {
-        this(null, null, null);
+        this(null, null, null, null);
     }
 
     public Socket tunnel(
@@ -158,7 +158,6 @@ public class ProxyClient {
         credsProvider.setCredentials(new AuthScope(proxy), credentials);
 
         // Populate the execution context
-        context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
         context.setAttribute(HttpCoreContext.HTTP_REQUEST, connect);
         context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
         context.setAttribute(HttpClientContext.CREDS_PROVIDER, credsProvider);

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RoutedHttpRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RoutedHttpRequest.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RoutedHttpRequest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/RoutedHttpRequest.java Mon May  1 10:47:09 2017
@@ -160,6 +160,9 @@ public class RoutedHttpRequest extends H
                 buf.append(":").append(this.authority.getPort());
             }
         }
+        if (buf.length() > 0 && this.path != null && !this.path.startsWith("/")) {
+            buf.append("/");
+        }
         buf.append(this.path != null ? this.path : "/");
         return buf.toString();
     }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionEndpoint.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionEndpoint.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionEndpoint.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/ConnectionEndpoint.java Mon May  1 10:47:09 2017
@@ -27,7 +27,6 @@
 
 package org.apache.hc.client5.http.io;
 
-import java.io.Closeable;
 import java.io.IOException;
 
 import org.apache.hc.core5.annotation.Contract;
@@ -37,6 +36,7 @@ import org.apache.hc.core5.http.ClassicH
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
 import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.io.GracefullyCloseable;
 
 /**
  * Client connection endpoint that can be used to execute message exchanges.
@@ -44,7 +44,7 @@ import org.apache.hc.core5.http.protocol
  * @since 5.0
  */
 @Contract(threading = ThreadingBehavior.SAFE)
-public abstract class ConnectionEndpoint implements Closeable {
+public abstract class ConnectionEndpoint implements GracefullyCloseable {
 
     public abstract ClassicHttpResponse execute(
             ClassicHttpRequest request,
@@ -55,6 +55,4 @@ public abstract class ConnectionEndpoint
 
     public abstract void setSocketTimeout(int timeout);
 
-    public abstract void shutdown() throws IOException;
-
 }

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=1793305&r1=1793304&r2=1793305&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 Mon May  1 10:47:09 2017
@@ -28,10 +28,10 @@ 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.protocol.HttpContext;
+import org.apache.hc.core5.util.TimeValue;
 
 /**
  * Represents a manager of persistent client connections.
@@ -57,7 +57,7 @@ public interface HttpClientConnectionMan
      * 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)}
+     * by calling {@link #connect(ConnectionEndpoint, TimeValue, 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
@@ -79,11 +79,8 @@ public interface HttpClientConnectionMan
      * @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 release(ConnectionEndpoint endpoint, Object newState, long validDuration, TimeUnit timeUnit);
+    void release(ConnectionEndpoint endpoint, Object newState, TimeValue validDuration);
 
     /**
      * Connects the endpoint to the initial hop (connection target in case
@@ -92,15 +89,10 @@ public interface HttpClientConnectionMan
      *
      * @param endpoint      the managed endpoint.
      * @param connectTimeout connect timeout.
-     * @param timeUnit the time unit.
      * @param context the actual HTTP context.
      * @throws IOException
      */
-    void connect(
-            ConnectionEndpoint endpoint,
-            long connectTimeout,
-            TimeUnit timeUnit,
-            HttpContext context) throws IOException;
+    void connect(ConnectionEndpoint endpoint, TimeValue connectTimeout, HttpContext context) throws IOException;
 
     /**
      * Upgrades the endpoint's underlying transport to Transport Layer Security.
@@ -109,8 +101,6 @@ public interface HttpClientConnectionMan
      * @param context the actual HTTP context.
      * @throws IOException
      */
-    void upgrade(
-            ConnectionEndpoint endpoint,
-            HttpContext context) throws IOException;
+    void upgrade(ConnectionEndpoint endpoint, HttpContext context) throws IOException;
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/HttpClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/HttpClientConnectionOperator.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/HttpClientConnectionOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/HttpClientConnectionOperator.java Mon May  1 10:47:09 2017
@@ -33,6 +33,7 @@ import java.net.InetSocketAddress;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.config.SocketConfig;
 import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.util.TimeValue;
 
 /**
  * Connection operator that performs connection connect and upgrade operations. Usually, components
@@ -49,7 +50,7 @@ public interface HttpClientConnectionOpe
             ManagedHttpClientConnection conn,
             HttpHost host,
             InetSocketAddress localAddress,
-            int connectTimeout,
+            TimeValue connectTimeout,
             SocketConfig socketConfig,
             HttpContext context) throws IOException;
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/nio/AsyncClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/nio/AsyncClientConnectionManager.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/nio/AsyncClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/nio/AsyncClientConnectionManager.java Mon May  1 10:47:09 2017
@@ -28,12 +28,12 @@ package org.apache.hc.client5.http.nio;
 
 import java.io.Closeable;
 import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
 
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.reactor.ConnectionInitiator;
+import org.apache.hc.core5.util.TimeValue;
 
 /**
  * Represents a manager of persistent non-blocking client connections.
@@ -60,7 +60,7 @@ public interface AsyncClientConnectionMa
      * {@link AsyncConnectionEndpoint#isConnected() disconnected}. The consumer
      * of the endpoint is responsible for fully establishing the route to
      * the endpoint target by calling {@link #connect(AsyncConnectionEndpoint,
-     * ConnectionInitiator, long, TimeUnit, HttpContext, FutureCallback)}
+     * ConnectionInitiator, TimeValue, HttpContext, FutureCallback)}
      * in order to connect directly to the target or to the first proxy hop,
      * and optionally calling {@link #upgrade(AsyncConnectionEndpoint, HttpContext)}
      * method to upgrade the underlying transport to Transport Layer Security
@@ -71,14 +71,12 @@ public interface AsyncClientConnectionMa
      * @param state expected state of the connection or {@code null}
      *              if the connection is not expected to carry any state.
      * @param timeout lease request timeout.
-     * @param timeUnit time unit.
      * @param callback result callback.
      */
     Future<AsyncConnectionEndpoint> lease(
             HttpRoute route,
             Object state,
-            long timeout,
-            TimeUnit timeUnit,
+            TimeValue timeout,
             FutureCallback<AsyncConnectionEndpoint> callback);
 
     /**
@@ -91,9 +89,8 @@ public interface AsyncClientConnectionMa
      * @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.
      */
-    void release(AsyncConnectionEndpoint endpoint, Object newState, long validDuration, TimeUnit timeUnit);
+    void release(AsyncConnectionEndpoint endpoint, Object newState, TimeValue validDuration);
 
     /**
      * Connects the endpoint to the initial hop (connection target in case
@@ -102,15 +99,13 @@ public interface AsyncClientConnectionMa
      *
      * @param endpoint      the managed endpoint.
      * @param connectTimeout connect timeout.
-     * @param timeUnit time unit.
      * @param context the actual HTTP context.
      * @param callback result callback.
      */
     Future<AsyncConnectionEndpoint> connect(
             AsyncConnectionEndpoint endpoint,
             ConnectionInitiator connectionInitiator,
-            long connectTimeout,
-            TimeUnit timeUnit,
+            TimeValue connectTimeout,
             HttpContext context,
             FutureCallback<AsyncConnectionEndpoint> callback);
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/socket/ConnectionSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/socket/ConnectionSocketFactory.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/socket/ConnectionSocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/socket/ConnectionSocketFactory.java Mon May  1 10:47:09 2017
@@ -33,6 +33,7 @@ import java.net.Socket;
 
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.util.TimeValue;
 
 /**
  * A factory for creating and connecting connection sockets.
@@ -43,7 +44,7 @@ public interface ConnectionSocketFactory
 
     /**
      * Creates new, unconnected socket. The socket should subsequently be passed to
-     * {@link #connectSocket(int, Socket, HttpHost, InetSocketAddress, InetSocketAddress,
+     * {@link #connectSocket(TimeValue, Socket, HttpHost, InetSocketAddress, InetSocketAddress,
      *    HttpContext) connectSocket} method.
      *
      * @return  a new socket
@@ -70,7 +71,7 @@ public interface ConnectionSocketFactory
      * @throws IOException if an I/O error occurs
      */
     Socket connectSocket(
-        int connectTimeout,
+        TimeValue connectTimeout,
         Socket sock,
         HttpHost host,
         InetSocketAddress remoteAddress,

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/socket/PlainConnectionSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/socket/PlainConnectionSocketFactory.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/socket/PlainConnectionSocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/socket/PlainConnectionSocketFactory.java Mon May  1 10:47:09 2017
@@ -35,6 +35,7 @@ import org.apache.hc.core5.annotation.Co
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.util.TimeValue;
 
 /**
  * The default class for creating plain (unencrypted) sockets.
@@ -61,7 +62,7 @@ public class PlainConnectionSocketFactor
 
     @Override
     public Socket connectSocket(
-            final int connectTimeout,
+            final TimeValue connectTimeout,
             final Socket socket,
             final HttpHost host,
             final InetSocketAddress remoteAddress,
@@ -72,7 +73,7 @@ public class PlainConnectionSocketFactor
             sock.bind(localAddress);
         }
         try {
-            sock.connect(remoteAddress, connectTimeout);
+            sock.connect(remoteAddress, TimeValue.isPositive(connectTimeout) ? connectTimeout.toMillisIntBound() : 0);
         } catch (final IOException ex) {
             try {
                 sock.close();

Copied: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/H2TlsStrategy.java (from r1790039, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLUpgradeStrategy.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/H2TlsStrategy.java?p2=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/H2TlsStrategy.java&p1=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLUpgradeStrategy.java&r1=1790039&r2=1793305&rev=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLUpgradeStrategy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/H2TlsStrategy.java Mon May  1 10:47:09 2017
@@ -44,11 +44,14 @@ import javax.net.ssl.SSLSession;
 import javax.security.auth.x500.X500Principal;
 
 import org.apache.hc.client5.http.psl.PublicSuffixMatcherLoader;
+import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.http2.ssl.H2TlsSupport;
+import org.apache.hc.core5.net.NamedEndpoint;
 import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
 import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
 import org.apache.hc.core5.ssl.SSLContexts;
 import org.apache.hc.core5.util.Args;
@@ -61,7 +64,7 @@ import org.apache.logging.log4j.Logger;
  *
  * @since 5.0
  */
-public class SSLUpgradeStrategy implements TlsStrategy {
+public class H2TlsStrategy implements TlsStrategy {
 
     private static String[] split(final String s) {
         if (TextUtils.isBlank(s)) {
@@ -75,13 +78,13 @@ public class SSLUpgradeStrategy implemen
     }
 
     public static TlsStrategy getDefault() {
-        return new SSLUpgradeStrategy(
+        return new H2TlsStrategy(
                 SSLContexts.createDefault(),
                 getDefaultHostnameVerifier());
     }
 
     public static TlsStrategy getSystemDefault() {
-        return new SSLUpgradeStrategy(
+        return new H2TlsStrategy(
                 SSLContexts.createSystemDefault(),
                 split(System.getProperty("https.protocols")),
                 split(System.getProperty("https.cipherSuites")),
@@ -97,7 +100,7 @@ public class SSLUpgradeStrategy implemen
     private final SSLBufferManagement sslBufferManagement;
     private final HostnameVerifier hostnameVerifier;
 
-    public SSLUpgradeStrategy(
+    public H2TlsStrategy(
             final SSLContext sslContext,
             final String[] supportedProtocols,
             final String[] supportedCipherSuites,
@@ -111,65 +114,54 @@ public class SSLUpgradeStrategy implemen
         this.hostnameVerifier = hostnameVerifier != null ? hostnameVerifier : getDefaultHostnameVerifier();
     }
 
-    public SSLUpgradeStrategy(
+    public H2TlsStrategy(
             final SSLContext sslcontext,
             final HostnameVerifier hostnameVerifier) {
         this(sslcontext, null, null, SSLBufferManagement.STATIC, hostnameVerifier);
     }
 
-    public SSLUpgradeStrategy(final SSLContext sslcontext) {
+    public H2TlsStrategy(final SSLContext sslcontext) {
         this(sslcontext, getDefaultHostnameVerifier());
     }
 
     @Override
-    public void upgrade(
+    public boolean upgrade(
             final TransportSecurityLayer tlsSession,
-            final String hostname,
+            final HttpHost host,
             final SocketAddress localAddress,
             final SocketAddress remoteAddress,
-            final String... parameters) {
-        tlsSession.start(sslContext, sslBufferManagement, new SSLSessionInitializer() {
+            final Object attachment) {
+        tlsSession.startTls(sslContext, sslBufferManagement, H2TlsSupport.enforceRequirements(null, new SSLSessionInitializer() {
 
             @Override
-            public void initialize(final SSLEngine sslengine) throws SSLException {
+            public void initialize(final NamedEndpoint endpoint, final SSLEngine sslEngine) {
                 if (supportedProtocols != null) {
-                    sslengine.setEnabledProtocols(supportedProtocols);
-                } else {
-                    // If supported protocols are not explicitly set, remove all SSL protocol versions
-                    final String[] allProtocols = sslengine.getEnabledProtocols();
-                    final List<String> enabledProtocols = new ArrayList<>(allProtocols.length);
-                    for (final String protocol: allProtocols) {
-                        if (!protocol.startsWith("SSL")) {
-                            enabledProtocols.add(protocol);
-                        }
-                    }
-                    if (!enabledProtocols.isEmpty()) {
-                        sslengine.setEnabledProtocols(enabledProtocols.toArray(new String[enabledProtocols.size()]));
-                    }
+                    sslEngine.setEnabledProtocols(supportedProtocols);
                 }
                 if (supportedCipherSuites != null) {
-                    sslengine.setEnabledCipherSuites(supportedCipherSuites);
+                    sslEngine.setEnabledCipherSuites(supportedCipherSuites);
                 }
-                initializeEngine(sslengine);
+                initializeEngine(sslEngine);
 
                 if (log.isDebugEnabled()) {
-                    log.debug("Enabled protocols: " + Arrays.asList(sslengine.getEnabledProtocols()));
-                    log.debug("Enabled cipher suites:" + Arrays.asList(sslengine.getEnabledCipherSuites()));
+                    log.debug("Enabled protocols: " + Arrays.asList(sslEngine.getEnabledProtocols()));
+                    log.debug("Enabled cipher suites:" + Arrays.asList(sslEngine.getEnabledCipherSuites()));
                 }
             }
 
-        }, new SSLSessionVerifier() {
+        }), new SSLSessionVerifier() {
 
             @Override
-            public void verify(final IOSession iosession, final SSLSession sslsession) throws SSLException {
-                // TODO: fix after upgrading to HttpCore 5.0a3
-                verifySession(hostname, sslsession);
+            public TlsDetails verify(final NamedEndpoint endpoint, final SSLEngine sslEngine) throws SSLException {
+                verifySession(endpoint.getHostName(), sslEngine.getSession());
+                return createTlsDetails(sslEngine);
             }
 
         });
+        return true;
     }
 
-    protected void initializeEngine(final SSLEngine engine) {
+    protected void initializeEngine(final SSLEngine sslEngine) {
     }
 
     protected void verifySession(
@@ -228,4 +220,8 @@ public class SSLUpgradeStrategy implemen
         }
     }
 
+    protected TlsDetails createTlsDetails(final SSLEngine sslEngine) {
+        return null;
+    }
+
 }

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

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

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

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLConnectionSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLConnectionSocketFactory.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLConnectionSocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLConnectionSocketFactory.java Mon May  1 10:47:09 2017
@@ -56,6 +56,7 @@ import org.apache.hc.core5.http.protocol
 import org.apache.hc.core5.ssl.SSLContexts;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.TextUtils;
+import org.apache.hc.core5.util.TimeValue;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -254,7 +255,7 @@ public class SSLConnectionSocketFactory
 
     @Override
     public Socket connectSocket(
-            final int connectTimeout,
+            final TimeValue connectTimeout,
             final Socket socket,
             final HttpHost host,
             final InetSocketAddress remoteAddress,
@@ -267,13 +268,13 @@ public class SSLConnectionSocketFactory
             sock.bind(localAddress);
         }
         try {
-            if (connectTimeout > 0 && sock.getSoTimeout() == 0) {
-                sock.setSoTimeout(connectTimeout);
+            if (TimeValue.isPositive(connectTimeout) && sock.getSoTimeout() == 0) {
+                sock.setSoTimeout(connectTimeout.toMillisIntBound());
             }
             if (this.log.isDebugEnabled()) {
                 this.log.debug("Connecting socket to " + remoteAddress + " with timeout " + connectTimeout);
             }
-            sock.connect(remoteAddress, connectTimeout);
+            sock.connect(remoteAddress, connectTimeout != null ? connectTimeout.toMillisIntBound() : 0);
         } catch (final IOException ex) {
             try {
                 sock.close();

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java Mon May  1 10:47:09 2017
@@ -29,8 +29,10 @@ package org.apache.hc.client5.http.confi
 
 import java.net.InetAddress;
 import java.util.Arrays;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.util.TimeValue;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -45,9 +47,9 @@ public class TestRequestConfig {
     @Test
     public void testDefaults() {
         final RequestConfig config = RequestConfig.DEFAULT;
-        Assert.assertEquals(-1, config.getSocketTimeout());
-        Assert.assertEquals(180000, config.getConnectTimeout());
-        Assert.assertEquals(180000, config.getConnectionRequestTimeout());
+        Assert.assertEquals(TimeValue.NEG_ONE_MILLISECONDS, config.getSocketTimeout());
+        Assert.assertEquals(TimeValue.ofMinutes(3), config.getConnectTimeout());
+        Assert.assertEquals(TimeValue.ofMinutes(3), config.getConnectionRequestTimeout());
         Assert.assertEquals(false, config.isExpectContinueEnabled());
         Assert.assertEquals(true, config.isAuthenticationEnabled());
         Assert.assertEquals(true, config.isRedirectsEnabled());
@@ -64,9 +66,9 @@ public class TestRequestConfig {
     @Test
     public void testBuildAndCopy() throws Exception {
         final RequestConfig config0 = RequestConfig.custom()
-                .setSocketTimeout(22)
-                .setConnectTimeout(33)
-                .setConnectionRequestTimeout(44)
+                .setSocketTimeout(22, TimeUnit.MILLISECONDS)
+                .setConnectTimeout(33, TimeUnit.MILLISECONDS)
+                .setConnectionRequestTimeout(44, TimeUnit.MILLISECONDS)
                 .setExpectContinueEnabled(true)
                 .setAuthenticationEnabled(false)
                 .setRedirectsEnabled(false)
@@ -80,9 +82,9 @@ public class TestRequestConfig {
                 .setContentCompressionEnabled(false)
                 .build();
         final RequestConfig config = RequestConfig.copy(config0).build();
-        Assert.assertEquals(22, config.getSocketTimeout());
-        Assert.assertEquals(33, config.getConnectTimeout());
-        Assert.assertEquals(44, config.getConnectionRequestTimeout());
+        Assert.assertEquals(TimeValue.ofMillis(22), config.getSocketTimeout());
+        Assert.assertEquals(TimeValue.ofMillis(33), config.getConnectTimeout());
+        Assert.assertEquals(TimeValue.ofMillis(44), config.getConnectionRequestTimeout());
         Assert.assertEquals(true, config.isExpectContinueEnabled());
         Assert.assertEquals(false, config.isAuthenticationEnabled());
         Assert.assertEquals(false, config.isRedirectsEnabled());

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultConnKeepAliveStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultConnKeepAliveStrategy.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultConnKeepAliveStrategy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestDefaultConnKeepAliveStrategy.java Mon May  1 10:47:09 2017
@@ -32,6 +32,7 @@ import org.apache.hc.core5.http.HttpStat
 import org.apache.hc.core5.http.message.BasicHttpResponse;
 import org.apache.hc.core5.http.protocol.BasicHttpContext;
 import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.util.TimeValue;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -52,8 +53,8 @@ public class TestDefaultConnKeepAliveStr
         final HttpContext context = new BasicHttpContext(null);
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         final ConnectionKeepAliveStrategy keepAliveStrat = new DefaultConnectionKeepAliveStrategy();
-        final long d = keepAliveStrat.getKeepAliveDuration(response, context);
-        Assert.assertEquals(-1, d);
+        final TimeValue d = keepAliveStrat.getKeepAliveDuration(response, context);
+        Assert.assertEquals(TimeValue.NEG_ONE_MILLISECONDS, d);
     }
 
     @Test
@@ -62,8 +63,8 @@ public class TestDefaultConnKeepAliveStr
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.addHeader("Keep-Alive", "timeout, max=20");
         final ConnectionKeepAliveStrategy keepAliveStrat = new DefaultConnectionKeepAliveStrategy();
-        final long d = keepAliveStrat.getKeepAliveDuration(response, context);
-        Assert.assertEquals(-1, d);
+        final TimeValue d = keepAliveStrat.getKeepAliveDuration(response, context);
+        Assert.assertEquals(TimeValue.NEG_ONE_MILLISECONDS, d);
     }
 
     @Test
@@ -72,8 +73,8 @@ public class TestDefaultConnKeepAliveStr
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.addHeader("Keep-Alive", "timeout=whatever, max=20");
         final ConnectionKeepAliveStrategy keepAliveStrat = new DefaultConnectionKeepAliveStrategy();
-        final long d = keepAliveStrat.getKeepAliveDuration(response, context);
-        Assert.assertEquals(-1, d);
+        final TimeValue d = keepAliveStrat.getKeepAliveDuration(response, context);
+        Assert.assertEquals(TimeValue.NEG_ONE_MILLISECONDS, d);
     }
 
     @Test
@@ -82,8 +83,8 @@ public class TestDefaultConnKeepAliveStr
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
         response.addHeader("Keep-Alive", "timeout=300, max=20");
         final ConnectionKeepAliveStrategy keepAliveStrat = new DefaultConnectionKeepAliveStrategy();
-        final long d = keepAliveStrat.getKeepAliveDuration(response, context);
-        Assert.assertEquals(300000, d);
+        final TimeValue d = keepAliveStrat.getKeepAliveDuration(response, context);
+        Assert.assertEquals(TimeValue.ofSeconds(300), d);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestIdleConnectionEvictor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestIdleConnectionEvictor.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestIdleConnectionEvictor.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestIdleConnectionEvictor.java Mon May  1 10:47:09 2017
@@ -30,6 +30,7 @@ package org.apache.hc.client5.http.impl;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.hc.core5.pool.ConnPoolControl;
+import org.apache.hc.core5.util.TimeValue;
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -43,13 +44,13 @@ public class TestIdleConnectionEvictor {
     public void testEvictExpiredAndIdle() throws Exception {
         final ConnPoolControl<?> cm = Mockito.mock(ConnPoolControl.class);
         final IdleConnectionEvictor connectionEvictor = new IdleConnectionEvictor(cm,
-                500, TimeUnit.MILLISECONDS, 3, TimeUnit.SECONDS);
+                TimeValue.ofMillis(500), TimeValue.ofSeconds(3));
         connectionEvictor.start();
 
         Thread.sleep(1000);
 
         Mockito.verify(cm, Mockito.atLeast(1)).closeExpired();
-        Mockito.verify(cm, Mockito.atLeast(1)).closeIdle(3000, TimeUnit.MILLISECONDS);
+        Mockito.verify(cm, Mockito.atLeast(1)).closeIdle(TimeValue.ofSeconds(3));
 
         Assert.assertTrue(connectionEvictor.isRunning());
 
@@ -62,13 +63,13 @@ public class TestIdleConnectionEvictor {
     public void testEvictExpiredOnly() throws Exception {
         final ConnPoolControl<?> cm = Mockito.mock(ConnPoolControl.class);
         final IdleConnectionEvictor connectionEvictor = new IdleConnectionEvictor(cm,
-                500, TimeUnit.MILLISECONDS, 0, TimeUnit.SECONDS);
+                TimeValue.ofMillis(500), null);
         connectionEvictor.start();
 
         Thread.sleep(1000);
 
         Mockito.verify(cm, Mockito.atLeast(1)).closeExpired();
-        Mockito.verify(cm, Mockito.never()).closeIdle(Mockito.anyLong(), Mockito.<TimeUnit>any());
+        Mockito.verify(cm, Mockito.never()).closeIdle(Mockito.<TimeValue>any());
 
         Assert.assertTrue(connectionEvictor.isRunning());
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestClientAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestClientAuthentication.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestClientAuthentication.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/integration/TestClientAuthentication.java Mon May  1 10:47:09 2017
@@ -59,8 +59,8 @@ import org.apache.hc.client5.http.sync.m
 import org.apache.hc.client5.http.sync.methods.HttpPut;
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.EndpointDetails;
 import org.apache.hc.core5.http.HeaderElements;
-import org.apache.hc.core5.http.HttpConnection;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHeaders;
@@ -512,8 +512,8 @@ public class TestClientAuthentication ex
                 final ClassicHttpRequest request,
                 final ClassicHttpResponse response,
                 final HttpContext context) throws HttpException, IOException {
-            final HttpConnection conn = (HttpConnection) context.getAttribute(HttpCoreContext.HTTP_CONNECTION);
-            final InetSocketAddress socketAddress = (InetSocketAddress) conn.getLocalAddress();
+            final EndpointDetails endpoint = (EndpointDetails) context.getAttribute(HttpCoreContext.CONNECTION_ENDPOINT);
+            final InetSocketAddress socketAddress = (InetSocketAddress) endpoint.getLocalAddress();
             final String localhost = socketAddress.getHostName();
             final int port = socketAddress.getPort();
             response.setCode(HttpStatus.SC_MOVED_PERMANENTLY);



Mime
View raw message