Search in sources :

Example 61 with BasicResponseConsumer

use of org.apache.hc.core5.http.nio.support.BasicResponseConsumer in project httpcomponents-core by apache.

the class Http1IntegrationTest method testHeaderTooLargePost.

@Test
public void testHeaderTooLargePost() throws Exception {
    server.register("/hello", () -> new SingleLineResponseHandler("Hi there"));
    final InetSocketAddress serverEndpoint = server.start(null, Http1Config.custom().setMaxLineLength(100).build());
    client.start(new DefaultHttpProcessor(RequestContent.INSTANCE, RequestTargetHost.INSTANCE, RequestConnControl.INSTANCE), null);
    final Future<ClientSessionEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), TIMEOUT);
    final ClientSessionEndpoint streamEndpoint = connectFuture.get();
    final HttpRequest request1 = new BasicHttpRequest(Method.POST, createRequestURI(serverEndpoint, "/hello"));
    request1.setHeader("big-f-header", "1234567890123456789012345678901234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890");
    final byte[] b = new byte[2048];
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte) ('a' + i % 10);
    }
    final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(new BasicRequestProducer(request1, AsyncEntityProducers.create(b, ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
    final Message<HttpResponse, String> result1 = future1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
    Assertions.assertNotNull(result1);
    final HttpResponse response1 = result1.getHead();
    Assertions.assertNotNull(response1);
    Assertions.assertEquals(431, response1.getCode());
    Assertions.assertEquals("Maximum line length limit exceeded", result1.getBody());
}
Also used : BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) StringAsyncEntityConsumer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer) Message(org.apache.hc.core5.http.Message) InetSocketAddress(java.net.InetSocketAddress) BasicRequestProducer(org.apache.hc.core5.http.nio.support.BasicRequestProducer) HttpResponse(org.apache.hc.core5.http.HttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) DefaultHttpProcessor(org.apache.hc.core5.http.protocol.DefaultHttpProcessor) Test(org.junit.Test)

Example 62 with BasicResponseConsumer

use of org.apache.hc.core5.http.nio.support.BasicResponseConsumer in project httpcomponents-core by apache.

the class Http1IntegrationTest method testLargePostsPipelined.

@Test
public void testLargePostsPipelined() throws Exception {
    server.register("*", () -> new EchoHandler(2048));
    final InetSocketAddress serverEndpoint = server.start();
    client.start();
    final Future<ClientSessionEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), TIMEOUT);
    final ClientSessionEndpoint streamEndpoint = connectFuture.get();
    final Queue<Future<Message<HttpResponse, String>>> queue = new LinkedList<>();
    for (int i = 0; i < 5; i++) {
        queue.add(streamEndpoint.execute(new BasicRequestProducer(Method.POST, createRequestURI(serverEndpoint, "/echo"), new MultiLineEntityProducer("0123456789abcdef", 5000)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null));
    }
    while (!queue.isEmpty()) {
        final Future<Message<HttpResponse, String>> future = queue.remove();
        final Message<HttpResponse, String> result = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
        Assertions.assertNotNull(result);
        final HttpResponse response = result.getHead();
        Assertions.assertNotNull(response);
        Assertions.assertEquals(200, response.getCode());
        final String entity = result.getBody();
        Assertions.assertNotNull(entity);
        final StringTokenizer t = new StringTokenizer(entity, "\r\n");
        while (t.hasMoreTokens()) {
            Assertions.assertEquals("0123456789abcdef", t.nextToken());
        }
    }
}
Also used : StringAsyncEntityConsumer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer) Message(org.apache.hc.core5.http.Message) InetSocketAddress(java.net.InetSocketAddress) BasicRequestProducer(org.apache.hc.core5.http.nio.support.BasicRequestProducer) HttpResponse(org.apache.hc.core5.http.HttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) LinkedList(java.util.LinkedList) StringTokenizer(java.util.StringTokenizer) Future(java.util.concurrent.Future) BasicResponseConsumer(org.apache.hc.core5.http.nio.support.BasicResponseConsumer) Test(org.junit.Test)

Example 63 with BasicResponseConsumer

