Search in sources :

Example 1 with HttpRequestExecutor

use of org.apache.http.protocol.HttpRequestExecutor in project tutorials by eugenp.

the class HttpClientConnectionManagementLiveTest method givenBasicHttpClientConnManager_whenConnectionReuse_thenNoExceptions.

// 6
@Test
public final // 6.1
void givenBasicHttpClientConnManager_whenConnectionReuse_thenNoExceptions() throws InterruptedException, ExecutionException, IOException, HttpException {
    basicConnManager = new BasicHttpClientConnectionManager();
    context = HttpClientContext.create();
    final ConnectionRequest connRequest = basicConnManager.requestConnection(route, null);
    conn = connRequest.get(10, TimeUnit.SECONDS);
    basicConnManager.connect(conn, route, 1000, context);
    basicConnManager.routeComplete(conn, route, context);
    final HttpRequestExecutor exeRequest = new HttpRequestExecutor();
    context.setTargetHost((new HttpHost("http://httpbin.org", 80)));
    final HttpGet get = new HttpGet("http://httpbin.org");
    exeRequest.execute(get, conn, context);
    conn.isResponseAvailable(1000);
    basicConnManager.releaseConnection(conn, null, 1, TimeUnit.SECONDS);
    // 
    client = HttpClients.custom().setConnectionManager(basicConnManager).build();
    client.execute(get);
}
Also used : ConnectionRequest(org.apache.http.conn.ConnectionRequest) HttpRequestExecutor(org.apache.http.protocol.HttpRequestExecutor) HttpHost(org.apache.http.HttpHost) HttpGet(org.apache.http.client.methods.HttpGet) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager) Test(org.junit.Test)

Aggregations

HttpHost (org.apache.http.HttpHost)1 HttpGet (org.apache.http.client.methods.HttpGet)1 ConnectionRequest (org.apache.http.conn.ConnectionRequest)1 BasicHttpClientConnectionManager (org.apache.http.impl.conn.BasicHttpClientConnectionManager)1 HttpRequestExecutor (org.apache.http.protocol.HttpRequestExecutor)1 Test (org.junit.Test)1