Search in sources :

Example 11 with StreamException

use of io.netty.handler.codec.http2.Http2Exception.StreamException in project netty by netty.

the class Http2FrameCodecTest method streamErrorShouldFireExceptionForInbound.

@Test
public void streamErrorShouldFireExceptionForInbound() throws Exception {
    frameInboundWriter.writeInboundHeaders(3, request, 31, false);
    Http2Stream stream = frameCodec.connection().stream(3);
    assertNotNull(stream);
    StreamException streamEx = new StreamException(3, Http2Error.INTERNAL_ERROR, "foo");
    channel.pipeline().fireExceptionCaught(streamEx);
    Http2FrameStreamEvent event = inboundHandler.readInboundMessageOrUserEvent();
    assertEquals(Http2FrameStreamEvent.Type.State, event.type());
    assertEquals(State.OPEN, event.stream().state());
    Http2HeadersFrame headersFrame = inboundHandler.readInboundMessageOrUserEvent();
    assertNotNull(headersFrame);
    Http2FrameStreamException e = assertThrows(Http2FrameStreamException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            inboundHandler.checkException();
        }
    });
    assertEquals(streamEx, e.getCause());
    assertNull(inboundHandler.readInboundMessageOrUserEvent());
}
Also used : Executable(org.junit.jupiter.api.function.Executable) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) Test(org.junit.jupiter.api.Test)

Example 12 with StreamException

use of io.netty.handler.codec.http2.Http2Exception.StreamException in project zuul by Netflix.

the class Http2StreamErrorHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (cause instanceof StreamException) {
        StreamException streamEx = (StreamException) cause;
        ctx.writeAndFlush(new DefaultHttp2ResetFrame(streamEx.error()));
    } else if (cause instanceof DecoderException) {
        ctx.writeAndFlush(new DefaultHttp2ResetFrame(Http2Error.PROTOCOL_ERROR));
    } else {
        super.exceptionCaught(ctx, cause);
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) DefaultHttp2ResetFrame(io.netty.handler.codec.http2.DefaultHttp2ResetFrame)

Aggregations

StreamException (io.netty.handler.codec.http2.Http2Exception.StreamException)9 Test (org.junit.jupiter.api.Test)4 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)3 Executable (org.junit.jupiter.api.function.Executable)3 Http2Exception (io.netty.handler.codec.http2.Http2Exception)2 CompositeStreamException (io.netty.handler.codec.http2.Http2Exception.CompositeStreamException)2 Test (org.junit.Test)2 RequestContext (com.linkedin.r2.message.RequestContext)1 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)1 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)1 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)1 ByteStringWriter (com.linkedin.r2.message.stream.entitystream.ByteStringWriter)1 HttpServerBuilder (com.linkedin.r2.testutils.server.HttpServerBuilder)1 FutureTransportCallback (com.linkedin.r2.transport.common.bridge.common.FutureTransportCallback)1 HttpClientBuilder (com.linkedin.r2.transport.http.client.HttpClientBuilder)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelPromise (io.netty.channel.ChannelPromise)1 DecoderException (io.netty.handler.codec.DecoderException)1 UnsupportedMessageTypeException (io.netty.handler.codec.UnsupportedMessageTypeException)1 DefaultHttp2ResetFrame (io.netty.handler.codec.http2.DefaultHttp2ResetFrame)1