I have upgraded from apache http client 5.3.x to 5.4.x.
The below code works fine
var sslContext = SSLContexts.custom() .loadTrustMaterial(null, TrustAllStrategy.INSTANCE) .build(); SSLConnectionSocketFactory sslConnSocketFactory = SSLConnectionSocketFactoryBuilder.create() .setHostnameVerifier(NoopHostnameVerifier.INSTANCE) .setSslContext(sslContext) .build(); var connectionManager = PoolingHttpClientConnectionManagerBuilder.create() .setSSLSocketFactory(sslConnSocketFactory) .build(); CloseableHttpClient client = HttpClientBuilder.create() .setConnectionManager(connectionManager) .build(); HttpGet httpGet = new HttpGet("https://mms.nw.ru/"); HttpHost host = RoutingSupport.determineHost(httpGet); ClassicHttpResponse response = client.executeOpen(host, httpGet, null); Assertions.assertEquals(200, response.getCode()); But the SSLConnectionSocketFactory class and setSSLSocketFactory method of PoolingHttpClientConnectionManagerBuilder became deprecated.
I have changed the code to
var sslContext = SSLContexts.custom() .loadTrustMaterial(null, TrustAllStrategy.INSTANCE) .build(); var tlsStrategy = ClientTlsStrategyBuilder.create() .setSslContext(sslContext) .setHostnameVerifier(NoopHostnameVerifier.INSTANCE) .build(); var connectionManager = PoolingHttpClientConnectionManagerBuilder.create() .setTlsSocketStrategy((TlsSocketStrategy) tlsStrategy) .build(); CloseableHttpClient client = HttpClientBuilder.create() .setConnectionManager(connectionManager) .build(); HttpGet httpGet = new HttpGet("https://mms.nw.ru/"); HttpHost host = RoutingSupport.determineHost(httpGet); ClassicHttpResponse response = client.executeOpen(host, httpGet, null); Assertions.assertEquals(200, response.getCode()); It throws javax.net.ssl.SSLHandshakeException: No name matching mms.nw.ru found cause java.security.cert.CertificateException: No name matching mms.nw.ru found.
What is wrong ?
ConnectionManagerBuilder.setSSLSocketFactorymethod. Thanks for suggestion.