From b74cb12d4437890c7e30da36f5aff7a915d8f20e Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Mon, 22 Oct 2018 15:14:04 +0200 Subject: [PATCH] Renamed RequestConfig#connectionTimeout to RequestConfig#connectTimeout --- .../http/examples/fluent/FluentExecutor.java | 3 +- .../http/examples/fluent/FluentRequests.java | 2 +- .../hc/client5/http/fluent/Request.java | 10 ++-- .../AbstractHttp1IntegrationTestBase.java | 2 +- .../client5/testing/async/TestHttp1Async.java | 2 +- .../async/TestHttp1AsyncRedirects.java | 2 +- .../TestHttp1AsyncStatefulConnManagement.java | 2 +- .../async/TestHttp1ClientAuthentication.java | 2 +- .../client5/testing/async/TestHttp2Async.java | 2 +- .../testing/async/TestHttp2AsyncRedirect.java | 2 +- .../async/TestHttp2ClientAuthentication.java | 2 +- .../testing/sync/LocalServerTestBase.java | 6 +-- .../http/examples/ClientConfiguration.java | 2 +- .../hc/client5/http/config/RequestConfig.java | 47 +++++++++---------- .../async/InternalHttp2AsyncExecRuntime.java | 6 +-- .../async/InternalHttpAsyncExecRuntime.java | 4 +- .../impl/async/MinimalHttp2AsyncClient.java | 2 +- .../impl/async/MinimalHttpAsyncClient.java | 4 +- .../impl/classic/InternalExecRuntime.java | 4 +- .../http/config/TestRequestConfig.java | 6 +-- .../impl/classic/TestInternalExecRuntime.java | 4 +- 21 files changed, 57 insertions(+), 59 deletions(-) diff --git a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentExecutor.java b/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentExecutor.java index 56e3fc992..2c763d153 100644 --- a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentExecutor.java +++ b/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentExecutor.java @@ -52,7 +52,8 @@ public class FluentExecutor { // Execute a GET with timeout settings and return response content as String. executor.execute(Request.Get("http://somehost/") - .connectionTimeout(Timeout.ofSeconds(1))).returnContent().asString(); + .connectTimeout(Timeout.ofSeconds(1))) + .returnContent().asString(); // Execute a POST with the 'expect-continue' handshake, using HTTP/1.1, // containing a request body as String and return response content as byte array. diff --git a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentRequests.java b/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentRequests.java index 4e656792a..a8d22bf06 100644 --- a/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentRequests.java +++ b/httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/FluentRequests.java @@ -43,7 +43,7 @@ public class FluentRequests { public static void main(String[] args)throws Exception { // Execute a GET with timeout settings and return response content as String. Request.Get("http://somehost/") - .connectionTimeout(Timeout.ofSeconds(1)) + .connectTimeout(Timeout.ofSeconds(1)) .execute().returnContent().asString(); // Execute a POST with the 'expect-continue' handshake, using HTTP/1.1, diff --git a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java index 0494461d1..e39c74720 100644 --- a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java +++ b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java @@ -76,7 +76,7 @@ public class Request { private final ClassicHttpRequest request; private Boolean useExpectContinue; - private Timeout connectionTimeout; + private Timeout connectTimeout; private HttpHost proxy; private SimpleDateFormat dateFormatter; @@ -174,8 +174,8 @@ public class Request { if (this.useExpectContinue != null) { builder.setExpectContinueEnabled(this.useExpectContinue); } - if (this.connectionTimeout != null) { - builder.setConnectionTimeout(this.connectionTimeout); + if (this.connectTimeout != null) { + builder.setConnectTimeout(this.connectTimeout); } if (this.proxy != null) { builder.setProxy(this.proxy); @@ -287,8 +287,8 @@ public class Request { //// HTTP connection parameter operations - public Request connectionTimeout(final Timeout timeout) { - this.connectionTimeout = timeout; + public Request connectTimeout(final Timeout timeout) { + this.connectTimeout = timeout; return this; } diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttp1IntegrationTestBase.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttp1IntegrationTestBase.java index 06ddd3877..59b46b833 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttp1IntegrationTestBase.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttp1IntegrationTestBase.java @@ -90,8 +90,8 @@ public abstract class AbstractHttp1IntegrationTestBase extends AbstractServerTes protected void before() throws Throwable { clientBuilder = HttpAsyncClientBuilder.create() .setDefaultRequestConfig(RequestConfig.custom() - .setConnectionTimeout(TIMEOUT) .setConnectionRequestTimeout(TIMEOUT) + .setConnectTimeout(TIMEOUT) .build()) .setConnectionManager(connManager); } diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java index 4171e72a7..7623b64cf 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java @@ -95,8 +95,8 @@ public class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest targetPreferredAuthSchemes; private final Collection proxyPreferredAuthSchemes; private final Timeout connectionRequestTimeout; - private final Timeout connectionTimeout; + private final Timeout connectTimeout; private final boolean contentCompressionEnabled; private final boolean hardCancellationEnabled; @@ -64,7 +64,8 @@ public class RequestConfig implements Cloneable { * Intended for CDI compatibility */ protected RequestConfig() { - this(false, null, null, false, false, 0, false, null, null, DEFAULT_CONNECTION_REQUEST_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT, false, false); + this(false, null, null, false, false, 0, false, null, null, + DEFAULT_CONNECTION_REQUEST_TIMEOUT, DEFAULT_CONNECT_TIMEOUT, false, false); } RequestConfig( @@ -78,7 +79,7 @@ public class RequestConfig implements Cloneable { final Collection targetPreferredAuthSchemes, final Collection proxyPreferredAuthSchemes, final Timeout connectionRequestTimeout, - final Timeout connectionTimeout, + final Timeout connectTimeout, final boolean contentCompressionEnabled, final boolean hardCancellationEnabled) { super(); @@ -92,7 +93,7 @@ public class RequestConfig implements Cloneable { this.targetPreferredAuthSchemes = targetPreferredAuthSchemes; this.proxyPreferredAuthSchemes = proxyPreferredAuthSchemes; this.connectionRequestTimeout = connectionRequestTimeout; - this.connectionTimeout = connectionTimeout; + this.connectTimeout = connectTimeout; this.contentCompressionEnabled = contentCompressionEnabled; this.hardCancellationEnabled = hardCancellationEnabled; } @@ -210,12 +211,10 @@ public class RequestConfig implements Cloneable { } /** - * Returns the timeout in milliseconds used when requesting a connection - * from the connection manager. A timeout value of zero is interpreted - * as an infinite timeout. + * Returns the connection lease request timeout used when requesting + * a connection from the connection manager. *

