Search in sources :

Example 36 with PoolingHttpClientConnectionManager

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

the class HttpClientConnectionManagementLiveTest method whenCustomizedIdleConnMonitor_thenNoExceptions.

@Test
public final // 8.2 ARTICLE VERSION
void whenCustomizedIdleConnMonitor_thenNoExceptions() throws InterruptedException, IOException {
    new HttpGet("http://google.com");
    poolingConnManager = new PoolingHttpClientConnectionManager();
    client = HttpClients.custom().setConnectionManager(poolingConnManager).build();
    final IdleConnectionMonitorThread staleMonitor = new IdleConnectionMonitorThread(poolingConnManager);
    staleMonitor.start();
    staleMonitor.join(1000);
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Test(org.junit.Test)

Example 37 with PoolingHttpClientConnectionManager

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

the class HttpClientConnectionManagementLiveTest method whenExecutingSameRequestsInDifferentThreads_thenExecuteReuqest.

@Test
public final // 4.2 Article version
void whenExecutingSameRequestsInDifferentThreads_thenExecuteReuqest() throws InterruptedException {
    final HttpGet get = new HttpGet("http://www.google.com");
    poolingConnManager = new PoolingHttpClientConnectionManager();
    client = HttpClients.custom().setConnectionManager(poolingConnManager).build();
    final MultiHttpClientConnThread thread1 = new MultiHttpClientConnThread(client, get);
    final MultiHttpClientConnThread thread2 = new MultiHttpClientConnThread(client, get);
    final MultiHttpClientConnThread thread3 = new MultiHttpClientConnThread(client, get);
    thread1.start();
    thread2.start();
    thread3.start();
    thread1.join();
    thread2.join();
    thread3.join();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Test(org.junit.Test)

Example 38 with PoolingHttpClientConnectionManager

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

the class HttpClientConnectionManagementLiveTest method whenPollingConnectionManagerIsConfiguredOnHttpClient_thenNoExceptions.

// 3
@Test
public final // Example 3.1.
void whenPollingConnectionManagerIsConfiguredOnHttpClient_thenNoExceptions() throws InterruptedException, ClientProtocolException, IOException {
    poolingConnManager = new PoolingHttpClientConnectionManager();
    client = HttpClients.custom().setConnectionManager(poolingConnManager).build();
    client.execute(get1);
    assertTrue(poolingConnManager.getTotalStats().getLeased() == 1);
}
Also used : PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Test(org.junit.Test)

Example 39 with PoolingHttpClientConnectionManager

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

the class HttpClientConnectionManagementLiveTest method whenExecutingSameRequestsInDifferentThreads_thenUseDefaultConnLimit.

@Test
public final /*tester*/
void whenExecutingSameRequestsInDifferentThreads_thenUseDefaultConnLimit() throws InterruptedException, IOException {
    poolingConnManager = new PoolingHttpClientConnectionManager();
    client = HttpClients.custom().setConnectionManager(poolingConnManager).build();
    final TesterVersion_MultiHttpClientConnThread thread1 = new TesterVersion_MultiHttpClientConnThread(client, new HttpGet("http://www.google.com"), poolingConnManager);
    final TesterVersion_MultiHttpClientConnThread thread2 = new TesterVersion_MultiHttpClientConnThread(client, new HttpGet("http://www.google.com"), poolingConnManager);
    final TesterVersion_MultiHttpClientConnThread thread3 = new TesterVersion_MultiHttpClientConnThread(client, new HttpGet("http://www.google.com"), poolingConnManager);
    thread1.start();
    thread2.start();
    thread3.start();
    thread1.join(10000);
    thread2.join(10000);
    thread3.join(10000);
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Test(org.junit.Test)

Example 40 with PoolingHttpClientConnectionManager

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

the class CakeShopPostgresIT method before.

@Before
public void before() throws Exception {
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build();
    // Increase max total connection to 200
    cm.setMaxTotal(200);
    // Increase default max connection per route to 20
    cm.setDefaultMaxPerRoute(20);
    ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
    client = new ResteasyClientBuilder().httpEngine(engine).build();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Before(org.junit.Before)

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