Search in sources :

Example 6 with EmptyPublisher

use of software.amazon.awssdk.http.EmptyPublisher in project aws-sdk-java-v2 by aws.

the class WindowSizeTest method expectCorrectWindowSizeValueTest.

private void expectCorrectWindowSizeValueTest(Integer builderSetterValue, int settingsFrameValue) throws InterruptedException {
    ConcurrentLinkedQueue<Http2Frame> receivedFrames = new ConcurrentLinkedQueue<>();
    server = new TestH2Server(() -> new StreamHandler(receivedFrames));
    server.init();
    netty = NettyNioAsyncHttpClient.builder().protocol(Protocol.HTTP2).http2Configuration(Http2Configuration.builder().initialWindowSize(builderSetterValue).build()).build();
    AsyncExecuteRequest req = AsyncExecuteRequest.builder().requestContentPublisher(new EmptyPublisher()).request(SdkHttpFullRequest.builder().method(SdkHttpMethod.GET).protocol("http").host("localhost").port(server.port()).build()).responseHandler(new SdkAsyncHttpResponseHandler() {

        @Override
        public void onHeaders(SdkHttpResponse headers) {
        }

        @Override
        public void onStream(Publisher<ByteBuffer> stream) {
        }

        @Override
        public void onError(Throwable error) {
        }
    }).build();
    netty.execute(req).join();
    List<Http2Settings> receivedSettings = receivedFrames.stream().filter(f -> f instanceof Http2SettingsFrame).map(f -> (Http2SettingsFrame) f).map(Http2SettingsFrame::settings).collect(Collectors.toList());
    assertThat(receivedSettings.size()).isGreaterThan(0);
    for (Http2Settings s : receivedSettings) {
        assertThat(s.initialWindowSize()).isEqualTo(settingsFrameValue);
    }
}
Also used : ChannelOption(io.netty.channel.ChannelOption) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Protocol(software.amazon.awssdk.http.Protocol) Http2FrameCodecBuilder(io.netty.handler.codec.http2.Http2FrameCodecBuilder) Supplier(java.util.function.Supplier) ByteBuffer(java.nio.ByteBuffer) Http2Frame(io.netty.handler.codec.http2.Http2Frame) ServerSocketChannel(io.netty.channel.socket.ServerSocketChannel) NettyNioAsyncHttpClient(software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) After(org.junit.After) Http2DataFrame(io.netty.handler.codec.http2.Http2DataFrame) SdkHttpMethod(software.amazon.awssdk.http.SdkHttpMethod) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) EmptyPublisher(software.amazon.awssdk.http.EmptyPublisher) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) SocketChannel(io.netty.channel.socket.SocketChannel) ExpectedException(org.junit.rules.ExpectedException) Http2Configuration(software.amazon.awssdk.http.nio.netty.Http2Configuration) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) ChannelInitializer(io.netty.channel.ChannelInitializer) Publisher(org.reactivestreams.Publisher) DefaultHttp2HeadersFrame(io.netty.handler.codec.http2.DefaultHttp2HeadersFrame) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Http2FrameCodec(io.netty.handler.codec.http2.Http2FrameCodec) Test(org.junit.Test) Collectors(java.util.stream.Collectors) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Http2HeadersFrame(io.netty.handler.codec.http2.Http2HeadersFrame) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) Http2Settings(io.netty.handler.codec.http2.Http2Settings) List(java.util.List) Rule(org.junit.Rule) ReferenceCountUtil(io.netty.util.ReferenceCountUtil) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelHandler(io.netty.channel.ChannelHandler) Http2SettingsFrame(io.netty.handler.codec.http2.Http2SettingsFrame) Queue(java.util.Queue) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Http2SettingsFrame(io.netty.handler.codec.http2.Http2SettingsFrame) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) EmptyPublisher(software.amazon.awssdk.http.EmptyPublisher) Publisher(org.reactivestreams.Publisher) Http2Frame(io.netty.handler.codec.http2.Http2Frame) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) EmptyPublisher(software.amazon.awssdk.http.EmptyPublisher) Http2Settings(io.netty.handler.codec.http2.Http2Settings) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 7 with EmptyPublisher