use of org.apache.hc.core5.http.nio.support.BasicResponseConsumer in project httpcomponents-core by apache.

the class Http1IntegrationTest method testSlowResponseConsumer.

@Test
public void testSlowResponseConsumer() throws Exception {
    server.register("/", () -> new MultiLineResponseHandler("0123456789abcd", 100));
    final InetSocketAddress serverEndpoint = server.start();
    client.start(Http1Config.custom().setBufferSize(256).build());
    final Future<ClientSessionEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), TIMEOUT);
    final ClientSessionEndpoint streamEndpoint = connectFuture.get();
    final HttpRequest request1 = new BasicHttpRequest(Method.GET, createRequestURI(serverEndpoint, "/"));
    final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(new BasicRequestProducer(request1, null), new BasicResponseConsumer<>(new AbstractClassicEntityConsumer<String>(16, Executors.newSingleThreadExecutor()) {

        @Override
        protected String consumeData(final ContentType contentType, final InputStream inputStream) throws IOException {
            final Charset charset = ContentType.getCharset(contentType, StandardCharsets.US_ASCII);
            final StringBuilder buffer = new StringBuilder();
            try {
                final byte[] tmp = new byte[16];
                int l;
                while ((l = inputStream.read(tmp)) != -1) {
                    buffer.append(charset.decode(ByteBuffer.wrap(tmp, 0, l)));
                    Thread.sleep(50);
                }
            } catch (final InterruptedException ex) {
                Thread.currentThread().interrupt();
                throw new InterruptedIOException(ex.getMessage());
            }
            return buffer.toString();
        }
    }), null);
    final Message<HttpResponse, String> result1 = future1.get(LONG_TIMEOUT.getDuration(), LONG_TIMEOUT.getTimeUnit());
    Assertions.assertNotNull(result1);
    final HttpResponse response1 = result1.getHead();
    Assertions.assertNotNull(response1);
    Assertions.assertEquals(200, response1.getCode());
    final String s1 = result1.getBody();
    Assertions.assertNotNull(s1);
    final StringTokenizer t1 = new StringTokenizer(s1, "\r\n");
    while (t1.hasMoreTokens()) {
        Assertions.assertEquals("0123456789abcd", t1.nextToken());
    }
}
Also used : BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) InterruptedIOException(java.io.InterruptedIOException) Message(org.apache.hc.core5.http.Message) ContentType(org.apache.hc.core5.http.ContentType) InetSocketAddress(java.net.InetSocketAddress) BasicRequestProducer(org.apache.hc.core5.http.nio.support.BasicRequestProducer) InputStream(java.io.InputStream) Charset(java.nio.charset.Charset) HttpResponse(org.apache.hc.core5.http.HttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) AbstractClassicEntityConsumer(org.apache.hc.core5.http.nio.support.classic.AbstractClassicEntityConsumer) StringTokenizer(java.util.StringTokenizer) Test(org.junit.Test)

Example 64 with BasicResponseConsumer

use of org.apache.hc.core5.http.nio.support.BasicResponseConsumer in project httpcomponents-core by apache.

the class H2CompatibilityTest method executeH2.

