Skip to content

Commit d65de19

Browse files
committed
Deprecate setConnectTimeout on HttpComponents client factory
Prior to this commit, the `HttpComponentsClientHttpRequestFactory` would set the connection timeout on the request configuration. This has been deprecated by the client itself and this value should be set while creating the client on the connection manager itself. This commit deprecates this method, as there is no way for the factory to set this value anymore. Closes gh-35748
1 parent 16822c2 commit d65de19

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import org.apache.hc.client5.http.classic.methods.HttpPut;
3434
import org.apache.hc.client5.http.classic.methods.HttpTrace;
3535
import org.apache.hc.client5.http.config.Configurable;
36+
import org.apache.hc.client5.http.config.ConnectionConfig;
3637
import org.apache.hc.client5.http.config.RequestConfig;
3738
import org.apache.hc.client5.http.impl.classic.HttpClients;
39+
import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager;
3840
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
3941
import org.apache.hc.client5.http.protocol.HttpClientContext;
4042
import org.apache.hc.core5.http.ClassicHttpRequest;
@@ -123,7 +125,12 @@ public HttpClient getHttpClient() {
123125
* @param connectTimeout the timeout value in milliseconds
124126
* @see RequestConfig#getConnectTimeout()
125127
* @see SocketConfig#getSoTimeout
128+
* @deprecated as of 6.2.13 in favor of setting it on
129+
* {@link BasicHttpClientConnectionManager#setConnectionConfig(ConnectionConfig) the connection configuration}
130+
* for the {@link org.apache.hc.client5.http.impl.classic.HttpClientBuilder#setConnectionManager(HttpClientConnectionManager)
131+
* connection manager}.
126132
*/
133+
@Deprecated(since = "6.2.13", forRemoval = true)
127134
public void setConnectTimeout(int connectTimeout) {
128135
Assert.isTrue(connectTimeout >= 0, "Timeout must be a non-negative value");
129136
this.connectTimeout = connectTimeout;
@@ -142,7 +149,12 @@ public void setConnectTimeout(int connectTimeout) {
142149
* @since 6.1
143150
* @see RequestConfig#getConnectTimeout()
144151
* @see SocketConfig#getSoTimeout
152+
* @deprecated as of 6.2.13 in favor of setting it on
153+
* {@link BasicHttpClientConnectionManager#setConnectionConfig(ConnectionConfig) the connection configuration}
154+
* for the {@link org.apache.hc.client5.http.impl.classic.HttpClientBuilder#setConnectionManager(HttpClientConnectionManager)
155+
* connection manager}.
145156
*/
157+
@Deprecated(since = "6.2.13", forRemoval = true)
146158
public void setConnectTimeout(Duration connectTimeout) {
147159
Assert.notNull(connectTimeout, "ConnectTimeout must not be null");
148160
Assert.isTrue(!connectTimeout.isNegative(), "Timeout must be a non-negative value");

spring-web/src/test/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void httpMethods() throws Exception {
6161
}
6262

6363
@Test
64-
@SuppressWarnings("deprecation")
64+
@SuppressWarnings("removal")
6565
void assertCustomConfig() throws Exception {
6666
HttpClient httpClient = HttpClientBuilder.create().build();
6767
HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(httpClient);
@@ -103,7 +103,7 @@ void defaultSettingsOfHttpClientMergedOnExecutorCustomization() throws Exception
103103
}
104104

105105
@Test
106-
@SuppressWarnings("deprecation")
106+
@SuppressWarnings("removal")
107107
void localSettingsOverrideClientDefaultSettings() throws Exception {
108108
RequestConfig defaultConfig = RequestConfig.custom()
109109
.setConnectTimeout(1234, MILLISECONDS)

0 commit comments

Comments
 (0)