use of org.apache.http.conn.HttpClientConnectionManager in project aliyun-oss-java-sdk by aliyun.
the class IdleConnectionReaper method run.
@SuppressWarnings("unchecked")
@Override
public void run() {
while (true) {
if (shuttingDown) {
getLog().debug("Shutting down reaper thread.");
return;
}
try {
Thread.sleep(REAP_INTERVAL_MILLISECONDS);
} catch (InterruptedException e) {
}
try {
List<HttpClientConnectionManager> connectionManagers = null;
synchronized (IdleConnectionReaper.class) {
connectionManagers = (List<HttpClientConnectionManager>) IdleConnectionReaper.connectionManagers.clone();
}
for (HttpClientConnectionManager connectionManager : connectionManagers) {
try {
connectionManager.closeExpiredConnections();
connectionManager.closeIdleConnections(idleConnectionTime, TimeUnit.MILLISECONDS);
} catch (Exception ex) {
getLog().warn("Unable to close idle connections", ex);
}
}
} catch (Throwable t) {
getLog().debug("Reaper thread: ", t);
}
}
}
use of org.apache.http.conn.HttpClientConnectionManager in project hbase by apache.
the class TestSecureRESTServer method getClient.
private Pair<CloseableHttpClient, HttpClientContext> getClient() {
HttpClientConnectionManager pool = new PoolingHttpClientConnectionManager();
HttpHost host = new HttpHost("localhost", REST_TEST.getServletPort());
Registry<AuthSchemeProvider> authRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, true)).build();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, EmptyCredentials.INSTANCE);
AuthCache authCache = new BasicAuthCache();
CloseableHttpClient client = HttpClients.custom().setDefaultAuthSchemeRegistry(authRegistry).setConnectionManager(pool).build();
HttpClientContext context = HttpClientContext.create();
context.setTargetHost(host);
context.setCredentialsProvider(credentialsProvider);
context.setAuthSchemeRegistry(authRegistry);
context.setAuthCache(authCache);
return new Pair<>(client, context);
}
use of org.apache.http.conn.HttpClientConnectionManager in project wildfly by wildfly.
the class TestHttpClientUtils method getHttpsClient.
/**
*@param credentialsProvider optional cred provider
* @return client that doesn't verify https connections
*/
public static CloseableHttpClient getHttpsClient(CredentialsProvider credentialsProvider) {
try {
SSLContext ctx = getSslContext();
SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(ctx, new NoopHostnameVerifier());
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", sslConnectionFactory).build();
HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registry);
HttpClientBuilder builder = HttpClientBuilder.create().setSSLSocketFactory(sslConnectionFactory).setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionManager(ccm);
if (credentialsProvider != null) {
builder.setDefaultCredentialsProvider(credentialsProvider);
}
return builder.build();
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
use of org.apache.http.conn.HttpClientConnectionManager in project canal by alibaba.
the class AbstractRequest method executeHttpRequest.
/**
* 执行http请求
*
* @param getMethod
* @return
* @throws IOException
*/
@SuppressWarnings("deprecation")
private final HttpResponse executeHttpRequest(HttpGet getMethod, String host) throws Exception {
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, (TrustStrategy) (arg0, arg1) -> true).build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Registry registry = RegistryBuilder.create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", sslsf).build();
HttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager(registry);
CloseableHttpClient httpClient = HttpClientBuilder.create().setMaxConnPerRoute(50).setMaxConnTotal(100).setConnectionManager(httpClientConnectionManager).build();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout).setSocketTimeout(timeout).build();
getMethod.setConfig(requestConfig);
HttpResponse response = httpClient.execute(getMethod);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpResponseStatus.OK.code() && statusCode != HttpResponseStatus.PARTIAL_CONTENT.code()) {
String result = EntityUtils.toString(response.getEntity());
throw new RuntimeException("return error !" + response.getStatusLine().getReasonPhrase() + ", " + result);
}
return response;
}
use of org.apache.http.conn.HttpClientConnectionManager in project docker-maven-plugin by fabric8io.
the class HttpClientBuilder method buildPooledClient.
public CloseableHttpClient buildPooledClient() throws IOException {
org.apache.http.impl.client.HttpClientBuilder builder = HttpClients.custom();
HttpClientConnectionManager manager = getPooledConnectionFactory(certPath, maxConnections);
builder.setConnectionManager(manager);
return builder.build();
}
Aggregations