From 2dde000475d60b07bfe17f6233f2284aa03a5cc2 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Fri, 6 Apr 2018 16:35:17 +0200 Subject: [PATCH] Document socket timeout config limitations for HttpClient This commit documents the difference between configuring the socket timeout on the `RequestConfig` and on the `SocketConfig`. The first one does not affect timeouts when establishing an SSL connection or sending a CONNECT request to a proxy. For these use cases, it is required to configure `SocketConfig` on the `HttpClient` instance directly. Issue: SPR-16697 --- ...HttpComponentsClientHttpRequestFactory.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java index 095b10a853..5608ebb400 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java @@ -69,7 +69,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest /** * Create a new instance of the {@code HttpComponentsClientHttpRequestFactory} - * with a default {@link HttpClient}. + * with a default {@link HttpClient} based on system properties. */ public HttpComponentsClientHttpRequestFactory() { this.httpClient = HttpClients.createSystem(); @@ -103,12 +103,17 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest } /** - * Set the connection timeout for the underlying HttpClient. + * Set the connection timeout for the underlying {@link RequestConfig}. * A timeout value of 0 specifies an infinite timeout. *

Additional properties can be configured by specifying a * {@link RequestConfig} instance on a custom {@link HttpClient}. + *

This options does not affect connection timeouts for SSL + * handshakes or CONNECT requests; for that, it is required to + * use the {@link org.apache.http.config.SocketConfig} on the + * {@link HttpClient} itself. * @param timeout the timeout value in milliseconds * @see RequestConfig#getConnectTimeout() + * @see org.apache.http.config.SocketConfig#getSoTimeout */ public void setConnectTimeout(int timeout) { Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value"); @@ -116,8 +121,8 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest } /** - * Set the timeout in milliseconds used when requesting a connection from the connection - * manager using the underlying HttpClient. + * Set the timeout in milliseconds used when requesting a connection + * from the connection manager using the underlying {@link RequestConfig}. * A timeout value of 0 specifies an infinite timeout. *

Additional properties can be configured by specifying a * {@link RequestConfig} instance on a custom {@link HttpClient}. @@ -125,11 +130,12 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest * @see RequestConfig#getConnectionRequestTimeout() */ public void setConnectionRequestTimeout(int connectionRequestTimeout) { - this.requestConfig = requestConfigBuilder().setConnectionRequestTimeout(connectionRequestTimeout).build(); + this.requestConfig = requestConfigBuilder() + .setConnectionRequestTimeout(connectionRequestTimeout).build(); } /** - * Set the socket read timeout for the underlying HttpClient. + * Set the socket read timeout for the underlying {@link RequestConfig}. * A timeout value of 0 specifies an infinite timeout. *

Additional properties can be configured by specifying a * {@link RequestConfig} instance on a custom {@link HttpClient}.