use of io.netty.handler.codec.DecoderException in project netty by netty.
the class SslHandler method channelInactive.
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
boolean handshakeFailed = handshakePromise.cause() != null;
ClosedChannelException exception = new ClosedChannelException();
// Make sure to release SSLEngine,
// and notify the handshake future if the connection has been closed during handshake.
setHandshakeFailure(ctx, exception, !isStateSet(STATE_OUTBOUND_CLOSED), isStateSet(STATE_HANDSHAKE_STARTED), false);
// Ensure we always notify the sslClosePromise as well
notifyClosePromise(exception);
try {
super.channelInactive(ctx);
} catch (DecoderException e) {
if (!handshakeFailed || !(e.getCause() instanceof SSLException)) {
// See https://github.com/netty/netty/issues/10119
throw e;
}
}
}
use of io.netty.handler.codec.DecoderException in project netty by netty.
the class SslClientHelloHandler method select.
private void select(final ChannelHandlerContext ctx, ByteBuf clientHello) throws Exception {
final Future<T> future;
try {
future = lookup(ctx, clientHello);
if (future.isDone()) {
onLookupComplete(ctx, future);
} else {
suppressRead = true;
final ByteBuf finalClientHello = clientHello;
future.addListener(new FutureListener<T>() {
@Override
public void operationComplete(Future<T> future) {
releaseIfNotNull(finalClientHello);
try {
suppressRead = false;
try {
onLookupComplete(ctx, future);
} catch (DecoderException err) {
ctx.fireExceptionCaught(err);
} catch (Exception cause) {
ctx.fireExceptionCaught(new DecoderException(cause));
} catch (Throwable cause) {
ctx.fireExceptionCaught(cause);
}
} finally {
if (readPending) {
readPending = false;
ctx.read();
}
}
}
});
// Ownership was transferred to the FutureListener.
clientHello = null;
}
} catch (Throwable cause) {
PlatformDependent.throwException(cause);
} finally {
releaseIfNotNull(clientHello);
}
}
use of io.netty.handler.codec.DecoderException in project netty by netty.
the class ApplicationProtocolNegotiationHandlerTest method testHandshakeFailure.
@Test
public void testHandshakeFailure() {
ChannelHandler alpnHandler = new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_1_1) {
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) {
fail();
}
};
EmbeddedChannel channel = new EmbeddedChannel(alpnHandler);
SSLHandshakeException exception = new SSLHandshakeException("error");
SslHandshakeCompletionEvent completionEvent = new SslHandshakeCompletionEvent(exception);
channel.pipeline().fireUserEventTriggered(completionEvent);
channel.pipeline().fireExceptionCaught(new DecoderException(exception));
assertNull(channel.pipeline().context(alpnHandler));
assertFalse(channel.finishAndReleaseAll());
}
use of io.netty.handler.codec.DecoderException in project Glowstone by GlowstoneMC.
the class CompressionHandler method decode.
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
int index = msg.readerIndex();
int uncompressedSize = ByteBufUtils.readVarInt(msg);
if (uncompressedSize == 0) {
// message is uncompressed
int length = msg.readableBytes();
if (length >= threshold) {
// invalid
throw new DecoderException("Received uncompressed message of size " + length + " greater than threshold " + threshold);
}
ByteBuf buf = ctx.alloc().buffer(length);
msg.readBytes(buf, length);
out.add(buf);
} else {
// message is compressed
byte[] sourceData = new byte[msg.readableBytes()];
msg.readBytes(sourceData);
inflater.setInput(sourceData);
byte[] destData = new byte[uncompressedSize];
int resultLength = inflater.inflate(destData);
inflater.reset();
if (resultLength == 0) {
// might be a leftover from before compression was enabled (no compression header)
// uncompressedSize is likely to be < threshold
msg.readerIndex(index);
msg.retain();
out.add(msg);
} else if (resultLength != uncompressedSize) {
throw new DecoderException("Received compressed message claiming to be of size " + uncompressedSize + " but actually " + resultLength);
} else {
out.add(Unpooled.wrappedBuffer(destData));
}
}
}
use of io.netty.handler.codec.DecoderException in project neo4j by neo4j.
the class StoreIdMarshal method unmarshal0.
protected StoreId unmarshal0(ReadableChannel channel) throws IOException {
byte exists = channel.get();
if (exists == 0) {
return null;
} else if (exists != 1) {
throw new DecoderException("Unexpected value: " + exists);
}
long creationTime = channel.getLong();
long randomId = channel.getLong();
long upgradeTime = channel.getLong();
long upgradeId = channel.getLong();
return new StoreId(creationTime, randomId, upgradeTime, upgradeId);
}
Aggregations