Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpClients.custom().setSSLSocketFactory() method not found

I have used

implementation group: 'org.apache.httpcomponents.client5', name: 'httpclient5', version: '5.2'

setSSLSocketFactory() method doesn't exist for this dependency

like image 544
Ayshan Rzayeva Avatar asked Sep 12 '25 05:09

Ayshan Rzayeva


1 Answers

It seems that the SSLSocketFactory should now be set on the ConnectionManagerBuilder

See the official documentation here with an example: Migration to Apache HttpClient 5.x classic APIs

Sample code:

PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
      .setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create()
              .setSslContext(SSLContexts.createSystemDefault())
              .setTlsVersions(TLS.V_1_3)
              .build())
      .setDefaultSocketConfig(SocketConfig.custom()
              .setSoTimeout(Timeout.ofMinutes(1))
              .build())
      .setPoolConcurrencyPolicy(PoolConcurrencyPolicy.STRICT)
      .setConnPoolPolicy(PoolReusePolicy.LIFO)
      .setDefaultConnectionConfig(ConnectionConfig.custom()
              .setSocketTimeout(Timeout.ofMinutes(1))
              .setConnectTimeout(Timeout.ofMinutes(1))
              .setTimeToLive(TimeValue.ofMinutes(10))
              .build())
      .build();
HttpClient httpClient = HttpClientBuilder
                        .create()
                        .setConnectionManager(connectionManager)
                        .build();

I did it and it is working fine

like image 152
Khalil Bouzekri Avatar answered Sep 14 '25 20:09

Khalil Bouzekri