void executeH2(final HttpHost target) throws Exception {
    {
        System.out.println("*** HTTP/2 simple request execution ***");
        final Future<AsyncClientEndpoint> connectFuture = client.connect(target, TIMEOUT, HttpVersionPolicy.FORCE_HTTP_2, null);
        try {
            final AsyncClientEndpoint endpoint = connectFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
            final CountDownLatch countDownLatch = new CountDownLatch(1);
            final HttpRequest httpget = new BasicHttpRequest(Method.GET, target, "/status.html");
            endpoint.execute(new BasicRequestProducer(httpget, null), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), new FutureCallback<Message<HttpResponse, String>>() {

                @Override
                public void completed(final Message<HttpResponse, String> responseMessage) {
                    final HttpResponse response = responseMessage.getHead();
                    final int code = response.getCode();
                    if (code == HttpStatus.SC_OK) {
                        logResult(TestResult.OK, target, httpget, response, Objects.toString(response.getFirstHeader("server")));
                    } else {
                        logResult(TestResult.NOK, target, httpget, response, "(status " + code + ")");
                    }
                    countDownLatch.countDown();
                }

                @Override
                public void failed(final Exception ex) {
                    logResult(TestResult.NOK, target, httpget, null, "(" + ex.getMessage() + ")");
                    countDownLatch.countDown();
                }

                @Override
                public void cancelled() {
                    logResult(TestResult.NOK, target, httpget, null, "(cancelled)");
                    countDownLatch.countDown();
                }
            });
            if (!countDownLatch.await(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit())) {
                logResult(TestResult.NOK, target, null, null, "(single request execution failed to complete in time)");
            }
        } catch (final ExecutionException ex) {
            final Throwable cause = ex.getCause();
            logResult(TestResult.NOK, target, null, null, "(" + cause.getMessage() + ")");
        } catch (final TimeoutException ex) {
            logResult(TestResult.NOK, target, null, null, "(time out)");
        }
    }
    {
        System.out.println("*** HTTP/2 multiplexed request execution ***");
        final Future<AsyncClientEndpoint> connectFuture = client.connect(target, TIMEOUT, HttpVersionPolicy.FORCE_HTTP_2, null);
        try {
            final AsyncClientEndpoint endpoint = connectFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
            final int reqCount = 20;
            final CountDownLatch countDownLatch = new CountDownLatch(reqCount);
            for (int i = 0; i < reqCount; i++) {
                final HttpRequest httpget = new BasicHttpRequest(Method.GET, target, "/status.html");
                endpoint.execute(new BasicRequestProducer(httpget, null), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), new FutureCallback<Message<HttpResponse, String>>() {

                    @Override
                    public void completed(final Message<HttpResponse, String> responseMessage) {
                        final HttpResponse response = responseMessage.getHead();
                        final int code = response.getCode();
                        if (code == HttpStatus.SC_OK) {
                            logResult(TestResult.OK, target, httpget, response, "multiplexed / " + response.getFirstHeader("server"));
                        } else {
                            logResult(TestResult.NOK, target, httpget, response, "(status " + code + ")");
                        }
                        countDownLatch.countDown();
                    }

                    @Override
                    public void failed(final Exception ex) {
                        logResult(TestResult.NOK, target, httpget, null, "(" + ex.getMessage() + ")");
                        countDownLatch.countDown();
                    }

                    @Override
                    public void cancelled() {
                        logResult(TestResult.NOK, target, httpget, null, "(cancelled)");
                        countDownLatch.countDown();
                    }
                });
            }
            if (!countDownLatch.await(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit())) {
                logResult(TestResult.NOK, target, null, null, "(multiplexed request execution failed to complete in time)");
            }
        } catch (final ExecutionException ex) {
            final Throwable cause = ex.getCause();
            logResult(TestResult.NOK, target, null, null, "(" + cause.getMessage() + ")");
        } catch (final TimeoutException ex) {
            logResult(TestResult.NOK, target, null, null, "(time out)");
        }
    }
    {
        System.out.println("*** HTTP/2 request execution with push ***");
        final Future<AsyncClientEndpoint> connectFuture = client.connect(target, TIMEOUT, HttpVersionPolicy.FORCE_HTTP_2, null);
        try {
            final AsyncClientEndpoint endpoint = connectFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
            final CountDownLatch countDownLatch = new CountDownLatch(5);
            final HttpRequest httpget = new BasicHttpRequest(Method.GET, target, "/index.html");
            final Future<Message<HttpResponse, String>> future = endpoint.execute(new BasicRequestProducer(httpget, null), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), (request, context) -> new AbstractAsyncPushHandler<Message<HttpResponse, Void>>(new BasicResponseConsumer<>(new DiscardingEntityConsumer<>())) {

                @Override
                protected void handleResponse(final HttpRequest promise, final Message<HttpResponse, Void> responseMessage) throws IOException, HttpException {
                    final HttpResponse response = responseMessage.getHead();
                    logResult(TestResult.OK, target, promise, response, "pushed / " + response.getFirstHeader("server"));
                    countDownLatch.countDown();
                }

                @Override
                protected void handleError(final HttpRequest promise, final Exception cause) {
                    logResult(TestResult.NOK, target, promise, null, "(" + cause.getMessage() + ")");
                    countDownLatch.countDown();
                }
            }, null, null);
            final Message<HttpResponse, String> message = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
            final HttpResponse response = message.getHead();
            final int code = response.getCode();
            if (code == HttpStatus.SC_OK) {
                logResult(TestResult.OK, target, httpget, response, Objects.toString(response.getFirstHeader("server")));
                if (!countDownLatch.await(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit())) {
                    logResult(TestResult.NOK, target, null, null, "Push messages not received");
                }
            } else {
                logResult(TestResult.NOK, target, httpget, response, "(status " + code + ")");
            }
        } catch (final ExecutionException ex) {
            final Throwable cause = ex.getCause();
            logResult(TestResult.NOK, target, null, null, "(" + cause.getMessage() + ")");
        } catch (final TimeoutException ex) {
            logResult(TestResult.NOK, target, null, null, "(time out)");
        }
    }
}
Also used : BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) StringAsyncEntityConsumer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer) Arrays(java.util.Arrays) H2Config(org.apache.hc.core5.http2.config.H2Config) IOReactorConfig(org.apache.hc.core5.reactor.IOReactorConfig) CharCodingConfig(org.apache.hc.core5.http.config.CharCodingConfig) LoggingConnPoolListener(org.apache.hc.core5.testing.classic.LoggingConnPoolListener) TimeoutException(java.util.concurrent.TimeoutException) AbstractAsyncPushHandler(org.apache.hc.core5.http.nio.support.AbstractAsyncPushHandler) StringAsyncEntityConsumer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer) HttpVersionPolicy(org.apache.hc.core5.http2.HttpVersionPolicy) LoggingIOSessionListener(org.apache.hc.core5.testing.nio.LoggingIOSessionListener) TextUtils(org.apache.hc.core5.util.TextUtils) Future(java.util.concurrent.Future) LoggingHttp1StreamListener(org.apache.hc.core5.testing.nio.LoggingHttp1StreamListener) CodingErrorAction(java.nio.charset.CodingErrorAction) CloseMode(org.apache.hc.core5.io.CloseMode) FutureCallback(org.apache.hc.core5.concurrent.FutureCallback) HttpResponse(org.apache.hc.core5.http.HttpResponse) HttpException(org.apache.hc.core5.http.HttpException) Message(org.apache.hc.core5.http.Message) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) LoggingH2StreamListener(org.apache.hc.core5.testing.nio.LoggingH2StreamListener) H2RequesterBootstrap(org.apache.hc.core5.http2.impl.nio.bootstrap.H2RequesterBootstrap) BasicResponseConsumer(org.apache.hc.core5.http.nio.support.BasicResponseConsumer) IOException(java.io.IOException) LoggingIOSessionDecorator(org.apache.hc.core5.testing.nio.LoggingIOSessionDecorator) StringAsyncEntityProducer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer) Timeout(org.apache.hc.core5.util.Timeout) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) BasicRequestProducer(org.apache.hc.core5.http.nio.support.BasicRequestProducer) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) HttpHost(org.apache.hc.core5.http.HttpHost) LoggingExceptionCallback(org.apache.hc.core5.testing.nio.LoggingExceptionCallback) HttpRequest(org.apache.hc.core5.http.HttpRequest) ContentType(org.apache.hc.core5.http.ContentType) AsyncClientEndpoint(org.apache.hc.core5.http.nio.AsyncClientEndpoint) HttpAsyncRequester(org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester) AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) Method(org.apache.hc.core5.http.Method) HttpStatus(org.apache.hc.core5.http.HttpStatus) DiscardingEntityConsumer(org.apache.hc.core5.http.nio.entity.DiscardingEntityConsumer) Message(org.apache.hc.core5.http.Message) AsyncClientEndpoint(org.apache.hc.core5.http.nio.AsyncClientEndpoint) BasicRequestProducer(org.apache.hc.core5.http.nio.support.BasicRequestProducer) HttpResponse(org.apache.hc.core5.http.HttpResponse) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractAsyncPushHandler(org.apache.hc.core5.http.nio.support.AbstractAsyncPushHandler) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) AsyncClientEndpoint(org.apache.hc.core5.http.nio.AsyncClientEndpoint) TimeoutException(java.util.concurrent.TimeoutException) HttpException(org.apache.hc.core5.http.HttpException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) DiscardingEntityConsumer(org.apache.hc.core5.http.nio.entity.DiscardingEntityConsumer) Future(java.util.concurrent.Future) BasicResponseConsumer(org.apache.hc.core5.http.nio.support.BasicResponseConsumer) ExecutionException(java.util.concurrent.ExecutionException) FutureCallback(org.apache.hc.core5.concurrent.FutureCallback) TimeoutException(java.util.concurrent.TimeoutException)

