Search in sources :

Example 1 with StringAsyncEntityProducer

use of org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer in project httpcomponents-core by apache.

the class H2AlpnTest method testALPN.

@Test
public void testALPN() throws Exception {
    server.start();
    final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
    final ListenerEndpoint listener = future.get();
    final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
    requester.start();
    final HttpHost target = new HttpHost(URIScheme.HTTPS.id, "localhost", address.getPort());
    final Future<Message<HttpResponse, String>> resultFuture1 = requester.execute(new BasicRequestProducer(Method.POST, target, "/stuff", new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null);
    final Message<HttpResponse, String> message1;
    try {
        message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
    } catch (final ExecutionException e) {
        final Throwable cause = e.getCause();
        assertFalse(h2Allowed, "h2 negotiation was enabled, but h2 was not negotiated");
        assertTrue(cause instanceof ProtocolNegotiationException);
        assertEquals("ALPN: missing application protocol", cause.getMessage());
        assertTrue(strictALPN, "strict ALPN mode was not enabled, but the client negotiator still threw");
        return;
    }
    assertTrue(h2Allowed, "h2 negotiation was disabled, but h2 was negotiated");
    assertThat(message1, CoreMatchers.notNullValue());
    final HttpResponse response1 = message1.getHead();
    assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
    final String body1 = message1.getBody();
    assertThat(body1, CoreMatchers.equalTo("some stuff"));
}
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) StringAsyncEntityProducer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer) HttpResponse(org.apache.hc.core5.http.HttpResponse) ListenerEndpoint(org.apache.hc.core5.reactor.ListenerEndpoint) HttpHost(org.apache.hc.core5.http.HttpHost) ProtocolNegotiationException(org.apache.hc.core5.http2.impl.nio.ProtocolNegotiationException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with StringAsyncEntityProducer

use of org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer in project httpcomponents-core by apache.

the class H2IntegrationTest method testMessageWithTrailers.

@Test
public void testMessageWithTrailers() throws Exception {
    server.register("/hello", () -> new AbstractServerExchangeHandler<Message<HttpRequest, String>>() {

        @Override
        protected AsyncRequestConsumer<Message<HttpRequest, String>> supplyConsumer(final HttpRequest request, final EntityDetails entityDetails, final HttpContext context) throws HttpException {
            return new BasicRequestConsumer<>(entityDetails != null ? new StringAsyncEntityConsumer() : null);
        }

        @Override
        protected void handle(final Message<HttpRequest, String> requestMessage, final AsyncServerRequestHandler.ResponseTrigger responseTrigger, final HttpContext context) throws HttpException, IOException {
            responseTrigger.submitResponse(new BasicResponseProducer(HttpStatus.SC_OK, new DigestingEntityProducer("MD5", new StringAsyncEntityProducer("Hello back with some trailers"))), context);
        }
    });
    final InetSocketAddress serverEndpoint = server.start();
    client.start();
    final Future<ClientSessionEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), TIMEOUT);
    final ClientSessionEndpoint streamEndpoint = connectFuture.get();
    final HttpRequest request1 = new BasicHttpRequest(Method.GET, createRequestURI(serverEndpoint, "/hello"));
    final DigestingEntityConsumer<String> entityConsumer = new DigestingEntityConsumer<>("MD5", new StringAsyncEntityConsumer());
    final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(new BasicRequestProducer(request1, null), new BasicResponseConsumer<>(entityConsumer), 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(200, response1.getCode());
    Assertions.assertEquals("Hello back with some trailers", result1.getBody());
    final List<Header> trailers = entityConsumer.getTrailers();
    Assertions.assertNotNull(trailers);
    Assertions.assertEquals(2, trailers.size());
    final Map<String, String> map = new HashMap<>();
    for (final Header header : trailers) {
        map.put(TextUtils.toLowerCase(header.getName()), header.getValue());
    }
    final String digest = TextUtils.toHexString(entityConsumer.getDigest());
    Assertions.assertEquals("MD5", map.get("digest-algo"));
    Assertions.assertEquals(digest, map.get("digest"));
}
Also used : Message(org.apache.hc.core5.http.Message) DigestingEntityProducer(org.apache.hc.core5.http.nio.entity.DigestingEntityProducer) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) StringAsyncEntityProducer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) EntityDetails(org.apache.hc.core5.http.EntityDetails) HttpException(org.apache.hc.core5.http.HttpException) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) StringAsyncEntityConsumer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer) DigestingEntityConsumer(org.apache.hc.core5.http.nio.entity.DigestingEntityConsumer) BasicRequestProducer(org.apache.hc.core5.http.nio.support.BasicRequestProducer) HttpContext(org.apache.hc.core5.http.protocol.HttpContext) HttpResponse(org.apache.hc.core5.http.HttpResponse) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) AsyncRequestConsumer(org.apache.hc.core5.http.nio.AsyncRequestConsumer) AsyncServerRequestHandler(org.apache.hc.core5.http.nio.AsyncServerRequestHandler) Header(org.apache.hc.core5.http.Header) BasicResponseProducer(org.apache.hc.core5.http.nio.support.BasicResponseProducer) Test(org.junit.Test)

