Search in sources :

Example 11 with StreamResetException

use of io.vertx.core.http.StreamResetException in project vert.x by eclipse.

the class Http2ClientTest method testClientResetServerStreamDuringResponse.

@Test
public void testClientResetServerStreamDuringResponse() throws Exception {
    server.requestHandler(req -> {
        req.exceptionHandler(err -> {
            assertTrue(err instanceof StreamResetException);
        });
        req.response().exceptionHandler(err -> {
            assertTrue(err instanceof StreamResetException);
            assertEquals(10L, ((StreamResetException) err).getCode());
            testComplete();
        });
        req.response().setChunked(true).write(Buffer.buffer("some-data"));
    });
    startServer();
    HttpClientRequest req = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath");
    req.handler(resp -> {
        resp.exceptionHandler(this::fail);
        req.reset(10);
        assertIllegalStateException(() -> req.write(Buffer.buffer()));
        assertIllegalStateException(req::end);
    }).end(Buffer.buffer("hello"));
    await();
}
Also used : Arrays(java.util.Arrays) JksOptions(io.vertx.core.net.JksOptions) BiFunction(java.util.function.BiFunction) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) AsciiString(io.netty.util.AsciiString) Cert(io.vertx.test.core.tls.Cert) Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2Exception(io.netty.handler.codec.http2.Http2Exception) ApplicationProtocolNegotiationHandler(io.netty.handler.ssl.ApplicationProtocolNegotiationHandler) AbstractHttp2ConnectionHandlerBuilder(io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder) StreamResetException(io.vertx.core.http.StreamResetException) ChannelInitializer(io.netty.channel.ChannelInitializer) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Set(java.util.Set) ChannelPipeline(io.netty.channel.ChannelPipeline) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) Http2FrameListener(io.netty.handler.codec.http2.Http2FrameListener) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) SslHandler(io.netty.handler.ssl.SslHandler) Http2Headers(io.netty.handler.codec.http2.Http2Headers) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Http2Error(io.netty.handler.codec.http2.Http2Error) GZIPOutputStream(java.util.zip.GZIPOutputStream) NetSocket(io.vertx.core.net.NetSocket) Trust(io.vertx.test.core.tls.Trust) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) io.vertx.core(io.vertx.core) Http2EventAdapter(io.netty.handler.codec.http2.Http2EventAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpClientRequest(io.vertx.core.http.HttpClientRequest) ByteBuf(io.netty.buffer.ByteBuf) ConnectException(java.net.ConnectException) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpConnection(io.vertx.core.http.HttpConnection) SocketAddress(io.vertx.core.net.SocketAddress) EventLoopGroup(io.netty.channel.EventLoopGroup) VertxInternal(io.vertx.core.impl.VertxInternal) ApplicationProtocolNames(io.netty.handler.ssl.ApplicationProtocolNames) Test(org.junit.Test) SSLHelper(io.vertx.core.net.impl.SSLHelper) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) Http2Settings(io.netty.handler.codec.http2.Http2Settings) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Http2ServerUpgradeCodec(io.netty.handler.codec.http2.Http2ServerUpgradeCodec) HttpMethod(io.vertx.core.http.HttpMethod) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) Collections(java.util.Collections) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) Http2CodecUtil(io.netty.handler.codec.http2.Http2CodecUtil) HttpServerUpgradeHandler(io.netty.handler.codec.http.HttpServerUpgradeHandler) HttpClientRequest(io.vertx.core.http.HttpClientRequest) StreamResetException(io.vertx.core.http.StreamResetException) Test(org.junit.Test)

Example 12 with StreamResetException

use of io.vertx.core.http.StreamResetException in project vert.x by eclipse.

the class Http2ServerResponseImpl method callReset.

void callReset(long code) {
    handleEnded(true);
    handleError(new StreamResetException(code));
}
Also used : StreamResetException(io.vertx.core.http.StreamResetException)

Aggregations

StreamResetException (io.vertx.core.http.StreamResetException)12 Test (org.junit.Test)8 HttpClientRequest (io.vertx.core.http.HttpClientRequest)7 ChannelFuture (io.netty.channel.ChannelFuture)5 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)5 Http2ConnectionEncoder (io.netty.handler.codec.http2.Http2ConnectionEncoder)5 HttpServerResponse (io.vertx.core.http.HttpServerResponse)5 ByteBuf (io.netty.buffer.ByteBuf)4 Channel (io.netty.channel.Channel)4 ChannelInitializer (io.netty.channel.ChannelInitializer)4 ChannelPipeline (io.netty.channel.ChannelPipeline)4 EventLoopGroup (io.netty.channel.EventLoopGroup)4 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)4 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)4 AbstractHttp2ConnectionHandlerBuilder (io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder)4 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)4 Http2ConnectionDecoder (io.netty.handler.codec.http2.Http2ConnectionDecoder)4 Http2ConnectionHandler (io.netty.handler.codec.http2.Http2ConnectionHandler)4 Http2Error (io.netty.handler.codec.http2.Http2Error)4 Http2EventAdapter (io.netty.handler.codec.http2.Http2EventAdapter)4