@ SneakyThrows private CloseableHttpClient buildHttpClient ( ) { val plainSocketFactory = PlainConnectionSocketFactory . getSocketFactory ( ) ; val registry = RegistryBuilder . < ConnectionSocketFactory > create ( ) . register ( "http" , plainSocketFactory ) . register ( "https" , this . sslSocketFactory ) . build ( ) ; val connectionManager = new PoolingHttpClientConnectionManager ( registry ) ; connectionManager . setMaxTotal ( this . maxPooledConnections ) ; connectionManager . setDefaultMaxPerRoute ( this . maxConnectionsPerRoute ) ; connectionManager . setValidateAfterInactivity ( DEFAULT_TIMEOUT ) ; val httpHost = new HttpHost ( InetAddress . getLocalHost ( ) ) ; val httpRoute = new HttpRoute ( httpHost ) ; connectionManager . setMaxPerRoute ( httpRoute , MAX_CONNECTIONS_PER_ROUTE ) ; val requestConfig = RequestConfig . custom ( ) . setSocketTimeout ( this . readTimeout ) . setConnectTimeout ( ( int ) this . connectionTimeout ) . setConnectionRequestTimeout ( ( int ) this . connectionTimeout ) . setCircularRedirectsAllowed ( this . circularRedirectsAllowed ) . setRedirectsEnabled ( this . redirectsEnabled ) . setAuthenticationEnabled ( this . authenticationEnabled ) . build ( ) ; val builder = HttpClients . custom ( ) . setConnectionManager ( connectionManager ) . setDefaultRequestConfig ( requestConfig ) . setSSLSocketFactory ( this . sslSocketFactory ) . setSSLHostnameVerifier ( this . hostnameVerifier ) . setRedirectStrategy ( this . redirectionStrategy ) . setDefaultCredentialsProvider ( this . credentialsProvider ) . setDefaultCookieStore ( this . cookieStore ) . setConnectionReuseStrategy ( this . connectionReuseStrategy ) . setConnectionBackoffStrategy ( this . connectionBackoffStrategy ) . setServiceUnavailableRetryStrategy ( this . serviceUnavailableRetryStrategy ) . setProxyAuthenticationStrategy ( this . proxyAuthenticationStrategy ) . setDefaultHeaders ( this . defaultHeaders ) . useSystemProperties ( ) ; return builder . build ( ) ; }
Build a HTTP client based on the current properties .