RestTemplate HTTPclient 开始显示带有 poolingConnectionManager bean 的 SSl 握手异常。
下面是我的代码-
@Bean
public CloseableHttpClient sslHttpClient() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
return HttpClients.custom()
.setDefaultRequestConfig(getRequestConfig())
//on uncommenting this we start getting SSL handshake Exception
//.setConnectionManager(poolingConnectionManager())
.setSSLSocketFactory(csf())
.build();
}
private RequestConfig getRequestConfig(){
return RequestConfig.custom()
.setConnectTimeout(connectionTimeout)
.setConnectionRequestTimeout(connectionTimeout)
.setSocketTimeout(socketTimeout)
.build();
}
private SSLConnectionSocketFactory csf() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException{
TrustStrategy acceptingTrustStrategy = (x509Certificates, s) -> true;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
return new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
}
@Bean
public PoolingHttpClientConnectionManager poolingConnectionManager() {
PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager();
poolingConnectionManager.setMaxTotal(restTotalConnections);
poolingConnectionManager.setDefaultMaxPerRoute(restDefaultConnectionsPerRoute);
return poolingConnectionManager;
}
我无法使用自定义 SSL 连接套接字工厂设置收集池属性。