Search in sources :

Example 41 with DecoderException

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

the class Socks4ClientDecoder method fail.

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

Example 42 with DecoderException

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

the class StompSubframeDecoder method readCommand.

private StompCommand readCommand(ByteBuf in) {
    CharSequence commandSequence = commandParser.parse(in);
    if (commandSequence == null) {
        throw new DecoderException("Failed to read command from channel");
    }
    String commandStr = commandSequence.toString();
    try {
        return StompCommand.valueOf(commandStr);
    } catch (IllegalArgumentException iae) {
        throw new DecoderException("Cannot to parse command " + commandStr);
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) AppendableCharSequence(io.netty.util.internal.AppendableCharSequence)

Example 43 with DecoderException

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

the class SslHandlerTest method testTruncatedPacket.

@Test
public void testTruncatedPacket() throws Exception {
    SSLEngine engine = newServerModeSSLEngine();
    final EmbeddedChannel ch = new EmbeddedChannel(new SslHandler(engine));
    // Push the first part of a 5-byte handshake message.
    ch.writeInbound(wrappedBuffer(new byte[] { 22, 3, 1, 0, 5 }));
    // Should decode nothing yet.
    assertThat(ch.readInbound(), is(nullValue()));
    DecoderException e = assertThrows(DecoderException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            // Push the second part of the 5-byte handshake message.
            ch.writeInbound(wrappedBuffer(new byte[] { 2, 0, 0, 1, 0 }));
        }
    });
    // Be sure we cleanup the channel and release any pending messages that may have been generated because
    // of an alert.
    // See https://github.com/netty/netty/issues/6057.
    ch.finishAndReleaseAll();
    // The pushed message is invalid, so it should raise an exception if it decoded the message correctly.
    assertThat(e.getCause(), is(instanceOf(SSLProtocolException.class)));
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) SSLEngine(javax.net.ssl.SSLEngine) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 44 with DecoderException

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

the class MqttDecoder method decodeProperties.

