After contacting Hoverfly support I had it work as follows
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();
I still have a problem on using setConnectionManager()
(it causes TLS errors again), these are the settings I need to add for the newly created HttpCleint
PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(30, TimeUnit.SECONDS);
poolingConnectionManager.setMaxTotal(1000);
poolingConnectionManager.setDefaultMaxPerRoute(1000);
UPDATE
Solved issue, after searching and contacting hoverfly support I found similar problem, sol I solved it using
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;
}
I wish Hoverfly could do all this hassle instead.