class HttpClientHelper {

    public static CloseableHttpClient createHttpClient(final int maxRedirects) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
        s_logger.info("Creating new HTTP connection pool and client");
        final Registry<ConnectionSocketFactory> socketFactoryRegistry = createSocketFactoryConfigration();
        final BasicCookieStore cookieStore = new BasicCookieStore();
        final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
        connManager.setDefaultMaxPerRoute(MAX_ALLOCATED_CONNECTIONS_PER_ROUTE);
        connManager.setMaxTotal(MAX_ALLOCATED_CONNECTIONS);
        final RequestConfig requestConfig = RequestConfig.custom()
            .setCookieSpec(CookieSpecs.DEFAULT)
            .setMaxRedirects(maxRedirects)
            .setSocketTimeout(DEFAULT_SOCKET_TIMEOUT)
            .setConnectionRequestTimeout(DEFAULT_CONNECTION_REQUEST_TIMEOUT)
            .setConnectTimeout(DEFAULT_CONNECT_TIMEOUT)
            .build();
        return HttpClientBuilder.create()
            .setConnectionManager(connManager)
            .setRedirectStrategy(new LaxRedirectStrategy())
            .setDefaultRequestConfig(requestConfig)
            .setDefaultCookieStore(cookieStore)
            .setRetryHandler(new StandardHttpRequestRetryHandler())
            .build();
    }

}