private static Result<MqttProperties> decodeProperties(ByteBuf buffer) {
    final long propertiesLength = decodeVariableByteInteger(buffer);
    int totalPropertiesLength = unpackA(propertiesLength);
    int numberOfBytesConsumed = unpackB(propertiesLength);
    MqttProperties decodedProperties = new MqttProperties();
    while (numberOfBytesConsumed < totalPropertiesLength) {
        long propertyId = decodeVariableByteInteger(buffer);
        final int propertyIdValue = unpackA(propertyId);
        numberOfBytesConsumed += unpackB(propertyId);
        MqttProperties.MqttPropertyType propertyType = MqttProperties.MqttPropertyType.valueOf(propertyIdValue);
        switch(propertyType) {
            case PAYLOAD_FORMAT_INDICATOR:
            case REQUEST_PROBLEM_INFORMATION:
            case REQUEST_RESPONSE_INFORMATION:
            case MAXIMUM_QOS:
            case RETAIN_AVAILABLE:
            case WILDCARD_SUBSCRIPTION_AVAILABLE:
            case SUBSCRIPTION_IDENTIFIER_AVAILABLE:
            case SHARED_SUBSCRIPTION_AVAILABLE:
                final int b1 = buffer.readUnsignedByte();
                numberOfBytesConsumed++;
                decodedProperties.add(new IntegerProperty(propertyIdValue, b1));
                break;
            case SERVER_KEEP_ALIVE:
            case RECEIVE_MAXIMUM:
            case TOPIC_ALIAS_MAXIMUM:
            case TOPIC_ALIAS:
                final int int2BytesResult = decodeMsbLsb(buffer);
                numberOfBytesConsumed += 2;
                decodedProperties.add(new IntegerProperty(propertyIdValue, int2BytesResult));
                break;
            case PUBLICATION_EXPIRY_INTERVAL:
            case SESSION_EXPIRY_INTERVAL:
            case WILL_DELAY_INTERVAL:
            case MAXIMUM_PACKET_SIZE:
                final int maxPacketSize = buffer.readInt();
                numberOfBytesConsumed += 4;
                decodedProperties.add(new IntegerProperty(propertyIdValue, maxPacketSize));
                break;
            case SUBSCRIPTION_IDENTIFIER:
                long vbIntegerResult = decodeVariableByteInteger(buffer);
                numberOfBytesConsumed += unpackB(vbIntegerResult);
                decodedProperties.add(new IntegerProperty(propertyIdValue, unpackA(vbIntegerResult)));
                break;
            case CONTENT_TYPE:
            case RESPONSE_TOPIC:
            case ASSIGNED_CLIENT_IDENTIFIER:
            case AUTHENTICATION_METHOD:
            case RESPONSE_INFORMATION:
            case SERVER_REFERENCE:
            case REASON_STRING:
                final Result<String> stringResult = decodeString(buffer);
                numberOfBytesConsumed += stringResult.numberOfBytesConsumed;
                decodedProperties.add(new MqttProperties.StringProperty(propertyIdValue, stringResult.value));
                break;
            case USER_PROPERTY:
                final Result<String> keyResult = decodeString(buffer);
                final Result<String> valueResult = decodeString(buffer);
                numberOfBytesConsumed += keyResult.numberOfBytesConsumed;
                numberOfBytesConsumed += valueResult.numberOfBytesConsumed;
                decodedProperties.add(new MqttProperties.UserProperty(keyResult.value, valueResult.value));
                break;
            case CORRELATION_DATA:
            case AUTHENTICATION_DATA:
                final byte[] binaryDataResult = decodeByteArray(buffer);
                numberOfBytesConsumed += binaryDataResult.length + 2;
                decodedProperties.add(new MqttProperties.BinaryProperty(propertyIdValue, binaryDataResult));
                break;
            default:
                // shouldn't reach here
                throw new DecoderException("Unknown property type: " + propertyType);
        }
    }
    return new Result<MqttProperties>(decodedProperties, numberOfBytesConsumed);
}
Also used : IntegerProperty(io.netty.handler.codec.mqtt.MqttProperties.IntegerProperty) DecoderException(io.netty.handler.codec.DecoderException)

Example 45 with DecoderException

use of io.netty.handler.codec.DecoderException in project grpc-java by grpc.

the class Utils method statusFromThrowable.

public static Status statusFromThrowable(Throwable t) {
    Status s = Status.fromThrowable(t);
    if (s.getCode() != Status.Code.UNKNOWN) {
        return s;
    }
    if (t instanceof ClosedChannelException) {
        // ClosedChannelException is used any time the Netty channel is closed. Proper error
        // processing requires remembering the error that occurred before this one and using it
        // instead.
        // 
        // Netty uses an exception that has no stack trace, while we would never hope to show this to
        // users, if it happens having the extra information may provide a small hint of where to
        // look.
        ClosedChannelException extraT = new ClosedChannelException();
        extraT.initCause(t);
        return Status.UNKNOWN.withDescription("channel closed").withCause(extraT);
    }
    if (t instanceof DecoderException && t.getCause() instanceof SSLException) {
        return Status.UNAVAILABLE.withDescription("ssl exception").withCause(t);
    }
    if (t instanceof IOException) {
        return Status.UNAVAILABLE.withDescription("io exception").withCause(t);
    }
    if (t instanceof UnresolvedAddressException) {
        return Status.UNAVAILABLE.withDescription("unresolved address").withCause(t);
    }
    if (t instanceof Http2Exception) {
        return Status.INTERNAL.withDescription("http2 exception").withCause(t);
    }
    return s;
}
Also used : Status(io.grpc.Status) ClosedChannelException(java.nio.channels.ClosedChannelException) DecoderException(io.netty.handler.codec.DecoderException) Http2Exception(io.netty.handler.codec.http2.Http2Exception) IOException(java.io.IOException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) SSLException(javax.net.ssl.SSLException)

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