Search in sources :

Example 1 with KeepAliveStrategy

use of org.asynchttpclient.channel.KeepAliveStrategy in project async-http-client by AsyncHttpClient.

the class BasicHttpsTest method multipleConcurrentPostRequestsOverHttpsWithDisabledKeepAliveStrategy.

@Test
public void multipleConcurrentPostRequestsOverHttpsWithDisabledKeepAliveStrategy() throws Throwable {
    logger.debug(">>> multipleConcurrentPostRequestsOverHttpsWithDisabledKeepAliveStrategy");
    KeepAliveStrategy keepAliveStrategy = (ahcRequest, nettyRequest, nettyResponse) -> !ahcRequest.getUri().isSecured();
    withClient(config().setSslEngineFactory(createSslEngineFactory()).setKeepAliveStrategy(keepAliveStrategy)).run(client -> withServer(server).run(server -> {
        server.enqueueEcho();
        server.enqueueEcho();
        server.enqueueEcho();
        String body = "hello there";
        client.preparePost(getTargetUrl()).setBody(body).setHeader(CONTENT_TYPE, "text/html").execute();
        client.preparePost(getTargetUrl()).setBody(body).setHeader(CONTENT_TYPE, "text/html").execute();
        Response response = client.preparePost(getTargetUrl()).setBody(body).setHeader(CONTENT_TYPE, "text/html").execute().get();
        assertEquals(response.getResponseBody(), body);
    }));
    logger.debug("<<< multipleConcurrentPostRequestsOverHttpsWithDisabledKeepAliveStrategy");
}
Also used : AfterClass(org.testng.annotations.AfterClass) KeepAliveStrategy(org.asynchttpclient.channel.KeepAliveStrategy) Arrays(java.util.Arrays) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) BeforeClass(org.testng.annotations.BeforeClass) HttpServletResponse(javax.servlet.http.HttpServletResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Assert.assertNotNull(org.testng.Assert.assertNotNull) EventCollectingHandler(org.asynchttpclient.test.EventCollectingHandler) TestUtils(org.asynchttpclient.test.TestUtils) ExecutionException(java.util.concurrent.ExecutionException) Dsl.config(org.asynchttpclient.Dsl.config) CONTENT_TYPE(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE) HttpServer(org.asynchttpclient.testserver.HttpServer) HttpTest(org.asynchttpclient.testserver.HttpTest) SECONDS(java.util.concurrent.TimeUnit.SECONDS) HttpServletResponse(javax.servlet.http.HttpServletResponse) KeepAliveStrategy(org.asynchttpclient.channel.KeepAliveStrategy) Test(org.testng.annotations.Test) HttpTest(org.asynchttpclient.testserver.HttpTest)

Aggregations

CONTENT_TYPE (io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE)1 Arrays (java.util.Arrays)1 ExecutionException (java.util.concurrent.ExecutionException)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Dsl.config (org.asynchttpclient.Dsl.config)1 KeepAliveStrategy (org.asynchttpclient.channel.KeepAliveStrategy)1 EventCollectingHandler (org.asynchttpclient.test.EventCollectingHandler)1 TestUtils (org.asynchttpclient.test.TestUtils)1 HttpServer (org.asynchttpclient.testserver.HttpServer)1 HttpTest (org.asynchttpclient.testserver.HttpTest)1 Assert.assertEquals (org.testng.Assert.assertEquals)1 Assert.assertNotNull (org.testng.Assert.assertNotNull)1 AfterClass (org.testng.annotations.AfterClass)1 BeforeClass (org.testng.annotations.BeforeClass)1 Test (org.testng.annotations.Test)1