use of io.netty.handler.codec.DecoderException in project camel by apache.
the class HL7MLLPNettyDecoder method decode.
@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
ByteBuf buf = (ByteBuf) super.decode(ctx, buffer);
if (buf != null) {
try {
int pos = buf.bytesBefore((byte) config.getStartByte());
if (pos >= 0) {
ByteBuf msg = buf.readerIndex(pos + 1).slice();
LOG.debug("Message ends with length {}", msg.readableBytes());
return config.isProduceString() ? asString(msg) : asByteArray(msg);
} else {
throw new DecoderException("Did not find start byte " + (int) config.getStartByte());
}
} finally {
// We need to release the buf here to avoid the memory leak
buf.release();
}
}
// Message not complete yet - return null to be called again
LOG.debug("No complete messages yet at position {}", buffer.readableBytes());
return null;
}
use of io.netty.handler.codec.DecoderException in project bookkeeper by apache.
the class PerChannelBookieClient method exceptionCaught.
/**
* Called by netty when an exception happens in one of the netty threads
* (mostly due to what we do in the netty threads).
*/
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
exceptionCounter.inc();
if (cause instanceof CorruptedFrameException || cause instanceof TooLongFrameException) {
LOG.error("Corrupted frame received from bookie: {}", ctx.channel().remoteAddress());
ctx.close();
return;
}
if (cause instanceof AuthHandler.AuthenticationException) {
LOG.error("Error authenticating connection", cause);
errorOutOutstandingEntries(BKException.Code.UnauthorizedAccessException);
Channel c = ctx.channel();
if (c != null) {
closeChannel(c);
}
return;
}
if (cause instanceof DecoderException && cause.getCause() instanceof SSLHandshakeException) {
LOG.error("TLS handshake failed", cause);
errorOutPendingOps(BKException.Code.SecurityException);
Channel c = ctx.channel();
if (c != null) {
closeChannel(c);
}
}
if (cause instanceof IOException) {
LOG.warn("Exception caught on:{} cause:", ctx.channel(), cause);
ctx.close();
return;
}
synchronized (this) {
if (state == ConnectionState.CLOSED) {
if (LOG.isDebugEnabled()) {
LOG.debug("Unexpected exception caught by bookie client channel handler, " + "but the client is closed, so it isn't important", cause);
}
} else {
LOG.error("Unexpected exception caught by bookie client channel handler", cause);
}
}
// Since we are a library, cant terminate App here, can we?
ctx.close();
}
use of io.netty.handler.codec.DecoderException in project zuul by Netflix.
the class Http2StreamErrorHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (cause instanceof StreamException) {
StreamException streamEx = (StreamException) cause;
ctx.writeAndFlush(new DefaultHttp2ResetFrame(streamEx.error()));
} else if (cause instanceof DecoderException) {
ctx.writeAndFlush(new DefaultHttp2ResetFrame(Http2Error.PROTOCOL_ERROR));
} else {
super.exceptionCaught(ctx, cause);
}
}
use of io.netty.handler.codec.DecoderException in project LanternServer by LanternPowered.
the class MessageCodecHandler method processMessage.
private void processMessage(Message message, List<Object> output, Protocol protocol, ProtocolState state, CodecContext context) {
if (message == NullMessage.INSTANCE) {
return;
}
if (message instanceof BulkMessage) {
((BulkMessage) message).getMessages().forEach(message1 -> processMessage(message1, output, protocol, state, context));
return;
}
final MessageRegistration messageRegistration = (MessageRegistration) protocol.inbound().findByMessageType(message.getClass()).orElseThrow(() -> new DecoderException("The returned message type is not attached to the used protocol state (" + state.toString() + ")!"));
final List<Processor> processors = messageRegistration.getProcessors();
// Only process if there are processors found
if (!processors.isEmpty()) {
for (Processor processor : processors) {
// The processor should handle the output messages
processor.process(context, message, output);
}
} else {
final Optional<Handler> optHandler = messageRegistration.getHandler();
if (optHandler.isPresent()) {
// Add the message to the output
output.add(new HandlerMessage(message, optHandler.get()));
} else {
output.add(message);
}
}
}
use of io.netty.handler.codec.DecoderException in project LanternServer by LanternPowered.
the class MessageCompressionHandler method decode.
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
int index = msg.readerIndex();
int uncompressedSize = readVarInt(msg);
if (uncompressedSize == 0) {
// Message is uncompressed
int length = msg.readableBytes();
if (length >= this.compressionThreshold) {
// Invalid
throw new DecoderException("Received uncompressed message of size " + length + " greater than threshold " + this.compressionThreshold);
}
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);
this.inflater.setInput(sourceData);
byte[] destData = new byte[uncompressedSize];
int resultLength = this.inflater.inflate(destData);
this.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));
}
}
}
Aggregations