Search in sources :

Example 41 with PoolingHttpClientConnectionManager

use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project connect-sdk-java by Ingenico-ePayments.

the class DefaultConnectionTest method assertMaxConnections.

@SuppressWarnings("resource")
private static void assertMaxConnections(DefaultConnection connection, int maxConnections, ProxyConfiguration proxyConfiguration) {
    CloseableHttpClient httpClient = ReflectionUtil.getField(connection, "httpClient", CloseableHttpClient.class);
    PoolingHttpClientConnectionManager connectionManager = ReflectionUtil.getField(httpClient, "connManager", PoolingHttpClientConnectionManager.class);
    Assert.assertEquals(maxConnections, connectionManager.getDefaultMaxPerRoute());
    Assert.assertTrue(maxConnections <= connectionManager.getMaxTotal());
    HttpHost target = new HttpHost("api-sandbox.globalcollect.com", -1, "https");
    HttpHost proxy = proxyConfiguration != null ? new HttpHost(proxyConfiguration.getHost(), proxyConfiguration.getPort(), proxyConfiguration.getScheme()) : null;
    HttpRoute route = proxy != null ? new HttpRoute(target, proxy) : new HttpRoute(target);
    Assert.assertEquals(maxConnections, connectionManager.getMaxPerRoute(route));
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpRoute(org.apache.http.conn.routing.HttpRoute) HttpHost(org.apache.http.HttpHost) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 42 with PoolingHttpClientConnectionManager

use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project connect-sdk-java by Ingenico-ePayments.

the class DefaultConnection method createHttpClientConnectionManager.

private HttpClientConnectionManager createHttpClientConnectionManager(int maxConnections) {
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
    connectionManager.setDefaultMaxPerRoute(maxConnections);
    connectionManager.setMaxTotal(maxConnections + 20);
    return connectionManager;
}
Also used : PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 43 with PoolingHttpClientConnectionManager

use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project solr-cmd-utils by tblsoft.

the class HttpFilter method init.

@Override
public void init() {
    urlField = getProperty("urlField", "url");
    userAgent = getProperty("userAgent", "Solr Cmd Utils Http Agent/1.0");
    // httpclient = HttpClients.createDefault();
    threads = getPropertyAsInt("threads", 1);
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(threads);
    cm.setDefaultMaxPerRoute(threads);
    httpclient = HttpClients.custom().setConnectionManager(cm).setMaxConnPerRoute(threads).build();
    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("tblsoft-http-filter-thread-%d").build();
    executor = Executors.newFixedThreadPool(threads, namedThreadFactory);
    System.out.println("start http filter with threads: " + threads);
    super.init();
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 44 with PoolingHttpClientConnectionManager

use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project spring-cloud-netflix by spring-cloud.

the class RibbonLoadBalancingHttpClientTests method testConnections.

@Test
public void testConnections() throws Exception {
    SpringClientFactory factory = new SpringClientFactory();
    factory.setApplicationContext(new AnnotationConfigApplicationContext(RibbonAutoConfiguration.class, Connections.class));
    RetryableRibbonLoadBalancingHttpClient client = factory.getClient("service", RetryableRibbonLoadBalancingHttpClient.class);
    HttpClient delegate = client.getDelegate();
    PoolingHttpClientConnectionManager connManager = (PoolingHttpClientConnectionManager) ReflectionTestUtils.getField(delegate, "connManager");
    assertThat(connManager.getMaxTotal(), is(101));
    assertThat(connManager.getDefaultMaxPerRoute(), is(201));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RibbonAutoConfiguration(org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration) SpringClientFactory(org.springframework.cloud.netflix.ribbon.SpringClientFactory) HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Test(org.junit.Test)

Example 45 with PoolingHttpClientConnectionManager

use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project repseqio by repseqio.

the class SequenceResolvers method initDefaultResolver.

public static void initDefaultResolver(Path cacheFolderPath) {
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    CloseableHttpClient httpClient = HttpClients.custom().disableCookieManagement().setConnectionManager(cm).build();
    HTTPResolversContext context = new HTTPResolversContext(cacheFolderPath, httpClient);
    initDefaultResolver(context);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Aggregations

PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)180 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)63 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)62 PlainConnectionSocketFactory (org.apache.http.conn.socket.PlainConnectionSocketFactory)54 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)52 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)42 SSLContext (javax.net.ssl.SSLContext)36 RequestConfig (org.apache.http.client.config.RequestConfig)31 IOException (java.io.IOException)29 Test (org.junit.Test)27 HttpHost (org.apache.http.HttpHost)21 HttpGet (org.apache.http.client.methods.HttpGet)18 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)17 AuthScope (org.apache.http.auth.AuthScope)16 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)16 HttpResponse (org.apache.http.HttpResponse)15 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)14 CredentialsProvider (org.apache.http.client.CredentialsProvider)14 HostnameVerifier (javax.net.ssl.HostnameVerifier)13 HttpClient (org.apache.http.client.HttpClient)12