Skip to content

Commit ebd734b

Browse files
spencergibbmp911de
authored andcommitted
Updates to Apache HTTP Client 5.
Fixes gh-727, see gh-728
1 parent 87aa6f3 commit ebd734b

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

spring-vault-core/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@
134134
<!-- HTTP clients -->
135135

136136
<dependency>
137-
<groupId>org.apache.httpcomponents</groupId>
138-
<artifactId>httpclient</artifactId>
137+
<groupId>org.apache.httpcomponents.client5</groupId>
138+
<artifactId>httpclient5</artifactId>
139139
<optional>true</optional>
140140
</dependency>
141141

142142
<dependency>
143-
<groupId>org.apache.httpcomponents</groupId>
144-
<artifactId>httpcore</artifactId>
143+
<groupId>org.apache.httpcomponents.core5</groupId>
144+
<artifactId>httpcore5</artifactId>
145145
<optional>true</optional>
146146
</dependency>
147147

spring-vault-core/src/main/java/org/springframework/vault/client/ClientHttpRequestFactoryFactory.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@
4747
import okhttp3.OkHttpClient.Builder;
4848
import org.apache.commons.logging.Log;
4949
import org.apache.commons.logging.LogFactory;
50-
import org.apache.http.client.config.RequestConfig;
51-
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
52-
import org.apache.http.impl.client.HttpClientBuilder;
53-
import org.apache.http.impl.client.HttpClients;
54-
import org.apache.http.impl.client.LaxRedirectStrategy;
55-
import org.apache.http.impl.conn.DefaultSchemePortResolver;
56-
import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
50+
import org.apache.hc.client5.http.config.RequestConfig;
51+
import org.apache.hc.client5.http.impl.DefaultSchemePortResolver;
52+
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
53+
import org.apache.hc.client5.http.impl.classic.HttpClients;
54+
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
55+
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
56+
import org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner;
57+
import org.apache.hc.client5.http.ssl.HttpsSupport;
58+
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
59+
import org.apache.hc.core5.http.io.SocketConfig;
5760

5861
import org.springframework.http.client.ClientHttpRequestFactory;
5962
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
@@ -303,22 +306,29 @@ static ClientHttpRequestFactory usingHttpComponents(ClientOptions options, SslCo
303306
}
304307

305308
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext,
306-
enabledProtocols, enabledCipherSuites, SSLConnectionSocketFactory.getDefaultHostnameVerifier());
307-
httpClientBuilder.setSSLSocketFactory(sslSocketFactory);
308-
httpClientBuilder.setSSLContext(sslContext);
309+
enabledProtocols, enabledCipherSuites, HttpsSupport.getDefaultHostnameVerifier());
310+
PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder //
311+
.create().setSSLSocketFactory(sslSocketFactory) //
312+
.setDefaultSocketConfig(SocketConfig.custom() //
313+
.setSoTimeout(Math.toIntExact(options.getReadTimeout().toMillis()),
314+
TimeUnit.MILLISECONDS)
315+
.build()) //
316+
.build(); //
317+
httpClientBuilder.setConnectionManager(connectionManager);
309318
}
310319

311320
RequestConfig requestConfig = RequestConfig.custom()
312321
//
313-
.setConnectTimeout(Math.toIntExact(options.getConnectionTimeout().toMillis())) //
314-
.setSocketTimeout(Math.toIntExact(options.getReadTimeout().toMillis())) //
322+
.setConnectTimeout(Math.toIntExact(options.getConnectionTimeout().toMillis()),
323+
TimeUnit.MILLISECONDS) //
315324
.setAuthenticationEnabled(true) //
316325
.build();
317326

318327
httpClientBuilder.setDefaultRequestConfig(requestConfig);
319328

320329
// Support redirects
321-
httpClientBuilder.setRedirectStrategy(new LaxRedirectStrategy());
330+
// TODO: DefaultRedirectStrategy doesn't take method into account
331+
// httpClientBuilder.setRedirectStrategy(new LaxRedirectStrategy());
322332

323333
return new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build());
324334
}

spring-vault-dependencies/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
</licenses>
5858

5959
<properties>
60-
<httpclient.version>4.5.13</httpclient.version>
61-
<httpcore.version>4.4.15</httpcore.version>
60+
<httpclient.version>5.1.3</httpclient.version>
61+
<httpcore.version>5.1.4</httpcore.version>
6262
<jetty-reactive-httpclient.version>3.0.6</jetty-reactive-httpclient.version>
6363
<netty.version>4.1.79.Final</netty.version>
6464
<okhttp3.version>3.14.9</okhttp3.version>
@@ -89,8 +89,8 @@
8989

9090
<!-- HTTP Client Libraries -->
9191
<dependency>
92-
<groupId>org.apache.httpcomponents</groupId>
93-
<artifactId>httpclient</artifactId>
92+
<groupId>org.apache.httpcomponents.client5</groupId>
93+
<artifactId>httpclient5</artifactId>
9494
<version>${httpclient.version}</version>
9595
<optional>true</optional>
9696
<exclusions>
@@ -102,8 +102,8 @@
102102
</dependency>
103103

104104
<dependency>
105-
<groupId>org.apache.httpcomponents</groupId>
106-
<artifactId>httpcore</artifactId>
105+
<groupId>org.apache.httpcomponents.core5</groupId>
106+
<artifactId>httpcore5</artifactId>
107107
<version>${httpcore.version}</version>
108108
<optional>true</optional>
109109
</dependency>

0 commit comments

Comments
 (0)