Search in sources :

Example 6 with DecoderException

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

the class Socks4ServerDecoder method fail.

private void fail(List<Object> out, Throwable cause) {
    if (!(cause instanceof DecoderException)) {
        cause = new DecoderException(cause);
    }
    Socks4CommandRequest m = new DefaultSocks4CommandRequest(type != null ? type : Socks4CommandType.CONNECT, dstAddr != null ? dstAddr : "", dstPort != 0 ? dstPort : 65535, userId != null ? userId : "");
    m.setDecoderResult(DecoderResult.failure(cause));
    out.add(m);
    checkpoint(State.FAILURE);
}
Also used : DecoderException(io.netty.handler.codec.DecoderException)

Example 7 with DecoderException

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

the class SniHandlerTest method testServerNameParsing.

@Test
public void testServerNameParsing() throws Exception {
    SslContext nettyContext = makeSslContext(provider, false);
    SslContext leanContext = makeSslContext(provider, false);
    SslContext leanContext2 = makeSslContext(provider, false);
    try {
        DomainNameMapping<SslContext> mapping = new DomainNameMappingBuilder<SslContext>(nettyContext).add("*.netty.io", nettyContext).add("*.LEANCLOUD.CN", leanContext).add("chat4.leancloud.cn", leanContext2).build();
        SniHandler handler = new SniHandler(mapping);
        EmbeddedChannel ch = new EmbeddedChannel(handler);
        // hex dump of a client hello packet, which contains hostname "CHAT4。LEANCLOUD。CN"
        String tlsHandshakeMessageHex1 = "16030100";
        // part 2
        String tlsHandshakeMessageHex = "bd010000b90303a74225676d1814ba57faff3b366" + "3656ed05ee9dbb2a4dbb1bb1c32d2ea5fc39e0000000100008c0000001700150000164348" + "415434E380824C45414E434C4F5544E38082434E000b000403000102000a00340032000e0" + "00d0019000b000c00180009000a0016001700080006000700140015000400050012001300" + "0100020003000f0010001100230000000d0020001e0601060206030501050205030401040" + "20403030103020303020102020203000f00010133740000";
        try {
            // Push the handshake message.
            // Decode should fail because SNI error
            ch.writeInbound(Unpooled.wrappedBuffer(DatatypeConverter.parseHexBinary(tlsHandshakeMessageHex1)));
            ch.writeInbound(Unpooled.wrappedBuffer(DatatypeConverter.parseHexBinary(tlsHandshakeMessageHex)));
            fail();
        } catch (DecoderException e) {
        // expected
        }
        // This should produce an alert
        assertTrue(ch.finish());
        assertThat(handler.hostname(), is("chat4.leancloud.cn"));
        assertThat(handler.sslContext(), is(leanContext));
        for (; ; ) {
            Object msg = ch.readOutbound();
            if (msg == null) {
                break;
            }
            ReferenceCountUtil.release(msg);
        }
    } finally {
        releaseAll(leanContext, leanContext2, nettyContext);
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) DomainNameMappingBuilder(io.netty.util.DomainNameMappingBuilder) Test(org.junit.Test)

Example 8 with DecoderException

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

the class ExecutionHandlerContext method getExceptionResponse.

private ByteBuf getExceptionResponse(ChannelHandlerContext ctx, Throwable cause) {
    ByteBuf response;
    if (cause instanceof RedisDataTypeMismatchException)
        response = Coder.getWrongTypeResponse(this.byteBufAllocator, cause.getMessage());
    else if (cause instanceof DecoderException && cause.getCause() instanceof RedisCommandParserException)
        response = Coder.getErrorResponse(this.byteBufAllocator, RedisConstants.PARSING_EXCEPTION_MESSAGE);
    else if (cause instanceof RegionCreationException) {
        this.logger.error(cause);
        response = Coder.getErrorResponse(this.byteBufAllocator, RedisConstants.ERROR_REGION_CREATION);
    } else if (cause instanceof InterruptedException || cause instanceof CacheClosedException)
        response = Coder.getErrorResponse(this.byteBufAllocator, RedisConstants.SERVER_ERROR_SHUTDOWN);
    else if (cause instanceof IllegalStateException) {
        response = Coder.getErrorResponse(this.byteBufAllocator, cause.getMessage());
    } else {
        if (this.logger.errorEnabled())
            this.logger.error("GeodeRedisServer-Unexpected error handler for " + ctx.channel(), cause);
        response = Coder.getErrorResponse(this.byteBufAllocator, RedisConstants.SERVER_ERROR_MESSAGE);
    }
    return response;
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ByteBuf(io.netty.buffer.ByteBuf)

Example 9 with DecoderException

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

the class CodecPlayInResourcePackStatus method decode.

@Override
public MessagePlayInResourcePackStatus decode(CodecContext context, ByteBuffer buf) throws CodecException {
    int status0 = buf.readVarInt();
    ResourcePackStatus status = this.status.get(status0);
    if (status == null) {
        throw new DecoderException("Unknown status: " + status0);
    }
    return new MessagePlayInResourcePackStatus(status);
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) MessagePlayInResourcePackStatus(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInResourcePackStatus) ResourcePackStatus(org.spongepowered.api.event.entity.living.humanoid.player.ResourcePackStatusEvent.ResourcePackStatus) MessagePlayInResourcePackStatus(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInResourcePackStatus)

Example 10 with DecoderException

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

the class CodecPlayInUseEntity method decode.

@Override
public MessagePlayInUseEntity decode(CodecContext context, ByteBuffer buf) throws CodecException {
    final int entityId = buf.readVarInt();
    final int action = buf.readVarInt();
    if (action == 1) {
        return new MessagePlayInUseEntity.Attack(entityId);
    } else if (action == 0 || action == 2) {
        Vector3d position = null;
        if (action == 2) {
            final double x = buf.readFloat();
            final double y = buf.readFloat();
            final double z = buf.readFloat();
            position = new Vector3d(x, y, z);
        }
        final HandType hand = buf.readVarInt() == 0 ? HandTypes.MAIN_HAND : HandTypes.OFF_HAND;
        return new MessagePlayInUseEntity.Interact(entityId, hand, position);
    } else {
        throw new DecoderException("Received a UseEntity message with a unknown action: " + action);
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) Vector3d(com.flowpowered.math.vector.Vector3d) HandType(org.spongepowered.api.data.type.HandType) MessagePlayInUseEntity(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInUseEntity)

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