9
9
10
10
import javax .net .ssl .SSLContext ;
11
11
12
- import org .apache .http .conn .ssl .SSLConnectionSocketFactory ;
13
- import org .apache .http .impl .client .CloseableHttpClient ;
14
- import org .apache .http .impl .client .HttpClients ;
15
- import org .apache .http .ssl .SSLContextBuilder ;
12
+ import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
13
+ import org .apache .hc .client5 .http .impl .classic .HttpClients ;
14
+ import org .apache .hc .client5 .http .impl .io .PoolingHttpClientConnectionManagerBuilder ;
15
+ import org .apache .hc .client5 .http .io .HttpClientConnectionManager ;
16
+ import org .apache .hc .client5 .http .ssl .SSLConnectionSocketFactory ;
17
+ import org .apache .hc .core5 .ssl .SSLContextBuilder ;
16
18
import org .springframework .beans .factory .annotation .Value ;
17
19
import org .springframework .context .annotation .Bean ;
18
20
import org .springframework .context .annotation .Configuration ;
@@ -38,7 +40,11 @@ public RestTemplate restTemplate() throws KeyManagementException, NoSuchAlgorith
38
40
.loadTrustMaterial (trustStore .getURL (), trustStorePassword .toCharArray ()).build ();
39
41
SSLConnectionSocketFactory sslConFactory = new SSLConnectionSocketFactory (sslContext );
40
42
41
- CloseableHttpClient httpClient = HttpClients .custom ().setSSLSocketFactory (sslConFactory ).build ();
43
+ final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder .create ()
44
+ .setSSLSocketFactory (sslConFactory )
45
+ .build ();
46
+
47
+ CloseableHttpClient httpClient = HttpClients .custom ().setConnectionManager (cm ).build ();
42
48
ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory (httpClient );
43
49
return new RestTemplate (requestFactory );
44
50
}
0 commit comments