private ApacheHttpClientToMockServerResponseMapper apacheHttpClientToMockServerResponseMapper = new ApacheHttpClientToMockServerResponseMapper();
private CloseableHttpClient httpClient;
public ApacheHttpClient(boolean isSecure) {
try {
HttpClientBuilder httpClientBuilder = HttpClients.custom().disableCookieManagement();
if (isSecure) {
httpClientBuilder
.setSslcontext(
SSLContexts
.custom()
.loadTrustMaterial(SSLFactory.getInstance().buildKeyStore(), trustStrategy)
.build()
)
.setHostnameVerifier(new AllowAllHostnameVerifier());
}
// TODO(jamesdbloom) the section below if commented out as it is still experimental
// System.getProperty("http.keepAlive", "false");
// httpClientBuilder
// .setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
// public long getKeepAliveDuration(org.apache.http.HttpResponse response, HttpContext context) {
// return 0;
// }
// })
// .setDefaultRequestConfig(
// RequestConfig
// .custom()
// .setConnectionRequestTimeout(new Long(maxTimeout()).intValue())
// .setConnectTimeout(new Long(maxTimeout()).intValue())
// .build()
// )
// .setDefaultSocketConfig(
// SocketConfig
// .custom()
// .setSoTimeout((int) TimeUnit.SECONDS.toMillis(10))
// .setSoLinger((int) TimeUnit.SECONDS.toMillis(10))
// .setSoKeepAlive(true)
// .build()
// );
this.httpClient = httpClientBuilder.build();
} catch (Exception e) {
throw new RuntimeException("Exception creating http client", e);
}
}