Search in sources :

Example 1 with StreamException

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

the class Http2ConnectionHandler method onError.

/**
     * Central handler for all exceptions caught during HTTP/2 processing.
     */
@Override
public void onError(ChannelHandlerContext ctx, Throwable cause) {
    Http2Exception embedded = getEmbeddedHttp2Exception(cause);
    if (isStreamError(embedded)) {
        onStreamError(ctx, cause, (StreamException) embedded);
    } else if (embedded instanceof CompositeStreamException) {
        CompositeStreamException compositException = (CompositeStreamException) embedded;
        for (StreamException streamException : compositException) {
            onStreamError(ctx, cause, streamException);
        }
    } else {
        onConnectionError(ctx, cause, embedded);
    }
    ctx.flush();
}
Also used : Http2CodecUtil.getEmbeddedHttp2Exception(io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception) CompositeStreamException(io.netty.handler.codec.http2.Http2Exception.CompositeStreamException) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) CompositeStreamException(io.netty.handler.codec.http2.Http2Exception.CompositeStreamException)

Example 2 with StreamException

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

the class Http2MultiplexCodec method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (!(msg instanceof Http2Frame)) {
        ctx.fireChannelRead(msg);
        return;
    }
    if (msg instanceof Http2StreamFrame) {
        Http2StreamFrame frame = (Http2StreamFrame) msg;
        int streamId = frame.streamId();
        Http2StreamChannel childChannel = childChannels.get(streamId);
        if (childChannel == null) {
            // TODO: Combine with DefaultHttp2ConnectionDecoder.shouldIgnoreHeadersOrDataFrame logic.
            ReferenceCountUtil.release(msg);
            throw new StreamException(streamId, STREAM_CLOSED, format("Received %s frame for an unknown stream %d", frame.name(), streamId));
        }
        fireChildReadAndRegister(childChannel, frame);
    } else if (msg instanceof Http2GoAwayFrame) {
        Http2GoAwayFrame goAwayFrame = (Http2GoAwayFrame) msg;
        for (PrimitiveEntry<Http2StreamChannel> entry : childChannels.entries()) {
            Http2StreamChannel childChannel = entry.value();
            int streamId = entry.key();
            if (streamId > goAwayFrame.lastStreamId() && isOutboundStream(server, streamId)) {
                childChannel.pipeline().fireUserEventTriggered(goAwayFrame.retainedDuplicate());
            }
        }
        goAwayFrame.release();
    } else {
        // It's safe to release, as UnsupportedMessageTypeException just calls msg.getClass()
        ReferenceCountUtil.release(msg);
        throw new UnsupportedMessageTypeException(msg);
    }
}
Also used : PrimitiveEntry(io.netty.util.collection.IntObjectMap.PrimitiveEntry) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) UnsupportedMessageTypeException(io.netty.handler.codec.UnsupportedMessageTypeException)

Example 3 with StreamException

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

the class Http2StreamCodec method onError.

@Override
public void onError(ChannelHandlerContext ctx, Throwable cause) {
    super.onError(ctx, cause);
    Http2Exception http2Exception = getEmbeddedHttp2Exception(cause);
    if (http2Exception == null) {
        doHandleConnectionException(ctx, cause);
    } else {
        if (http2Exception instanceof Http2Exception.StreamException) {
            Http2Exception.StreamException streamException = (Http2Exception.StreamException) http2Exception;
            doHandleStreamException(connection().stream(streamException.streamId()), ctx, streamException);
        } else if (http2Exception instanceof Http2Exception.CompositeStreamException) {
            Http2Exception.CompositeStreamException compositException = (Http2Exception.CompositeStreamException) http2Exception;
            for (Http2Exception.StreamException streamException : compositException) {
                doHandleStreamException(connection().stream(streamException.streamId()), ctx, streamException);
            }
        } else {
            doHandleConnectionException(ctx, http2Exception);
        }
    }
}
Also used : Http2CodecUtil.getEmbeddedHttp2Exception(io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception) Http2Exception(io.netty.handler.codec.http2.Http2Exception)

Example 4 with StreamException

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

the class Http2MultiplexTest method streamClosedErrorTranslatedToClosedChannelExceptionOnWrites.

@Test
public void streamClosedErrorTranslatedToClosedChannelExceptionOnWrites() throws Exception {
    LastInboundHandler inboundHandler = new LastInboundHandler();
    final Http2StreamChannel childChannel = newOutboundStream(inboundHandler);
    assertTrue(childChannel.isActive());
    Http2Headers headers = new DefaultHttp2Headers();
    when(frameWriter.writeHeaders(eqCodecCtx(), anyInt(), eq(headers), anyInt(), anyBoolean(), any(ChannelPromise.class))).thenAnswer(new Answer<ChannelFuture>() {

        @Override
        public ChannelFuture answer(InvocationOnMock invocationOnMock) {
            return ((ChannelPromise) invocationOnMock.getArgument(5)).setFailure(new StreamException(childChannel.stream().id(), Http2Error.STREAM_CLOSED, "Stream Closed"));
        }
    });
    final ChannelFuture future = childChannel.writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers()));
    parentChannel.flush();
    assertFalse(childChannel.isActive());
    assertFalse(childChannel.isOpen());
    inboundHandler.checkException();
    assertThrows(ClosedChannelException.class, new Executable() {

        @Override
        public void execute() {
            future.syncUninterruptibly();
        }
    });
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ChannelPromise(io.netty.channel.ChannelPromise) Http2TestUtil.anyChannelPromise(io.netty.handler.codec.http2.Http2TestUtil.anyChannelPromise) Executable(org.junit.jupiter.api.function.Executable) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) Test(org.junit.jupiter.api.Test)

Example 5 with StreamException

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

the class Http2FrameCodecTest method streamErrorShouldNotFireExceptionForOutbound.

@Test
public void streamErrorShouldNotFireExceptionForOutbound() 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");
    frameCodec.onError(frameCodec.ctx, true, streamEx);
    Http2FrameStreamEvent event = inboundHandler.readInboundMessageOrUserEvent();
    assertEquals(Http2FrameStreamEvent.Type.State, event.type());
    assertEquals(State.OPEN, event.stream().state());
    Http2HeadersFrame headersFrame = inboundHandler.readInboundMessageOrUserEvent();
    assertNotNull(headersFrame);
    // No exception expected
    inboundHandler.checkException();
    assertNull(inboundHandler.readInboundMessageOrUserEvent());
}
Also used : StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) Test(org.junit.jupiter.api.Test)

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