public static CloseableHttpClient newHttpClient ( ) { final SocketConfig socketConfig = SocketConfig . custom ( ) . setSoKeepAlive ( Boolean . TRUE ) . setTcpNoDelay ( Boolean . TRUE ) . setSoTimeout ( SOCKET_TIMEOUT_MS ) . build ( ) ; final PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager ( ) ; manager . setDefaultMaxPerRoute ( MAX_HOSTS ) ; manager . setMaxTotal ( MAX_HOSTS ) ; manager . setDefaultSocketConfig ( socketConfig ) ; final RequestConfig requestConfig = RequestConfig . custom ( ) . setConnectTimeout ( CONNECTION_TIMEOUT_MS ) . setCookieSpec ( CookieSpecs . IGNORE_COOKIES ) . setStaleConnectionCheckEnabled ( Boolean . FALSE ) . setSocketTimeout ( SOCKET_TIMEOUT_MS ) . build ( ) ; final CloseableHttpClient client = HttpClients . custom ( ) . disableRedirectHandling ( ) . setConnectionManager ( manager ) . setDefaultRequestConfig ( requestConfig ) . setConnectionReuseStrategy ( new DefaultConnectionReuseStrategy ( ) ) . setConnectionBackoffStrategy ( new DefaultBackoffStrategy ( ) ) . setRetryHandler ( new DefaultHttpRequestRetryHandler ( MAX_RETRIES , false ) ) . setKeepAliveStrategy ( new DefaultConnectionKeepAliveStrategy ( ) ) . build ( ) ; return client ; }
Get a new CloseableHttpClient