use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project neweagle-api by apgzs.
the class HttpHelper method init.
private static void init() {
if (cm == null) {
cm = new PoolingHttpClientConnectionManager();
// 整个连接池最大连接数
cm.setMaxTotal(50);
// 每路由最大连接数,默认值是2
cm.setDefaultMaxPerRoute(5);
}
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project JFramework by gugumall.
the class JHttp method createSelfSignedX.
/**
* @param certFilePath
* @param password
* @param keyStoreType
* @return
* @throws Exception
*/
public static JHttp createSelfSignedX(URL certFilePath, String password, String[] protocols) throws Exception {
JHttp jhttp = new JHttp();
SSLContext ctx = SSLContexts.custom().loadTrustMaterial(certFilePath, password.toCharArray(), new TrustSelfSignedStrategy()).build();
ctx.init(null, new TrustManager[] { new MyTrustManager() }, null);
SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(ctx, protocols, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier());
jhttp.poolingmgr = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", factory).build(), null, null, null, 5000, TimeUnit.MILLISECONDS);
jhttp.poolingmgr.setDefaultMaxPerRoute(100);
jhttp.poolingmgr.setMaxTotal(1000);
return jhttp;
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project csb-sdk by aliyun.
the class HttpClientFactory method createConnManager.
/**
* Create a connection pool which supports http and https socket
* @return
* @throws HttpCallerException
*/
public static PoolingHttpClientConnectionManager createConnManager() throws HttpCallerException {
try {
// ignore SSL certificate info with the below two setting:
// 1. trust https server certificate always.
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException {
return true;
}
}).build();
// 2. hostname verifier pass
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
return new PoolingHttpClientConnectionManager(socketFactoryRegistry);
} catch (Exception e) {
throw new HttpCallerException("Failed to create httpclient: " + e.getMessage(), e);
}
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project tutorials by eugenp.
the class RestEasyClientLiveTest method testAddMovieMultiConnection.
@Test
public void testAddMovieMultiConnection() {
final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
final CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build();
final ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
final ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
final ResteasyWebTarget target = client.target(FULL_PATH);
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
final Response batmanResponse = proxy.addMovie(batmanMovie);
final Response transformerResponse = proxy.addMovie(transformerMovie);
if (batmanResponse.getStatus() != Response.Status.CREATED.getStatusCode()) {
System.out.println("Batman Movie creation Failed : HTTP error code : " + batmanResponse.getStatus());
}
if (batmanResponse.getStatus() != Response.Status.CREATED.getStatusCode()) {
System.out.println("Batman Movie creation Failed : HTTP error code : " + batmanResponse.getStatus());
}
batmanResponse.close();
transformerResponse.close();
cm.close();
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project tephra by heisedebaise.
the class HttpImpl method onContextRefreshed.
@Override
public void onContextRefreshed() {
try {
SSLContext sslContext = SSLContext.getInstance("SSLv3");
sslContext.init(null, new TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, null);
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", sslConnectionSocketFactory).build();
manager = new PoolingHttpClientConnectionManager(registry);
manager.setMaxTotal(max);
manager.setDefaultMaxPerRoute(max >> 3);
} catch (Exception e) {
logger.warn(e, "初始化HTTP/S客户端时发生异常!");
}
}
Aggregations