2323import java .util .Map ;
2424import java .util .Set ;
2525
26- import org .apache .http .client .HttpClient ;
27- import org .apache .http .client .config .CookieSpecs ;
28- import org .apache .http .client .config .RequestConfig ;
29- import org .apache .http .client .config .RequestConfig .Builder ;
30- import org .apache .http .client .protocol .HttpClientContext ;
31- import org .apache .http .conn .ssl .SSLConnectionSocketFactory ;
32- import org .apache .http .conn .ssl .TrustSelfSignedStrategy ;
33- import org .apache .http .impl .client .HttpClients ;
34- import org .apache .http .protocol .HttpContext ;
35- import org .apache .http .ssl .SSLContextBuilder ;
26+ import javax .net .ssl .SSLContext ;
27+
28+ import org .apache .hc .client5 .http .classic .HttpClient ;
29+ import org .apache .hc .client5 .http .config .RequestConfig ;
30+ import org .apache .hc .client5 .http .cookie .StandardCookieSpec ;
31+ import org .apache .hc .client5 .http .impl .classic .HttpClients ;
32+ import org .apache .hc .client5 .http .impl .io .PoolingHttpClientConnectionManager ;
33+ import org .apache .hc .client5 .http .impl .io .PoolingHttpClientConnectionManagerBuilder ;
34+ import org .apache .hc .client5 .http .protocol .HttpClientContext ;
35+ import org .apache .hc .client5 .http .ssl .SSLConnectionSocketFactory ;
36+ import org .apache .hc .client5 .http .ssl .SSLConnectionSocketFactoryBuilder ;
37+ import org .apache .hc .client5 .http .ssl .TrustSelfSignedStrategy ;
38+ import org .apache .hc .core5 .http .protocol .HttpContext ;
39+ import org .apache .hc .core5 .http .ssl .TLS ;
40+ import org .apache .hc .core5 .ssl .SSLContextBuilder ;
3641
3742import org .springframework .boot .web .client .RestTemplateBuilder ;
3843import org .springframework .boot .web .client .RootUriTemplateHandler ;
@@ -997,8 +1002,8 @@ protected static class CustomHttpComponentsClientHttpRequestFactory extends Http
9971002
9981003 public CustomHttpComponentsClientHttpRequestFactory (HttpClientOption [] httpClientOptions ) {
9991004 Set <HttpClientOption > options = new HashSet <>(Arrays .asList (httpClientOptions ));
1000- this .cookieSpec = (options .contains (HttpClientOption .ENABLE_COOKIES ) ? CookieSpecs . STANDARD
1001- : CookieSpecs . IGNORE_COOKIES );
1005+ this .cookieSpec = (options .contains (HttpClientOption .ENABLE_COOKIES ) ? StandardCookieSpec . STRICT
1006+ : StandardCookieSpec . IGNORE );
10021007 this .enableRedirects = options .contains (HttpClientOption .ENABLE_REDIRECTS );
10031008 if (options .contains (HttpClientOption .SSL )) {
10041009 setHttpClient (createSslHttpClient ());
@@ -1007,9 +1012,15 @@ public CustomHttpComponentsClientHttpRequestFactory(HttpClientOption[] httpClien
10071012
10081013 private HttpClient createSslHttpClient () {
10091014 try {
1010- SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory (
1011- new SSLContextBuilder ().loadTrustMaterial (null , new TrustSelfSignedStrategy ()).build ());
1012- return HttpClients .custom ().setSSLSocketFactory (socketFactory ).build ();
1015+ SSLContext sslContext = new SSLContextBuilder ().loadTrustMaterial (null , new TrustSelfSignedStrategy ())
1016+ .build ();
1017+ SSLConnectionSocketFactory socketFactory = SSLConnectionSocketFactoryBuilder .create ()
1018+ .setSslContext (sslContext ).setTlsVersions (TLS .V_1_3 , TLS .V_1_2 ).build ();
1019+ PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder
1020+ .create ().setSSLSocketFactory (socketFactory ).build ();
1021+
1022+ return HttpClients .custom ().setConnectionManager (connectionManager )
1023+ .setDefaultRequestConfig (getRequestConfig ()).build ();
10131024 }
10141025 catch (Exception ex ) {
10151026 throw new IllegalStateException ("Unable to create SSL HttpClient" , ex );
@@ -1024,9 +1035,8 @@ protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
10241035 }
10251036
10261037 protected RequestConfig getRequestConfig () {
1027- Builder builder = RequestConfig .custom ().setCookieSpec (this .cookieSpec ).setAuthenticationEnabled (false )
1028- .setRedirectsEnabled (this .enableRedirects );
1029- return builder .build ();
1038+ return RequestConfig .custom ().setCookieSpec (this .cookieSpec ).setAuthenticationEnabled (false )
1039+ .setRedirectsEnabled (this .enableRedirects ).build ();
10301040 }
10311041
10321042 }
0 commit comments