Example 3 with StringAsyncEntityProducer

use of org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer in project httpcomponents-core by apache.

the class H2IntegrationTest method testBasicPost.

@Test
public void testBasicPost() throws Exception {
    server.register("/hello", () -> new SingleLineResponseHandler("Hi back"));
    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 < 10; i++) {
        final HttpRequest request = new BasicHttpRequest(Method.POST, createRequestURI(serverEndpoint, "/hello"));
        queue.add(streamEndpoint.execute(new BasicRequestProducer(request, new StringAsyncEntityProducer("Hi there", ContentType.TEXT_PLAIN)), 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();
        final String entity1 = result.getBody();
        Assertions.assertNotNull(response);
        Assertions.assertEquals(200, response.getCode());
        Assertions.assertEquals("Hi back", entity1);
    }
}
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) StringAsyncEntityProducer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer) HttpResponse(org.apache.hc.core5.http.HttpResponse) LinkedList(java.util.LinkedList) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) Future(java.util.concurrent.Future) BasicResponseConsumer(org.apache.hc.core5.http.nio.support.BasicResponseConsumer) Test(org.junit.Test)

Example 4 with StringAsyncEntityProducer

use of org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer in project httpcomponents-core by apache.

the class Http1IntegrationTest method testTruncatedChunk.

