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);
}
Aggregations