List of usage examples for org.apache.http.impl.client DefaultConnectionKeepAliveStrategy INSTANCE
DefaultConnectionKeepAliveStrategy INSTANCE
To view the source code for org.apache.http.impl.client DefaultConnectionKeepAliveStrategy INSTANCE.
Click Source Link
From source file:com.amazonaws.http.conn.SdkConnectionKeepAliveStrategy.java
@Override public long getKeepAliveDuration(HttpResponse response, HttpContext context) { // If there's a Keep-Alive timeout directive in the response and it's // shorter than our configured max, honor that. Otherwise go with the // configured maximum. long duration = DefaultConnectionKeepAliveStrategy.INSTANCE.getKeepAliveDuration(response, context); if (0 < duration && duration < maxIdleTime) { return duration; }//from w w w . j a va 2 s . c o m return maxIdleTime; }
From source file:com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClientBuilder.java
public CloseableHttpClient build() throws Exception { HttpClientBuilder builder = HttpClients.custom(); builder.useSystemProperties();/*w ww . j av a 2 s .c om*/ builder.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).build()) .setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE); HostnameVerifier hostnameVerifier = sslVerificationMode.verifier(); TrustStrategy trustStrategy = sslVerificationMode.trustStrategy(); KeyStore trustStore = agentTruststore(); SSLContextBuilder sslContextBuilder = SSLContextBuilder.create().useProtocol( systemEnvironment.get(SystemEnvironment.GO_SSL_TRANSPORT_PROTOCOL_TO_BE_USED_BY_AGENT)); if (trustStore != null || trustStrategy != null) { sslContextBuilder.loadTrustMaterial(trustStore, trustStrategy); } sslContextBuilder.loadKeyMaterial(agentKeystore(), keystorePassword().toCharArray()); SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory( sslContextBuilder.build(), hostnameVerifier); builder.setSSLSocketFactory(sslConnectionSocketFactory); return builder.build(); }
From source file:org.apache.hadoop.gateway.dispatch.DefaultHttpClientFactory.java
@Override public HttpClient createHttpClient(FilterConfig filterConfig) { HttpClientBuilder builder = null;//from w ww .j a va 2s . co m GatewayConfig gatewayConfig = (GatewayConfig) filterConfig.getServletContext() .getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE); if (gatewayConfig != null && gatewayConfig.isMetricsEnabled()) { GatewayServices services = (GatewayServices) filterConfig.getServletContext() .getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE); MetricsService metricsService = services.getService(GatewayServices.METRICS_SERVICE); builder = metricsService.getInstrumented(HttpClientBuilder.class); } else { builder = HttpClients.custom(); } if ("true".equals(System.getProperty(GatewayConfig.HADOOP_KERBEROS_SECURED))) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UseJaasCredentials()); Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create() .register(AuthSchemes.SPNEGO, new KnoxSpnegoAuthSchemeFactory(true)).build(); builder = builder.setDefaultAuthSchemeRegistry(authSchemeRegistry) .setDefaultCookieStore(new HadoopAuthCookieStore()) .setDefaultCredentialsProvider(credentialsProvider); } else { builder = builder.setDefaultCookieStore(new NoCookieStore()); } builder.setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE); builder.setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE); builder.setRedirectStrategy(new NeverRedirectStrategy()); builder.setRetryHandler(new NeverRetryHandler()); int maxConnections = getMaxConnections(filterConfig); builder.setMaxConnTotal(maxConnections); builder.setMaxConnPerRoute(maxConnections); builder.setDefaultRequestConfig(getRequestConfig(filterConfig)); HttpClient client = builder.build(); return client; }
From source file:org.callimachusproject.client.HttpClientFactory.java
private HttpClientFactory(File cacheDir) throws IOException { cacheDir.mkdirs();//from w ww . j a va 2 s. com entryFactory = new FileResourceFactory(cacheDir); decorator = new ProxyClientExecDecorator(); LayeredConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactory.getSystemSocketFactory(); connManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory).build()); connManager.setDefaultSocketConfig(getDefaultSocketConfig()); connManager.setDefaultConnectionConfig(getDefaultConnectionConfig()); int max = Integer.parseInt(System.getProperty("http.maxConnections", "20")); connManager.setDefaultMaxPerRoute(max); connManager.setMaxTotal(2 * max); reuseStrategy = DefaultConnectionReuseStrategy.INSTANCE; keepAliveStrategy = new ConnectionKeepAliveStrategy() { private final long KEEPALIVE = SystemProperties.getClientKeepAliveTimeout(); private ConnectionKeepAliveStrategy delegate = DefaultConnectionKeepAliveStrategy.INSTANCE; public long getKeepAliveDuration(HttpResponse response, HttpContext context) { long ret = delegate.getKeepAliveDuration(response, context); if (ret > 0) return ret; return KEEPALIVE; } }; }
From source file:com.ibm.og.client.ApacheClient.java
private CloseableHttpClient createClient() { final HttpClientBuilder builder = HttpClients.custom(); if (this.userAgent != null) { builder.setUserAgent(this.userAgent); }/*from w w w.jav a2 s .c o m*/ // Some authentication implementations add Content-Length or Transfer-Encoding headers as a part // of their authentication algorithm; remove them here so that the default interceptors do not // throw a ProtocolException // @see RequestContent interceptor builder.addInterceptorFirst(new HttpRequestInterceptor() { @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { request.removeHeaders(HTTP.TRANSFER_ENCODING); request.removeHeaders(HTTP.CONTENT_LEN); } }); return builder.setRequestExecutor(new HttpRequestExecutor(this.waitForContinue)) .setConnectionManager(createConnectionManager()) // TODO investigate ConnectionConfig, particularly bufferSize and fragmentSizeHint // TODO defaultCredentialsProvider and defaultAuthSchemeRegistry for pre/passive auth? .setConnectionReuseStrategy(createConnectionReuseStrategy()) .setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE).disableConnectionState() .disableCookieManagement().disableContentCompression().disableAuthCaching() .setRetryHandler(new CustomHttpRequestRetryHandler(this.retryCount, this.requestSentRetry)) .setRedirectStrategy(new CustomRedirectStrategy()).setDefaultRequestConfig(createRequestConfig()) .evictExpiredConnections() .evictIdleConnections(Long.valueOf(this.maxIdleTime), TimeUnit.MILLISECONDS).build(); }
From source file:org.apache.http.impl.nio.client.MinimalHttpAsyncClient.java
public MinimalHttpAsyncClient(final NHttpClientConnectionManager connmgr, final HttpProcessor httpProcessor) { this(connmgr, Executors.defaultThreadFactory(), new HttpAsyncRequestExecutor(), httpProcessor, DefaultConnectionReuseStrategy.INSTANCE, DefaultConnectionKeepAliveStrategy.INSTANCE); }