private PoolingHttpClientConnectionManager createConnectionMgr ( ) { PoolingHttpClientConnectionManager connectionMgr ; // prepare SSLContext SSLContext sslContext = buildSslContext ( ) ; ConnectionSocketFactory plainsf = PlainConnectionSocketFactory . getSocketFactory ( ) ; // we allow to disable host name verification against CA certificate, // notice: in general this is insecure and should be avoided in production, // (this type of configuration is useful for development purposes) boolean noHostVerification = false ; LayeredConnectionSocketFactory sslsf = new SSLConnectionSocketFactory ( sslContext , noHostVerification ? NoopHostnameVerifier . INSTANCE : new DefaultHostnameVerifier ( ) ) ; Registry < ConnectionSocketFactory > r = RegistryBuilder . < ConnectionSocketFactory > create ( ) . register ( "http" , plainsf ) . register ( "https" , sslsf ) . build ( ) ; connectionMgr = new PoolingHttpClientConnectionManager ( r , null , null , null , connectionPoolTimeToLive , TimeUnit . SECONDS ) ; connectionMgr . setMaxTotal ( maxConnectionsTotal ) ; connectionMgr . setDefaultMaxPerRoute ( maxConnectionsPerRoute ) ; HttpHost localhost = new HttpHost ( "localhost" , 80 ) ; connectionMgr . setMaxPerRoute ( new HttpRoute ( localhost ) , maxConnectionsPerRoute ) ; return connectionMgr ; }
Creates custom Http Client connection pool to be used by Http Client