Search in sources :

Example 36 with DecoderException

use of io.netty.handler.codec.DecoderException in project LanternServer by LanternPowered.

the class CodecPlayInOutCustomPayload method decode0.

@Override
protected Message decode0(CodecContext context, String channel, ByteBuffer content) throws CodecException {
    if ("FML|HS".equals(channel)) {
        int type = content.readByte();
        switch(type) {
            case FML_HANDSHAKE_RESET:
                // server -> client message: ignore
                break;
            case FML_HANDSHAKE_ACK:
                ForgeClientHandshakePhase phase = ForgeClientHandshakePhase.values()[content.readByte()];
                return new MessageForgeHandshakeInOutAck(phase);
            case FML_HANDSHAKE_SERVER_HELLO:
                // server -> client message: ignore
                break;
            case FML_HANDSHAKE_CLIENT_HELLO:
                // The forge protocol version on the client
                content.readByte();
                return new MessageForgeHandshakeInOutHello();
            case FML_HANDSHAKE_MOD_LIST:
                int size = content.readVarInt();
                Map<String, String> entries = Maps.newHashMapWithExpectedSize(size);
                for (int i = 0; i < size; i++) {
                    entries.put(content.readString(), content.readString());
                }
                return new MessageForgeHandshakeInOutModList(entries);
            case FML_HANDSHAKE_REGISTRY_DATA:
                // server -> client message: ignore
                break;
            default:
                throw new DecoderException("Unknown forge handshake message with opcode: " + type);
        }
        throw new DecoderException("Received an unexpected forge message with opcode: " + type);
    } else {
        throw new DecoderException("Received an unexpected message with channel: " + channel);
    }
}
Also used : MessageForgeHandshakeInOutHello(org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutHello) DecoderException(io.netty.handler.codec.DecoderException) MessageForgeHandshakeInOutModList(org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutModList) MessageForgeHandshakeInOutAck(org.lanternpowered.server.network.forge.message.type.handshake.MessageForgeHandshakeInOutAck) ForgeClientHandshakePhase(org.lanternpowered.server.network.forge.handshake.ForgeClientHandshakePhase)

Example 37 with DecoderException

use of io.netty.handler.codec.DecoderException in project netty by netty.

the class HttpContentDecoderTest method testCleanupThrows.

@Test
public void testCleanupThrows() {
    HttpContentDecoder decoder = new HttpContentDecoder() {

        @Override
        protected EmbeddedChannel newContentDecoder(String contentEncoding) throws Exception {
            return new EmbeddedChannel(new ChannelInboundHandlerAdapter() {

                @Override
                public void channelInactive(ChannelHandlerContext ctx) throws Exception {
                    ctx.fireExceptionCaught(new DecoderException());
                    ctx.fireChannelInactive();
                }
            });
        }
    };
    final AtomicBoolean channelInactiveCalled = new AtomicBoolean();
    EmbeddedChannel channel = new EmbeddedChannel(decoder, new ChannelInboundHandlerAdapter() {

        @Override
        public void channelInactive(ChannelHandlerContext ctx) throws Exception {
            assertTrue(channelInactiveCalled.compareAndSet(false, true));
            super.channelInactive(ctx);
        }
    });
    assertTrue(channel.writeInbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/")));
    HttpContent content = new DefaultHttpContent(Unpooled.buffer().writeZero(10));
    assertTrue(channel.writeInbound(content));
    assertEquals(1, content.refCnt());
    try {
        channel.finishAndReleaseAll();
        fail();
    } catch (CodecException expected) {
    // expected
    }
    assertTrue(channelInactiveCalled.get());
    assertEquals(0, content.refCnt());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CodecException(io.netty.handler.codec.CodecException) DecoderException(io.netty.handler.codec.DecoderException) DecoderException(io.netty.handler.codec.DecoderException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CodecException(io.netty.handler.codec.CodecException) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Test(org.junit.jupiter.api.Test)

Example 38 with DecoderException

use of io.netty.handler.codec.DecoderException in project netty by netty.

the class Socks5PasswordAuthRequestDecoder method fail.

private void fail(List<Object> out, Exception cause) {
    if (!(cause instanceof DecoderException)) {
        cause = new DecoderException(cause);
    }
    checkpoint(State.FAILURE);
    Socks5Message m = new DefaultSocks5PasswordAuthRequest("", "");
    m.setDecoderResult(DecoderResult.failure(cause));
    out.add(m);
}
Also used : DecoderException(io.netty.handler.codec.DecoderException)

Example 39 with DecoderException

use of io.netty.handler.codec.DecoderException in project netty by netty.

the class Socks5CommandRequestDecoder method fail.

private void fail(List<Object> out, Exception cause) {
    if (!(cause instanceof DecoderException)) {
        cause = new DecoderException(cause);
    }
    checkpoint(State.FAILURE);
    Socks5Message m = new DefaultSocks5CommandRequest(Socks5CommandType.CONNECT, Socks5AddressType.IPv4, "0.0.0.0", 1);
    m.setDecoderResult(DecoderResult.failure(cause));
    out.add(m);
}
Also used : DecoderException(io.netty.handler.codec.DecoderException)

Example 40 with DecoderException

use of io.netty.handler.codec.DecoderException in project netty by netty.

the class Socks5CommandResponseDecoder method fail.

private void fail(List<Object> out, Exception cause) {
    if (!(cause instanceof DecoderException)) {
        cause = new DecoderException(cause);
    }
    checkpoint(State.FAILURE);
    Socks5Message m = new DefaultSocks5CommandResponse(Socks5CommandStatus.FAILURE, Socks5AddressType.IPv4, null, 0);
    m.setDecoderResult(DecoderResult.failure(cause));
    out.add(m);
}
Also used : DecoderException(io.netty.handler.codec.DecoderException)

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