联系Hoverfly 支持后,我的工作如下
CloseableHttpClient httpClient = HttpClients.custom()
//.setConnectionManager(poolingConnectionManager) //this causes TLS errors so I commented it out until this final issue is solved.
.setRetryHandler(new DefaultHttpRequestRetryHandler(2, true))
.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy())
.setDefaultRequestConfig(requestConfig)
.setDefaultCredentialsProvider(credsProvider)
.setDefaultHeaders(headers)
.useSystemProperties()
.build();
我在使用时仍然有问题setConnectionManager()
(它再次导致 TLS 错误),这些是我需要为新创建的添加的设置HttpCleint
PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(30, TimeUnit.SECONDS);
poolingConnectionManager.setMaxTotal(1000);
poolingConnectionManager.setDefaultMaxPerRoute(1000);
更新
已解决的问题,在搜索和联系 hoverfly 支持后我发现了类似的问题,我解决了它使用
private PoolingHttpClientConnectionManager getPoolingHttpClientConnectionManager() {
SSLConnectionSocketFactory sslsocketFactory = null;
try {
sslsocketFactory = new SSLConnectionSocketFactory(SSLContext.getDefault(), new DefaultHostnameVerifier());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", sslsocketFactory)
.register("http", PlainConnectionSocketFactory.INSTANCE)
.build();
PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
poolingConnectionManager.setMaxTotal(1000);
poolingConnectionManager.setDefaultMaxPerRoute(1000);
// Used these settings instead of constructor parameters (long timeToLive, TimeUnit timeUnit)
poolingConnectionManager.closeIdleConnections(30, TimeUnit.SECONDS);
return poolingConnectionManager;
}
我希望 Hoverfly 可以代替所有这些麻烦。