55import org .apache .hc .client5 .http .impl .io .PoolingHttpClientConnectionManager ;
66import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
77import org .apache .hc .client5 .http .impl .classic .HttpClients ;
8- import org .apache .hc .client5 .http .socket .ConnectionSocketFactory ;
9- import org .apache .hc .client5 .http .socket .PlainConnectionSocketFactory ;
10- import org .apache .hc .client5 .http .ssl .SSLConnectionSocketFactory ;
11- import org .apache .hc .client5 .http .ssl .TrustSelfSignedStrategy ;
8+ import org .apache .hc .client5 .http .impl .io .PoolingHttpClientConnectionManagerBuilder ;
129import org .apache .hc .core5 .http .HeaderElement ;
13- import org .apache .hc .core5 .http .config .Registry ;
14- import org .apache .hc .core5 .http .config .RegistryBuilder ;
1510import org .apache .hc .core5 .http .message .BasicHeaderElementIterator ;
16- import org .apache .hc .core5 .ssl .SSLContextBuilder ;
1711import org .apache .hc .core5 .util .TimeValue ;
1812import org .apache .hc .core5 .util .Timeout ;
1913import org .apache .hc .core5 .http .HttpHeaders ;
2317import org .springframework .context .annotation .Configuration ;
2418import org .springframework .scheduling .annotation .Scheduled ;
2519
26- import java .security .KeyManagementException ;
27- import java .security .KeyStoreException ;
28- import java .security .NoSuchAlgorithmException ;
29-
3020@ Configuration
3121public class HttpClientConfig {
3222
@@ -43,35 +33,12 @@ public class HttpClientConfig {
4333 = Integer .getInteger ("DEFAULT_KEEP_ALIVE_TIME_MILLIS" , DEFAULT_KEEP_ALIVE_TIME_MILLIS );
4434 //@formatter:on
4535
36+
4637 @ Bean
4738 public PoolingHttpClientConnectionManager poolingConnectionManager () {
48- SSLContextBuilder builder = new SSLContextBuilder ();
49- try {
50- builder .loadTrustMaterial (null , new TrustSelfSignedStrategy ());
51- }
52- catch (NoSuchAlgorithmException | KeyStoreException e ) {
53- LOGGER .error ("Pooling Connection Manager Initialisation failure because of "
54- + e .getMessage (), e );
55- }
56-
57- SSLConnectionSocketFactory sslsf = null ;
58- try {
59- sslsf = new SSLConnectionSocketFactory (builder .build ());
60- }
61- catch (KeyManagementException | NoSuchAlgorithmException e ) {
62- LOGGER .error ("Pooling Connection Manager Initialisation failure because of "
63- + e .getMessage (), e );
64- }
65-
66- Registry <ConnectionSocketFactory > socketFactoryRegistry = RegistryBuilder
67- .<ConnectionSocketFactory > create ().register ("https" , sslsf )
68- .register ("http" , new PlainConnectionSocketFactory ())
39+ return PoolingHttpClientConnectionManagerBuilder .create ()
40+ .setMaxConnTotal (MAX_TOTAL_CONNECTIONS )
6941 .build ();
70-
71- PoolingHttpClientConnectionManager poolingConnectionManager =
72- new PoolingHttpClientConnectionManager (socketFactoryRegistry );
73- poolingConnectionManager .setMaxTotal (MAX_TOTAL_CONNECTIONS );
74- return poolingConnectionManager ;
7542 }
7643
7744 @ Bean
0 commit comments