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);
}
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);
}
}
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;
}
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);
}
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);
}
}
Aggregations