Example 65 with BasicResponseConsumer

use of org.apache.hc.core5.http.nio.support.BasicResponseConsumer in project httpcomponents-core by apache.

the class H2CompatibilityTest method executeHttpBin.

void executeHttpBin(final HttpHost target) throws Exception {
    {
        System.out.println("*** httpbin.org HTTP/1.1 simple request execution ***");
        final List<Message<HttpRequest, AsyncEntityProducer>> requestMessages = Arrays.asList(new Message<>(new BasicHttpRequest(Method.GET, target, "/headers"), null), new Message<>(new BasicHttpRequest(Method.POST, target, "/anything"), new StringAsyncEntityProducer("some important message", ContentType.TEXT_PLAIN)), new Message<>(new BasicHttpRequest(Method.PUT, target, "/anything"), new StringAsyncEntityProducer("some important message", ContentType.TEXT_PLAIN)), new Message<>(new BasicHttpRequest(Method.GET, target, "/drip"), null), new Message<>(new BasicHttpRequest(Method.GET, target, "/bytes/20000"), null), new Message<>(new BasicHttpRequest(Method.GET, target, "/delay/2"), null), new Message<>(new BasicHttpRequest(Method.POST, target, "/delay/2"), new StringAsyncEntityProducer("some important message", ContentType.TEXT_PLAIN)), new Message<>(new BasicHttpRequest(Method.PUT, target, "/delay/2"), new StringAsyncEntityProducer("some important message", ContentType.TEXT_PLAIN)));
        for (final Message<HttpRequest, AsyncEntityProducer> message : requestMessages) {
            final CountDownLatch countDownLatch = new CountDownLatch(1);
            final HttpRequest request = message.getHead();
            final AsyncEntityProducer entityProducer = message.getBody();
            client.execute(new BasicRequestProducer(request, entityProducer), new BasicResponseConsumer<>(new StringAsyncEntityConsumer(CharCodingConfig.custom().setCharset(StandardCharsets.US_ASCII).setMalformedInputAction(CodingErrorAction.IGNORE).setUnmappableInputAction(CodingErrorAction.REPLACE).build())), TIMEOUT, new FutureCallback<Message<HttpResponse, String>>() {

                @Override
                public void completed(final Message<HttpResponse, String> responseMessage) {
                    final HttpResponse response = responseMessage.getHead();
                    final int code = response.getCode();
                    if (code == HttpStatus.SC_OK) {
                        logResult(TestResult.OK, target, request, response, Objects.toString(response.getFirstHeader("server")));
                    } else {
                        logResult(TestResult.NOK, target, request, response, "(status " + code + ")");
                    }
                    countDownLatch.countDown();
                }

                @Override
                public void failed(final Exception ex) {
                    logResult(TestResult.NOK, target, request, null, "(" + ex.getMessage() + ")");
                    countDownLatch.countDown();
                }

                @Override
                public void cancelled() {
                    logResult(TestResult.NOK, target, request, null, "(cancelled)");
                    countDownLatch.countDown();
                }
            });
            if (!countDownLatch.await(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit())) {
                logResult(TestResult.NOK, target, null, null, "(httpbin.org tests failed to complete in time)");
            }
        }
    }
    {
        System.out.println("*** httpbin.org HTTP/1.1 pipelined request execution ***");
        final Future<AsyncClientEndpoint> connectFuture = client.connect(target, TIMEOUT);
        final AsyncClientEndpoint streamEndpoint = connectFuture.get();
        final int n = 10;
        final CountDownLatch countDownLatch = new CountDownLatch(n);
        for (int i = 0; i < n; i++) {
            final HttpRequest request;
            final AsyncEntityProducer entityProducer;
            if (i % 2 == 0) {
                request = new BasicHttpRequest(Method.GET, target, "/headers");
                entityProducer = null;
            } else {
                request = new BasicHttpRequest(Method.POST, target, "/anything");
                entityProducer = new StringAsyncEntityProducer("some important message", ContentType.TEXT_PLAIN);
            }
            streamEndpoint.execute(new BasicRequestProducer(request, entityProducer), new BasicResponseConsumer<>(new StringAsyncEntityConsumer(CharCodingConfig.custom().setCharset(StandardCharsets.US_ASCII).setMalformedInputAction(CodingErrorAction.IGNORE).setUnmappableInputAction(CodingErrorAction.REPLACE).build())), new FutureCallback<Message<HttpResponse, String>>() {

                @Override
                public void completed(final Message<HttpResponse, String> responseMessage) {
                    final HttpResponse response = responseMessage.getHead();
                    final int code = response.getCode();
                    if (code == HttpStatus.SC_OK) {
                        logResult(TestResult.OK, target, request, response, "pipelined / " + response.getFirstHeader("server"));
                    } else {
                        logResult(TestResult.NOK, target, request, response, "(status " + code + ")");
                    }
                    countDownLatch.countDown();
                }

                @Override
                public void failed(final Exception ex) {
                    logResult(TestResult.NOK, target, request, null, "(" + ex.getMessage() + ")");
                    countDownLatch.countDown();
                }

                @Override
                public void cancelled() {
                    logResult(TestResult.NOK, target, request, null, "(cancelled)");
                    countDownLatch.countDown();
                }
            });
        }
        if (!countDownLatch.await(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit())) {
            logResult(TestResult.NOK, target, null, null, "(httpbin.org tests failed to complete in time)");
        }
    }
}
Also used : BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) StringAsyncEntityConsumer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer) Message(org.apache.hc.core5.http.Message) AsyncClientEndpoint(org.apache.hc.core5.http.nio.AsyncClientEndpoint) BasicRequestProducer(org.apache.hc.core5.http.nio.support.BasicRequestProducer) StringAsyncEntityProducer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer) HttpResponse(org.apache.hc.core5.http.HttpResponse) CountDownLatch(java.util.concurrent.CountDownLatch) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) AsyncClientEndpoint(org.apache.hc.core5.http.nio.AsyncClientEndpoint) TimeoutException(java.util.concurrent.TimeoutException) HttpException(org.apache.hc.core5.http.HttpException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) StringAsyncEntityProducer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer) AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) BasicResponseConsumer(org.apache.hc.core5.http.nio.support.BasicResponseConsumer) Future(java.util.concurrent.Future) List(java.util.List) FutureCallback(org.apache.hc.core5.concurrent.FutureCallback)

Aggregations

StringAsyncEntityConsumer (org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer)94 Message (org.apache.hc.core5.http.Message)93 HttpResponse (org.apache.hc.core5.http.HttpResponse)92 BasicRequestProducer (org.apache.hc.core5.http.nio.support.BasicRequestProducer)86 InetSocketAddress (java.net.InetSocketAddress)84 Test (org.junit.Test)73 HttpRequest (org.apache.hc.core5.http.HttpRequest)41 BasicHttpRequest (org.apache.hc.core5.http.message.BasicHttpRequest)40 HttpHost (org.apache.hc.core5.http.HttpHost)38 BasicHttpResponse (org.apache.hc.core5.http.message.BasicHttpResponse)36 StringAsyncEntityProducer (org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer)30 IOException (java.io.IOException)27 ListenerEndpoint (org.apache.hc.core5.reactor.ListenerEndpoint)26 HttpException (org.apache.hc.core5.http.HttpException)25 BasicResponseConsumer (org.apache.hc.core5.http.nio.support.BasicResponseConsumer)23 InterruptedIOException (java.io.InterruptedIOException)22 Header (org.apache.hc.core5.http.Header)20 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)20 Future (java.util.concurrent.Future)18 ExecutionException (java.util.concurrent.ExecutionException)17