public static void setParams ( int connectionTimeout , int socketTimeout , int maxRequests ) { PrudentHttpEntityResolver . maxRequests = maxRequests ; PoolingHttpClientConnectionManager phcConnMgr ; Registry < ConnectionSocketFactory > registry = // RegistryBuilder . < ConnectionSocketFactory > create ( ) // . register ( "http" , PlainConnectionSocketFactory . getSocketFactory ( ) ) // . register ( "https" , SSLConnectionSocketFactory . getSocketFactory ( ) ) // . build ( ) ; HttpClientBuilder builder = HttpClients . custom ( ) . useSystemProperties ( ) ; builder . setRedirectStrategy ( new LaxRedirectStrategy ( ) ) ; builder . setMaxConnPerRoute ( maxRequests ) ; builder . setMaxConnTotal ( Integer . parseInt ( System . getProperty ( "nu.validator.servlet.max-total-connections" , "200" ) ) ) ; if ( "true" . equals ( System . getProperty ( "nu.validator.xml.promiscuous-ssl" , "true" ) ) ) { // try { SSLContext promiscuousSSLContext = new SSLContextBuilder ( ) // . loadTrustMaterial ( null , new TrustStrategy ( ) { @ Override public boolean isTrusted ( X509Certificate [ ] arg0 , String arg1 ) throws CertificateException { return true ; } } ) . build ( ) ; builder . setSslcontext ( promiscuousSSLContext ) ; HostnameVerifier verifier = // SSLConnectionSocketFactory . ALLOW_ALL_HOSTNAME_VERIFIER ; SSLConnectionSocketFactory promiscuousSSLConnSocketFactory = // new SSLConnectionSocketFactory ( promiscuousSSLContext , verifier ) ; registry = RegistryBuilder . < ConnectionSocketFactory > create ( ) // . register ( "https" , promiscuousSSLConnSocketFactory ) // . register ( "http" , PlainConnectionSocketFactory . getSocketFactory ( ) ) // . build ( ) ; } catch ( KeyManagementException | KeyStoreException | NoSuchAlgorithmException | NumberFormatException e ) { e . printStackTrace ( ) ; } } phcConnMgr = new PoolingHttpClientConnectionManager ( registry ) ; phcConnMgr . setDefaultMaxPerRoute ( maxRequests ) ; phcConnMgr . setMaxTotal ( 200 ) ; builder . setConnectionManager ( phcConnMgr ) ; RequestConfig . Builder config = RequestConfig . custom ( ) ; config . setCircularRedirectsAllowed ( true ) ; config . setMaxRedirects ( Integer . parseInt ( System . getProperty ( "nu.validator.servlet.max-redirects" , "20" ) ) ) ; config . setConnectTimeout ( connectionTimeout ) ; config . setCookieSpec ( CookieSpecs . BEST_MATCH ) ; config . setSocketTimeout ( socketTimeout ) ; config . setCookieSpec ( CookieSpecs . IGNORE_COOKIES ) ; client = builder . setDefaultRequestConfig ( config . build ( ) ) . build ( ) ; }
Sets the timeouts of the HTTP client .