use of software.amazon.awssdk.http.EmptyPublisher in project aws-sdk-java-v2 by aws.

the class NettyClientTlsAuthTest method sendRequest.

private void sendRequest(SdkAsyncHttpClient client, SdkAsyncHttpResponseHandler responseHandler) {
    AsyncExecuteRequest req = AsyncExecuteRequest.builder().request(testSdkRequest()).requestContentPublisher(new EmptyPublisher()).responseHandler(responseHandler).build();
    client.execute(req).join();
}
Also used : AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) EmptyPublisher(software.amazon.awssdk.http.EmptyPublisher)

Example 8 with EmptyPublisher

use of software.amazon.awssdk.http.EmptyPublisher in project aws-sdk-java-v2 by aws.

the class NettyNioAsyncHttpClientSpiVerificationTest method callsOnStreamForEmptyResponseContent.

@Test
public void callsOnStreamForEmptyResponseContent() throws Exception {
    stubFor(any(urlEqualTo("/")).willReturn(aResponse().withStatus(204).withHeader("foo", "bar")));
    CompletableFuture<Boolean> streamReceived = new CompletableFuture<>();
    SdkAsyncHttpResponseHandler handler = new TestResponseHandler() {

        @Override
        public void onStream(Publisher<ByteBuffer> stream) {
            super.onStream(stream);
            streamReceived.complete(true);
        }
    };
    SdkHttpRequest request = createRequest(URI.create("http://localhost:" + mockServer.port()));
    client.execute(AsyncExecuteRequest.builder().request(request).responseHandler(handler).requestContentPublisher(new EmptyPublisher()).build());
    assertThat(streamReceived.get(1, TimeUnit.SECONDS)).isTrue();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) EmptyPublisher(software.amazon.awssdk.http.EmptyPublisher) EmptyPublisher(software.amazon.awssdk.http.EmptyPublisher) Publisher(org.reactivestreams.Publisher) Test(org.junit.Test)

Example 9 with EmptyPublisher

use of software.amazon.awssdk.http.EmptyPublisher in project aws-sdk-java-v2 by aws.

the class ProxyWireMockTest method proxyConfigured_hostInNonProxySet_doesNotConnect.

@Test
public void proxyConfigured_hostInNonProxySet_doesNotConnect() {
    RecordingResponseHandler responseHandler = new RecordingResponseHandler();
    AsyncExecuteRequest req = AsyncExecuteRequest.builder().request(testSdkRequest()).responseHandler(responseHandler).requestContentPublisher(new EmptyPublisher()).build();
    ProxyConfiguration cfg = proxyCfg.toBuilder().nonProxyHosts(Stream.of("localhost").collect(Collectors.toSet())).build();
    client = NettyNioAsyncHttpClient.builder().proxyConfiguration(cfg).build();
    client.execute(req).join();
    responseHandler.completeFuture.join();
    assertThat(responseHandler.fullResponseAsString()).isEqualTo("hello");
}
Also used : AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) EmptyPublisher(software.amazon.awssdk.http.EmptyPublisher) Test(org.junit.Test)

Aggregations

EmptyPublisher (software.amazon.awssdk.http.EmptyPublisher)9 Test (org.junit.Test)5 AsyncExecuteRequest (software.amazon.awssdk.http.async.AsyncExecuteRequest)5 SdkAsyncHttpResponseHandler (software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler)5 Publisher (org.reactivestreams.Publisher)4 ByteBuffer (java.nio.ByteBuffer)3 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)3 SdkHttpResponse (software.amazon.awssdk.http.SdkHttpResponse)3 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)2 ChannelHandler (io.netty.channel.ChannelHandler)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)2 ChannelInitializer (io.netty.channel.ChannelInitializer)2 ChannelOption (io.netty.channel.ChannelOption)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 ServerSocketChannel (io.netty.channel.socket.ServerSocketChannel)2 SocketChannel (io.netty.channel.socket.SocketChannel)2 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)2 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)2 DefaultHttp2HeadersFrame (io.netty.handler.codec.http2.DefaultHttp2HeadersFrame)2