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();
}
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);
}
}
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);
}
}
}
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();
}
});
}
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());
}
Aggregations