23
23
import java .util .Map ;
24
24
import java .util .Set ;
25
25
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 ;
36
41
37
42
import org .springframework .boot .web .client .RestTemplateBuilder ;
38
43
import org .springframework .boot .web .client .RootUriTemplateHandler ;
@@ -997,8 +1002,8 @@ protected static class CustomHttpComponentsClientHttpRequestFactory extends Http
997
1002
998
1003
public CustomHttpComponentsClientHttpRequestFactory (HttpClientOption [] httpClientOptions ) {
999
1004
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 );
1002
1007
this .enableRedirects = options .contains (HttpClientOption .ENABLE_REDIRECTS );
1003
1008
if (options .contains (HttpClientOption .SSL )) {
1004
1009
setHttpClient (createSslHttpClient ());
@@ -1007,9 +1012,15 @@ public CustomHttpComponentsClientHttpRequestFactory(HttpClientOption[] httpClien
1007
1012
1008
1013
private HttpClient createSslHttpClient () {
1009
1014
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 ();
1013
1024
}
1014
1025
catch (Exception ex ) {
1015
1026
throw new IllegalStateException ("Unable to create SSL HttpClient" , ex );
@@ -1024,9 +1035,8 @@ protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
1024
1035
}
1025
1036
1026
1037
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 ();
1030
1040
}
1031
1041
1032
1042
}
0 commit comments