@Test
public void testTruncatedChunk() throws Exception {
    final InetSocketAddress serverEndpoint = server.start(new InternalServerHttp1EventHandlerFactory(HttpProcessors.server(), (request, context) -> new MessageExchangeHandler<String>(new StringAsyncEntityConsumer()) {

        @Override
        protected void handle(final Message<HttpRequest, String> request, final AsyncServerRequestHandler.ResponseTrigger responseTrigger, final HttpContext context) throws IOException, HttpException {
            responseTrigger.submitResponse(new BasicResponseProducer(new StringAsyncEntityProducer("useful stuff")), context);
        }
    }, Http1Config.DEFAULT, CharCodingConfig.DEFAULT, DefaultConnectionReuseStrategy.INSTANCE, scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null, null, null) {

        @Override
        protected ServerHttp1StreamDuplexer createServerHttp1StreamDuplexer(final ProtocolIOSession ioSession, final HttpProcessor httpProcessor, final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory, final Http1Config http1Config, final CharCodingConfig connectionConfig, final ConnectionReuseStrategy connectionReuseStrategy, final NHttpMessageParser<HttpRequest> incomingMessageParser, final NHttpMessageWriter<HttpResponse> outgoingMessageWriter, final ContentLengthStrategy incomingContentStrategy, final ContentLengthStrategy outgoingContentStrategy, final Http1StreamListener streamListener) {
            return new ServerHttp1StreamDuplexer(ioSession, httpProcessor, exchangeHandlerFactory, scheme.id, http1Config, connectionConfig, connectionReuseStrategy, incomingMessageParser, outgoingMessageWriter, incomingContentStrategy, outgoingContentStrategy, streamListener) {

                @Override
                protected ContentEncoder createContentEncoder(final long len, final WritableByteChannel channel, final SessionOutputBuffer buffer, final BasicHttpTransportMetrics metrics) throws HttpException {
                    if (len == ContentLengthStrategy.CHUNKED) {
                        return new BrokenChunkEncoder(channel, buffer, metrics);
                    } else {
                        return super.createContentEncoder(len, channel, buffer, metrics);
                    }
                }
            };
        }
    });
    client.start();
    final Future<ClientSessionEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), TIMEOUT);
    final ClientSessionEndpoint streamEndpoint = connectFuture.get();
    final AsyncRequestProducer requestProducer = new BasicRequestProducer(Method.GET, createRequestURI(serverEndpoint, "/hello"));
    final StringAsyncEntityConsumer entityConsumer = new StringAsyncEntityConsumer() {

        @Override
        public void releaseResources() {
        // Do not clear internal content buffer
        }
    };
    final BasicResponseConsumer<String> responseConsumer = new BasicResponseConsumer<>(entityConsumer);
    final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(requestProducer, responseConsumer, null);
    final ExecutionException exception = Assertions.assertThrows(ExecutionException.class, () -> future1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()));
    final Throwable cause = exception.getCause();
    Assertions.assertTrue(cause instanceof MalformedChunkCodingException);
    Assertions.assertEquals("garbage", entityConsumer.generateContent());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) BasicResponseProducer(org.apache.hc.core5.http.nio.support.BasicResponseProducer) IOReactorConfig(org.apache.hc.core5.reactor.IOReactorConfig) CharCodingConfig(org.apache.hc.core5.http.config.CharCodingConfig) BasicAsyncServerExpectationDecorator(org.apache.hc.core5.http.nio.support.BasicAsyncServerExpectationDecorator) StringAsyncEntityConsumer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer) AbstractClassicEntityProducer(org.apache.hc.core5.http.nio.support.classic.AbstractClassicEntityProducer) HttpProcessor(org.apache.hc.core5.http.protocol.HttpProcessor) Future(java.util.concurrent.Future) Map(java.util.Map) DigestingEntityProducer(org.apache.hc.core5.http.nio.entity.DigestingEntityProducer) AbstractClassicServerExchangeHandler(org.apache.hc.core5.http.nio.support.classic.AbstractClassicServerExchangeHandler) RequestConnControl(org.apache.hc.core5.http.protocol.RequestConnControl) CancellationException(java.util.concurrent.CancellationException) DataStreamChannel(org.apache.hc.core5.http.nio.DataStreamChannel) HandlerFactory(org.apache.hc.core5.http.nio.HandlerFactory) ContentLengthStrategy(org.apache.hc.core5.http.ContentLengthStrategy) ConnectionReuseStrategy(org.apache.hc.core5.http.ConnectionReuseStrategy) Timeout(org.apache.hc.core5.util.Timeout) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) MalformedChunkCodingException(org.apache.hc.core5.http.MalformedChunkCodingException) HeaderElements(org.apache.hc.core5.http.HeaderElements) CapacityChannel(org.apache.hc.core5.http.nio.CapacityChannel) HttpContext(org.apache.hc.core5.http.protocol.HttpContext) AsyncServerRequestHandler(org.apache.hc.core5.http.nio.AsyncServerRequestHandler) RunWith(org.junit.runner.RunWith) InterruptedIOException(java.io.InterruptedIOException) NHttpMessageParser(org.apache.hc.core5.http.nio.NHttpMessageParser) EntityDetails(org.apache.hc.core5.http.EntityDetails) HttpVersion(org.apache.hc.core5.http.HttpVersion) StringTokenizer(java.util.StringTokenizer) RequestTargetHost(org.apache.hc.core5.http.protocol.RequestTargetHost) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NHttpMessageWriter(org.apache.hc.core5.http.nio.NHttpMessageWriter) SessionOutputBuffer(org.apache.hc.core5.http.nio.SessionOutputBuffer) AsyncResponseProducer(org.apache.hc.core5.http.nio.AsyncResponseProducer) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) ImmediateResponseExchangeHandler(org.apache.hc.core5.http.nio.support.ImmediateResponseExchangeHandler) BufferedWriter(java.io.BufferedWriter) IOException(java.io.IOException) Test(org.junit.Test) InputStreamReader(java.io.InputStreamReader) URIScheme(org.apache.hc.core5.http.URIScheme) ExecutionException(java.util.concurrent.ExecutionException) BasicRequestProducer(org.apache.hc.core5.http.nio.support.BasicRequestProducer) HttpHeaders(org.apache.hc.core5.http.HttpHeaders) AfterEach(org.junit.jupiter.api.AfterEach) HttpHost(org.apache.hc.core5.http.HttpHost) HttpRequest(org.apache.hc.core5.http.HttpRequest) ContentType(org.apache.hc.core5.http.ContentType) WritableByteChannel(java.nio.channels.WritableByteChannel) AsyncRequestProducer(org.apache.hc.core5.http.nio.AsyncRequestProducer) BufferedReader(java.io.BufferedReader) HttpStatus(org.apache.hc.core5.http.HttpStatus) AsyncEntityProducers(org.apache.hc.core5.http.nio.entity.AsyncEntityProducers) CoreMatchers(org.hamcrest.CoreMatchers) AsyncRequestBuilder(org.apache.hc.core5.http.nio.support.AsyncRequestBuilder) RequestContent(org.apache.hc.core5.http.protocol.RequestContent) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) BasicHttpTransportMetrics(org.apache.hc.core5.http.impl.BasicHttpTransportMetrics) ByteBuffer(java.nio.ByteBuffer) AbstractClassicEntityConsumer(org.apache.hc.core5.http.nio.support.classic.AbstractClassicEntityConsumer) HttpProcessors(org.apache.hc.core5.http.impl.HttpProcessors) URI(java.net.URI) Http1Config(org.apache.hc.core5.http.config.Http1Config) EnableRuleMigrationSupport(org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport) AsyncServerExchangeHandler(org.apache.hc.core5.http.nio.AsyncServerExchangeHandler) RequestValidateHost(org.apache.hc.core5.http.protocol.RequestValidateHost) Parameterized(org.junit.runners.Parameterized) Message(org.apache.hc.core5.http.Message) TimeValue(org.apache.hc.core5.util.TimeValue) Collection(java.util.Collection) BasicResponseConsumer(org.apache.hc.core5.http.nio.support.BasicResponseConsumer) InetSocketAddress(java.net.InetSocketAddress) StringAsyncEntityProducer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer) List(java.util.List) ContentEncoder(org.apache.hc.core5.http.nio.ContentEncoder) SSLTestContexts(org.apache.hc.core5.testing.SSLTestContexts) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) ProtocolIOSession(org.apache.hc.core5.reactor.ProtocolIOSession) Queue(java.util.Queue) DefaultConnectionReuseStrategy(org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy) AbstractContentEncoder(org.apache.hc.core5.http.impl.nio.AbstractContentEncoder) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ResponseChannel(org.apache.hc.core5.http.nio.ResponseChannel) TextUtils(org.apache.hc.core5.util.TextUtils) AsyncRequestConsumer(org.apache.hc.core5.http.nio.AsyncRequestConsumer) Charset(java.nio.charset.Charset) OutputStreamWriter(java.io.OutputStreamWriter) ServerHttp1StreamDuplexer(org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexer) HttpResponse(org.apache.hc.core5.http.HttpResponse) LinkedList(java.util.LinkedList) Http1StreamListener(org.apache.hc.core5.http.impl.Http1StreamListener) DefaultHttpProcessor(org.apache.hc.core5.http.protocol.DefaultHttpProcessor) OutputStream(java.io.OutputStream) HttpException(org.apache.hc.core5.http.HttpException) Logger(org.slf4j.Logger) Header(org.apache.hc.core5.http.Header) ProtocolException(org.apache.hc.core5.http.ProtocolException) BasicRequestConsumer(org.apache.hc.core5.http.nio.support.BasicRequestConsumer) AbstractServerExchangeHandler(org.apache.hc.core5.http.nio.support.AbstractServerExchangeHandler) DigestingEntityConsumer(org.apache.hc.core5.http.nio.entity.DigestingEntityConsumer) AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) IOSession(org.apache.hc.core5.reactor.IOSession) Method(org.apache.hc.core5.http.Method) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) Assertions(org.junit.jupiter.api.Assertions) InputStream(java.io.InputStream) CharCodingConfig(org.apache.hc.core5.http.config.CharCodingConfig) Message(org.apache.hc.core5.http.Message) InetSocketAddress(java.net.InetSocketAddress) ProtocolIOSession(org.apache.hc.core5.reactor.ProtocolIOSession) HttpProcessor(org.apache.hc.core5.http.protocol.HttpProcessor) DefaultHttpProcessor(org.apache.hc.core5.http.protocol.DefaultHttpProcessor) StringAsyncEntityProducer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer) Http1StreamListener(org.apache.hc.core5.http.impl.Http1StreamListener) AsyncRequestProducer(org.apache.hc.core5.http.nio.AsyncRequestProducer) SessionOutputBuffer(org.apache.hc.core5.http.nio.SessionOutputBuffer) BasicResponseConsumer(org.apache.hc.core5.http.nio.support.BasicResponseConsumer) HttpException(org.apache.hc.core5.http.HttpException) ExecutionException(java.util.concurrent.ExecutionException) AsyncServerExchangeHandler(org.apache.hc.core5.http.nio.AsyncServerExchangeHandler) StringAsyncEntityConsumer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) MalformedChunkCodingException(org.apache.hc.core5.http.MalformedChunkCodingException) ServerHttp1StreamDuplexer(org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexer) ContentEncoder(org.apache.hc.core5.http.nio.ContentEncoder) AbstractContentEncoder(org.apache.hc.core5.http.impl.nio.AbstractContentEncoder) BasicRequestProducer(org.apache.hc.core5.http.nio.support.BasicRequestProducer) HttpContext(org.apache.hc.core5.http.protocol.HttpContext) WritableByteChannel(java.nio.channels.WritableByteChannel) HttpResponse(org.apache.hc.core5.http.HttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) ContentLengthStrategy(org.apache.hc.core5.http.ContentLengthStrategy) BasicHttpTransportMetrics(org.apache.hc.core5.http.impl.BasicHttpTransportMetrics) ConnectionReuseStrategy(org.apache.hc.core5.http.ConnectionReuseStrategy) DefaultConnectionReuseStrategy(org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy) BasicResponseProducer(org.apache.hc.core5.http.nio.support.BasicResponseProducer) Http1Config(org.apache.hc.core5.http.config.Http1Config) Test(org.junit.Test)

