Search in sources :

Example 21 with DecoderException

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;
        }
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) DecoderException(io.netty.handler.codec.DecoderException) SSLException(javax.net.ssl.SSLException)

Example 22 with DecoderException

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);
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) ByteBuf(io.netty.buffer.ByteBuf) DecoderException(io.netty.handler.codec.DecoderException)

Example 23 with DecoderException

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());
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Test(org.junit.jupiter.api.Test)

Example 24 with DecoderException

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));
        }
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) ByteBuf(io.netty.buffer.ByteBuf)

Example 25 with DecoderException

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);
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) StoreId(org.neo4j.causalclustering.identity.StoreId)

Aggregations

DecoderException (io.netty.handler.codec.DecoderException)46 ByteBuf (io.netty.buffer.ByteBuf)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)5 ClosedChannelException (java.nio.channels.ClosedChannelException)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)4 Channel (io.netty.channel.Channel)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 Test (org.junit.jupiter.api.Test)3 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)2 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)2 DomainNameMappingBuilder (io.netty.util.DomainNameMappingBuilder)2 IOException (java.io.IOException)2 SSLException (javax.net.ssl.SSLException)2 Test (org.junit.Test)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 Vector3i (com.flowpowered.math.vector.Vector3i)1 ApiError (com.nike.backstopper.apierror.ApiError)1 ApiErrorWithMetadata (com.nike.backstopper.apierror.ApiErrorWithMetadata)1 CircuitBreakerException (com.nike.fastbreak.exception.CircuitBreakerException)1 Pair (com.nike.internal.util.Pair)1