use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project metron by apache.
the class TaxiiHandler method buildClient.
private static HttpClient buildClient(URL proxy, String username, String password) throws Exception {
// Start with a default TAXII HTTP client.
HttpClient client = new HttpClient();
// Create an Apache HttpClientBuilder to be customized by the command line arguments.
HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties();
// Proxy
if (proxy != null) {
HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort(), proxy.getProtocol());
builder.setProxy(proxyHost);
}
// Basic authentication. User & Password
if (username != null ^ password != null) {
throw new Exception("'username' and 'password' arguments are required to appear together.");
}
// from: http://stackoverflow.com/questions/19517538/ignoring-ssl-certificate-in-apache-httpclient-4-3
SSLContextBuilder ssbldr = new SSLContextBuilder();
ssbldr.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(ssbldr.build(), SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", new PlainConnectionSocketFactory()).register("https", sslsf).build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
// max connection
cm.setMaxTotal(20);
// ""
System.setProperty("jsse.enableSNIExtension", "false");
CloseableHttpClient httpClient = builder.setSSLSocketFactory(sslsf).setConnectionManager(cm).build();
client.setHttpclient(httpClient);
return client;
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project metron by apache.
the class RestFunctionsTest method restGetShouldGetPoolingConnectionManager.
@Test
public void restGetShouldGetPoolingConnectionManager() {
RestConfig restConfig = new RestConfig();
restConfig.put(POOLING_MAX_TOTAL, 5);
restConfig.put(POOLING_DEFAULT_MAX_PER_RUOTE, 2);
PoolingHttpClientConnectionManager cm = RestFunctions.getConnectionManager(restConfig);
assertEquals(5, cm.getMaxTotal());
assertEquals(2, cm.getDefaultMaxPerRoute());
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project docker-maven-plugin by fabric8io.
the class HttpClientBuilder method getPooledConnectionFactory.
private static HttpClientConnectionManager getPooledConnectionFactory(String certPath, int maxConnections) throws IOException {
PoolingHttpClientConnectionManager ret = certPath != null ? new PoolingHttpClientConnectionManager(getSslFactoryRegistry(certPath)) : new PoolingHttpClientConnectionManager();
ret.setDefaultMaxPerRoute(maxConnections);
ret.setMaxTotal(maxConnections);
return ret;
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project docker-maven-plugin by fabric8io.
the class AbstractNativeClientBuilder method buildPooledClient.
@Override
public CloseableHttpClient buildPooledClient() {
final HttpClientBuilder httpBuilder = HttpClients.custom();
final PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(registry, dnsResolver);
manager.setDefaultMaxPerRoute(maxConnections);
httpBuilder.setConnectionManager(manager);
return httpBuilder.build();
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project carbon-apimgt by wso2.
the class APIUtil method getPoolingHttpClientConnectionManager.
/**
* Return a PoolingHttpClientConnectionManager instance
*
* @param protocol- service endpoint protocol. It can be http/https
* @return PoolManager
*/
private static PoolingHttpClientConnectionManager getPoolingHttpClientConnectionManager(String protocol) throws APIManagementException {
PoolingHttpClientConnectionManager poolManager;
if (APIConstants.HTTPS_PROTOCOL.equals(protocol)) {
SSLConnectionSocketFactory socketFactory = createSocketFactory();
org.apache.http.config.Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register(APIConstants.HTTPS_PROTOCOL, socketFactory).build();
poolManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
} else {
poolManager = new PoolingHttpClientConnectionManager();
}
return poolManager;
}
Aggregations