Renamed RequestConfig#connectionTimeout to RequestConfig#connectTimeout

This commit is contained in:
Oleg Kalnichevski 2018-10-22 15:14:04 +02:00
parent e92c75be8a
commit b74cb12d44
21 changed files with 57 additions and 59 deletions

View File

@ -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.

View File

@ -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,

View File

@ -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;
}

View File

@ -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);
}

View File

@ -95,8 +95,8 @@ public class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest<CloseableH
protected void before() throws Throwable {
clientBuilder = HttpAsyncClientBuilder.create()
.setDefaultRequestConfig(RequestConfig.custom()
.setConnectionTimeout(TIMEOUT)
.setConnectionRequestTimeout(TIMEOUT)
.setConnectTimeout(TIMEOUT)
.build())
.setConnectionManager(connManager);
}

View File

@ -116,8 +116,8 @@ public class TestHttp1AsyncRedirects extends AbstractHttpAsyncRedirectsTest<Clos
protected void before() throws Throwable {
clientBuilder = HttpAsyncClientBuilder.create()
.setDefaultRequestConfig(RequestConfig.custom()
.setConnectionTimeout(TIMEOUT)
.setConnectionRequestTimeout(TIMEOUT)
.setConnectTimeout(TIMEOUT)
.build())
.setConnectionManager(connManager);
}

View File

@ -90,7 +90,7 @@ public class TestHttp1AsyncStatefulConnManagement extends AbstractIntegrationTes
protected void before() throws Throwable {
clientBuilder = HttpAsyncClientBuilder.create()
.setDefaultRequestConfig(RequestConfig.custom()
.setConnectionTimeout(TIMEOUT)
.setConnectTimeout(TIMEOUT)
.setConnectionRequestTimeout(TIMEOUT)
.build())
.setConnectionManager(connManager);

View File

@ -106,8 +106,8 @@ public class TestHttp1ClientAuthentication extends AbstractHttpAsyncClientAuthen
protected void before() throws Throwable {
clientBuilder = HttpAsyncClientBuilder.create()
.setDefaultRequestConfig(RequestConfig.custom()
.setConnectionTimeout(TIMEOUT)
.setConnectionRequestTimeout(TIMEOUT)
.setConnectTimeout(TIMEOUT)
.build())
.setConnectionManager(connManager);
}

View File

@ -62,8 +62,8 @@ public class TestHttp2Async extends AbstractHttpAsyncFundamentalsTest<CloseableH
protected void before() throws Throwable {
clientBuilder = Http2AsyncClientBuilder.create()
.setDefaultRequestConfig(RequestConfig.custom()
.setConnectionTimeout(TIMEOUT)
.setConnectionRequestTimeout(TIMEOUT)
.setConnectTimeout(TIMEOUT)
.build())
.setTlsStrategy(new BasicClientTlsStrategy(SSLTestContexts.createClientSSLContext()));
}

View File

@ -65,8 +65,8 @@ public class TestHttp2AsyncRedirect extends AbstractHttpAsyncRedirectsTest<Close
protected void before() throws Throwable {
clientBuilder = Http2AsyncClientBuilder.create()
.setDefaultRequestConfig(RequestConfig.custom()
.setConnectionTimeout(TIMEOUT)
.setConnectionRequestTimeout(TIMEOUT)
.setConnectTimeout(TIMEOUT)
.build())
.setTlsStrategy(new DefaultClientTlsStrategy(SSLTestContexts.createClientSSLContext()));
}

View File

@ -66,8 +66,8 @@ public class TestHttp2ClientAuthentication extends AbstractHttpAsyncClientAuthen
protected void before() throws Throwable {
clientBuilder = Http2AsyncClientBuilder.create()
.setDefaultRequestConfig(RequestConfig.custom()
.setConnectionTimeout(TIMEOUT)
.setConnectionRequestTimeout(TIMEOUT)
.setConnectTimeout(TIMEOUT)
.build())
.setTlsStrategy(new DefaultClientTlsStrategy(SSLTestContexts.createClientSSLContext()));
}

View File

@ -111,9 +111,9 @@ public abstract class LocalServerTestBase {
.build());
clientBuilder = HttpClientBuilder.create()
.setDefaultRequestConfig(RequestConfig.custom()
.setConnectionTimeout(TIMEOUT)
.setConnectionRequestTimeout(TIMEOUT)
.build())
.setConnectionRequestTimeout(TIMEOUT)
.setConnectTimeout(TIMEOUT)
.build())
.setConnectionManager(connManager);
}

View File

@ -212,8 +212,8 @@ public class ClientConfiguration {
// Request configuration can be overridden at the request level.
// They will take precedence over the one set at the client level.
final RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig)
.setConnectionTimeout(Timeout.ofSeconds(5))
.setConnectionRequestTimeout(Timeout.ofSeconds(5))
.setConnectTimeout(Timeout.ofSeconds(5))
.setProxy(new HttpHost("myotherproxy", 8080))
.build();
httpget.setConfig(requestConfig);

View File

@ -42,7 +42,7 @@ import org.apache.hc.core5.util.Timeout;
public class RequestConfig implements Cloneable {
private static final Timeout DEFAULT_CONNECTION_REQUEST_TIMEOUT = Timeout.ofMinutes(3);
private static final Timeout DEFAULT_CONNECTION_TIMEOUT = Timeout.ofMinutes(3);
private static final Timeout DEFAULT_CONNECT_TIMEOUT = Timeout.ofMinutes(3);
public static final RequestConfig DEFAULT = new Builder().build();
@ -56,7 +56,7 @@ public class RequestConfig implements Cloneable {
private final Collection<String> targetPreferredAuthSchemes;
private final Collection<String> 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<String> targetPreferredAuthSchemes,
final Collection<String> 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.
* <p>
* A timeout value of zero is interpreted as an infinite timeout.
* A negative value is interpreted as undefined (system default).
* </p>
* <p>
* 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).
* <p>
* 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 {
* <p>
* Default: 3 minutes
* </p>
*
* @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<String> targetPreferredAuthSchemes;
private Collection<String> 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);
}

View File

@ -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<IOSession>() {
@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<IOSession>() {
@Override

View File

@ -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);
}

View File

@ -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<IOSession> sessionFuture = connPool.getSession(target, connectTimeout, new FutureCallback<IOSession>() {

View File

@ -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<AsyncClientEndpoint> 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<AsyncConnectionEndpoint> leaseFuture = leaseEndpoint(

View File

@ -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);
}

View File

@ -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());

View File

@ -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);