public CloseableHttpClient createHttpClient ( final Consumer < HttpClientBuilder > customiser ) { final HttpClientBuilder builder = HttpClientBuilder . create ( ) ; // By default set long call timeouts { RequestConfig . Builder requestBuilder = RequestConfig . custom ( ) ; requestBuilder . setConnectTimeout ( ( int ) connectionTimeout . getMilliseconds ( ) ) . setSocketTimeout ( ( int ) socketTimeout . getMilliseconds ( ) ) ; builder . setDefaultRequestConfig ( requestBuilder . build ( ) ) ; } // Set the default keepalive setting if ( noKeepalive ) builder . setConnectionReuseStrategy ( new NoConnectionReuseStrategy ( ) ) ; // By default share the common connection provider builder . setConnectionManager ( connectionManager ) ; // By default use the JRE default route planner for proxies builder . setRoutePlanner ( new SystemDefaultRoutePlanner ( ProxySelector . getDefault ( ) ) ) ; // Allow customisation if ( customiser != null ) customiser . accept ( builder ) ; return builder . build ( ) ; }
Build an HttpClient