Search in sources :

Example 11 with DecoderException

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

the class AbstractCodecPlayInOutCustomPayload method decode.

@Override
public Message decode(CodecContext context, ByteBuffer buf) throws CodecException {
    final String channel = buf.readLimitedString(LanternChannelRegistrar.MAX_NAME_LENGTH);
    final int length = buf.available();
    if (length > Short.MAX_VALUE) {
        throw new DecoderException("CustomPayload messages may not be longer then " + Short.MAX_VALUE + " bytes");
    }
    final ByteBuffer content = buf.slice();
    final Message message = decode0(context, content, channel);
    if (content.available() > 0) {
        Lantern.getLogger().warn("Trailing bytes {}b after decoding with custom payload message codec {} with channel {}!\n{}", content.available(), getClass().getName(), channel, message);
    }
    // Skip all the bytes, we already processed them
    buf.setReadIndex(buf.readerIndex() + buf.available());
    return message;
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) NullMessage(org.lanternpowered.server.network.message.NullMessage) Message(org.lanternpowered.server.network.message.Message) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Example 12 with DecoderException

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

the class CodecPlayInPlayerDigging method decode.

@Override
public Message decode(CodecContext context, ByteBuffer buf) throws CodecException {
    int action = buf.readByte();
    Vector3i position = buf.read(Types.VECTOR_3_I);
    int face = buf.readByte();
    switch(action) {
        case 0:
        case 1:
        case 2:
            return new MessagePlayInPlayerDigging(MessagePlayInPlayerDigging.Action.values()[action], position, fromFace(face));
        case 3:
        case 4:
            return new MessagePlayInDropHeldItem(action == 3);
        case 5:
            return new MessagePlayInOutFinishUsingItem();
        case 6:
            return new MessagePlayInSwapHandItems();
        default:
            throw new DecoderException("Unknown player digging message action: " + action);
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) MessagePlayInOutFinishUsingItem(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutFinishUsingItem) Vector3i(com.flowpowered.math.vector.Vector3i) MessagePlayInPlayerDigging(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerDigging) MessagePlayInSwapHandItems(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInSwapHandItems) MessagePlayInDropHeldItem(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInDropHeldItem)

Example 13 with DecoderException

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

the class MessageCodec method deserialize.

/**
 * Deserializes message from given byte buffer.
 *
 * @param bb byte buffer
 */
public static Message deserialize(ByteBuf bb) {
    Schema<Message> schema = RuntimeSchema.getSchema(Message.class);
    Message message = schema.newMessage();
    try {
        ProtostuffIOUtil.mergeFrom(new ByteBufInputStream(bb), message, schema);
    } catch (Exception e) {
        throw new DecoderException(e.getMessage(), e);
    }
    return message;
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) DecoderException(io.netty.handler.codec.DecoderException) EncoderException(io.netty.handler.codec.EncoderException)

Example 14 with DecoderException

use of io.netty.handler.codec.DecoderException in project graylog2-server by Graylog2.

the class SyslogOctetCountFrameDecoderTest method testBrokenFrames.

@Test
public void testBrokenFrames() throws Exception {
    final ByteBuf buf = Unpooled.copiedBuffer("1 2014-10-21T10:21:09+00:00 c4dc57ba1ebb syslog-ng 7120 - ", StandardCharsets.US_ASCII);
    try {
        channel.writeInbound(buf);
        fail("Expected DecoderException");
    } catch (DecoderException e) {
        assertTrue(e.getCause() instanceof NumberFormatException);
        channel.close().sync().await();
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 15 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, Exception 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)

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