* A timeout value of zero is interpreted as an infinite timeout. - * A negative value is interpreted as undefined (system default). *

*

* Default: 3 minutes. @@ -226,9 +225,9 @@ public class RequestConfig implements Cloneable { } /** - * Determines the timeout in milliseconds until a new connection is - * fully established or established connection transmits a data packet. - * A timeout value of zero is interpreted as an infinite timeout. + * Determines the timeout until a new connection is fully established. + * This may also include transport security negotiation exchanges + * such as {@code SSL} or {@code TLS} protocol negotiation). *

* A timeout value of zero is interpreted as an infinite timeout. * A negative value is interpreted as undefined (system default). @@ -236,11 +235,9 @@ public class RequestConfig implements Cloneable { *

* Default: 3 minutes *

- * - * @since 5.0 */ - public Timeout getConnectionTimeout() { - return connectionTimeout; + public Timeout getConnectTimeout() { + return connectTimeout; } /** @@ -305,7 +302,7 @@ public class RequestConfig implements Cloneable { builder.append(", targetPreferredAuthSchemes=").append(targetPreferredAuthSchemes); builder.append(", proxyPreferredAuthSchemes=").append(proxyPreferredAuthSchemes); builder.append(", connectionRequestTimeout=").append(connectionRequestTimeout); - builder.append(", connectionTimeout=").append(connectionTimeout); + builder.append(", connectTimeout=").append(connectTimeout); builder.append(", contentCompressionEnabled=").append(contentCompressionEnabled); builder.append(", hardCancellationEnabled=").append(hardCancellationEnabled); builder.append("]"); @@ -328,7 +325,7 @@ public class RequestConfig implements Cloneable { .setTargetPreferredAuthSchemes(config.getTargetPreferredAuthSchemes()) .setProxyPreferredAuthSchemes(config.getProxyPreferredAuthSchemes()) .setConnectionRequestTimeout(config.getConnectionRequestTimeout()) - .setConnectionTimeout(config.getConnectionTimeout()) + .setConnectTimeout(config.getConnectTimeout()) .setContentCompressionEnabled(config.isContentCompressionEnabled()) .setHardCancellationEnabled(config.isHardCancellationEnabled()); } @@ -345,7 +342,7 @@ public class RequestConfig implements Cloneable { private Collection targetPreferredAuthSchemes; private Collection proxyPreferredAuthSchemes; private Timeout connectionRequestTimeout; - private Timeout connectionTimeout; + private Timeout connectTimeout; private boolean contentCompressionEnabled; private boolean hardCancellationEnabled; @@ -355,7 +352,7 @@ public class RequestConfig implements Cloneable { this.maxRedirects = 50; this.authenticationEnabled = true; this.connectionRequestTimeout = DEFAULT_CONNECTION_REQUEST_TIMEOUT; - this.connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; + this.connectTimeout = DEFAULT_CONNECT_TIMEOUT; this.contentCompressionEnabled = true; this.hardCancellationEnabled = true; } @@ -415,13 +412,13 @@ public class RequestConfig implements Cloneable { return this; } - public Builder setConnectionTimeout(final Timeout connectionTimeout) { - this.connectionTimeout = connectionTimeout; + public Builder setConnectTimeout(final Timeout connectTimeout) { + this.connectTimeout = connectTimeout; return this; } - public Builder setConnectionTimeout(final long connectTimeout, final TimeUnit timeUnit) { - this.connectionTimeout = Timeout.of(connectTimeout, timeUnit); + public Builder setConnectTimeout(final long connectTimeout, final TimeUnit timeUnit) { + this.connectTimeout = Timeout.of(connectTimeout, timeUnit); return this; } @@ -447,7 +444,7 @@ public class RequestConfig implements Cloneable { targetPreferredAuthSchemes, proxyPreferredAuthSchemes, connectionRequestTimeout != null ? connectionRequestTimeout : DEFAULT_CONNECTION_REQUEST_TIMEOUT, - connectionTimeout != null ? connectionTimeout : DEFAULT_CONNECTION_TIMEOUT, + connectTimeout != null ? connectTimeout : DEFAULT_CONNECT_TIMEOUT, contentCompressionEnabled, hardCancellationEnabled); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttp2AsyncExecRuntime.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttp2AsyncExecRuntime.java index c286acebf..311a063bc 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttp2AsyncExecRuntime.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttp2AsyncExecRuntime.java @@ -85,7 +85,7 @@ class InternalHttp2AsyncExecRuntime implements AsyncExecRuntime { if (sessionRef.get() == null) { final HttpHost target = route.getTargetHost(); final RequestConfig requestConfig = context.getRequestConfig(); - final Timeout connectTimeout = requestConfig.getConnectionTimeout(); + final Timeout connectTimeout = requestConfig.getConnectTimeout(); return Operations.cancellable(connPool.getSession( target, connectTimeout, @@ -169,7 +169,7 @@ class InternalHttp2AsyncExecRuntime implements AsyncExecRuntime { } final HttpHost target = endpoint.target; final RequestConfig requestConfig = context.getRequestConfig(); - final Timeout connectTimeout = requestConfig.getConnectionTimeout(); + final Timeout connectTimeout = requestConfig.getConnectTimeout(); return Operations.cancellable(connPool.getSession(target, connectTimeout, new FutureCallback() { @Override @@ -213,7 +213,7 @@ class InternalHttp2AsyncExecRuntime implements AsyncExecRuntime { } else { final HttpHost target = endpoint.target; final RequestConfig requestConfig = context.getRequestConfig(); - final Timeout connectTimeout = requestConfig.getConnectionTimeout(); + final Timeout connectTimeout = requestConfig.getConnectTimeout(); connPool.getSession(target, connectTimeout, new FutureCallback() { @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncExecRuntime.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncExecRuntime.java index 5e1c94d27..f0d0399d7 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncExecRuntime.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncExecRuntime.java @@ -192,7 +192,7 @@ class InternalHttpAsyncExecRuntime implements AsyncExecRuntime { return Operations.nonCancellable(); } final RequestConfig requestConfig = context.getRequestConfig(); - final Timeout connectTimeout = requestConfig.getConnectionTimeout(); + final Timeout connectTimeout = requestConfig.getConnectTimeout(); return Operations.cancellable(manager.connect( endpoint, connectionInitiator, @@ -224,7 +224,7 @@ class InternalHttpAsyncExecRuntime implements AsyncExecRuntime { public void upgradeTls(final HttpClientContext context) { final AsyncConnectionEndpoint endpoint = ensureValid(); final RequestConfig requestConfig = context.getRequestConfig(); - final Timeout connectTimeout = requestConfig.getConnectionTimeout(); + final Timeout connectTimeout = requestConfig.getConnectTimeout(); if (TimeValue.isPositive(connectTimeout)) { endpoint.setSocketTimeout(connectTimeout); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttp2AsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttp2AsyncClient.java index 3d6c68c15..7e7b82d57 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttp2AsyncClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttp2AsyncClient.java @@ -153,7 +153,7 @@ public final class MinimalHttp2AsyncClient extends AbstractMinimalHttpAsyncClien } else { requestConfig = clientContext.getRequestConfig(); } - final Timeout connectTimeout = requestConfig.getConnectionTimeout(); + final Timeout connectTimeout = requestConfig.getConnectTimeout(); final HttpHost target = new HttpHost(request.getAuthority(), request.getScheme()); final Future sessionFuture = connPool.getSession(target, connectTimeout, new FutureCallback() { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java index 1d46463bb..d0f5e0057 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java @@ -210,7 +210,7 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient final HttpClientContext clientContext = HttpClientContext.adapt(context); final RequestConfig requestConfig = clientContext.getRequestConfig(); final Timeout connectionRequestTimeout = requestConfig.getConnectionRequestTimeout(); - final Timeout connectTimeout = requestConfig.getConnectionTimeout(); + final Timeout connectTimeout = requestConfig.getConnectTimeout(); final BasicFuture future = new BasicFuture<>(callback); leaseEndpoint( host, @@ -264,7 +264,7 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient requestConfig = clientContext.getRequestConfig(); } final Timeout connectionRequestTimeout = requestConfig.getConnectionRequestTimeout(); - final Timeout connectTimeout = requestConfig.getConnectionTimeout(); + final Timeout connectTimeout = requestConfig.getConnectTimeout(); final HttpHost target = new HttpHost(request.getAuthority(), request.getScheme()); final Future leaseFuture = leaseEndpoint( diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalExecRuntime.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalExecRuntime.java index 02ac4f98e..596b464ba 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalExecRuntime.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalExecRuntime.java @@ -149,7 +149,7 @@ class InternalExecRuntime implements ExecRuntime, Cancellable { } } final RequestConfig requestConfig = context.getRequestConfig(); - final Timeout connectTimeout = requestConfig.getConnectionTimeout(); + final Timeout connectTimeout = requestConfig.getConnectTimeout(); manager.connect(endpoint, connectTimeout, context); } @@ -174,7 +174,7 @@ class InternalExecRuntime implements ExecRuntime, Cancellable { public void upgradeTls(final HttpClientContext context) throws IOException { final ConnectionEndpoint endpoint = ensureValid(); final RequestConfig requestConfig = context.getRequestConfig(); - final Timeout timeout = requestConfig.getConnectionTimeout(); + final Timeout timeout = requestConfig.getConnectTimeout(); if (TimeValue.isPositive(timeout)) { endpoint.setSocketTimeout(timeout); } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java b/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java index da7b7ca54..c4d92e25e 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java @@ -49,7 +49,7 @@ public class TestRequestConfig { @Test public void testDefaults() { final RequestConfig config = RequestConfig.DEFAULT; - Assert.assertEquals(Timeout.ofMinutes(3), config.getConnectionTimeout()); + Assert.assertEquals(Timeout.ofMinutes(3), config.getConnectTimeout()); Assert.assertEquals(Timeout.ofMinutes(3), config.getConnectionRequestTimeout()); Assert.assertEquals(false, config.isExpectContinueEnabled()); Assert.assertEquals(true, config.isAuthenticationEnabled()); @@ -66,7 +66,7 @@ public class TestRequestConfig { @Test public void testBuildAndCopy() throws Exception { final RequestConfig config0 = RequestConfig.custom() - .setConnectionTimeout(33, TimeUnit.MILLISECONDS) + .setConnectTimeout(33, TimeUnit.MILLISECONDS) .setConnectionRequestTimeout(44, TimeUnit.MILLISECONDS) .setExpectContinueEnabled(true) .setAuthenticationEnabled(false) @@ -80,7 +80,7 @@ public class TestRequestConfig { .setContentCompressionEnabled(false) .build(); final RequestConfig config = RequestConfig.copy(config0).build(); - Assert.assertEquals(TimeValue.ofMillis(33), config.getConnectionTimeout()); + Assert.assertEquals(TimeValue.ofMillis(33), config.getConnectTimeout()); Assert.assertEquals(TimeValue.ofMillis(44), config.getConnectionRequestTimeout()); Assert.assertEquals(true, config.isExpectContinueEnabled()); Assert.assertEquals(false, config.isAuthenticationEnabled()); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalExecRuntime.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalExecRuntime.java index c7f03c45d..7cc3892bd 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalExecRuntime.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalExecRuntime.java @@ -82,8 +82,8 @@ public class TestInternalExecRuntime { public void testAcquireEndpoint() throws Exception { final HttpClientContext context = HttpClientContext.create(); final RequestConfig config = RequestConfig.custom() - .setConnectionTimeout(123, TimeUnit.MILLISECONDS) .setConnectionRequestTimeout(345, TimeUnit.MILLISECONDS) + .setConnectTimeout(123, TimeUnit.MILLISECONDS) .build(); context.setRequestConfig(config); final HttpRoute route = new HttpRoute(new HttpHost("host", 80)); @@ -248,8 +248,8 @@ public class TestInternalExecRuntime { public void testConnectEndpoint() throws Exception { final HttpClientContext context = HttpClientContext.create(); final RequestConfig config = RequestConfig.custom() - .setConnectionTimeout(123, TimeUnit.MILLISECONDS) .setConnectionRequestTimeout(345, TimeUnit.MILLISECONDS) + .setConnectTimeout(123, TimeUnit.MILLISECONDS) .build(); context.setRequestConfig(config);