Example 5 with StringAsyncEntityProducer

use of org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer in project httpcomponents-core by apache.

the class H2ProtocolNegotiationTest method testNegotiateProtocol.

@Test
public void testNegotiateProtocol() throws Exception {
    server.start();
    final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
    final ListenerEndpoint listener = future.get();
    final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
    requester.start();
    final HttpHost target = new HttpHost(URIScheme.HTTPS.id, "localhost", address.getPort());
    final Future<AsyncClientEndpoint> connectFuture = requester.connect(target, TIMEOUT, HttpVersionPolicy.NEGOTIATE, null);
    final AsyncClientEndpoint endpoint = connectFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
    final Future<Message<HttpResponse, String>> resultFuture1 = endpoint.execute(new BasicRequestProducer(Method.POST, target, "/stuff", new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
    final Message<HttpResponse, String> message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
    assertThat(message1, CoreMatchers.notNullValue());
    final HttpResponse response1 = message1.getHead();
    assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
    assertThat(response1.getVersion(), CoreMatchers.equalTo(HttpVersion.HTTP_2));
}
Also used : StringAsyncEntityConsumer(org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer) Message(org.apache.hc.core5.http.Message) AsyncClientEndpoint(org.apache.hc.core5.http.nio.AsyncClientEndpoint) InetSocketAddress(java.net.InetSocketAddress) 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) ListenerEndpoint(org.apache.hc.core5.reactor.ListenerEndpoint) HttpHost(org.apache.hc.core5.http.HttpHost) Test(org.junit.jupiter.api.Test)

Aggregations

StringAsyncEntityProducer (org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer)29 Message (org.apache.hc.core5.http.Message)28 StringAsyncEntityConsumer (org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer)28 BasicRequestProducer (org.apache.hc.core5.http.nio.support.BasicRequestProducer)28 InetSocketAddress (java.net.InetSocketAddress)27 HttpResponse (org.apache.hc.core5.http.HttpResponse)24 HttpHost (org.apache.hc.core5.http.HttpHost)23 ListenerEndpoint (org.apache.hc.core5.reactor.ListenerEndpoint)22 Test (org.junit.Test)17 Test (org.junit.jupiter.api.Test)13 IOException (java.io.IOException)8 ExecutionException (java.util.concurrent.ExecutionException)8 AsyncClientEndpoint (org.apache.hc.core5.http.nio.AsyncClientEndpoint)8 BasicHttpRequest (org.apache.hc.core5.http.message.BasicHttpRequest)7 BasicResponseConsumer (org.apache.hc.core5.http.nio.support.BasicResponseConsumer)7 Future (java.util.concurrent.Future)6 Header (org.apache.hc.core5.http.Header)6 HttpRequest (org.apache.hc.core5.http.HttpRequest)6 LinkedList (java.util.LinkedList)5 HttpException (org.apache.hc.core5.http.HttpException)5