use of io.netty.handler.codec.DecoderException in project LanternServer by LanternPowered.
the class CodecPlayInOutCustomPayload method decode0.
@Override
protected Message decode0(CodecContext context, String channel, ByteBuffer content) throws CodecException {
if ("FML|HS".equals(channel)) {
int type = content.readByte();
switch(type) {
case FML_HANDSHAKE_RESET:
// server -> client message: ignore
break;
case FML_HANDSHAKE_ACK:
ForgeClientHandshakePhase phase = ForgeClientHandshakePhase.values()[content.readByte()];
return new MessageForgeHandshakeInOutAck(phase);
case FML_HANDSHAKE_SERVER_HELLO:
// server -> client message: ignore
break;
case FML_HANDSHAKE_CLIENT_HELLO:
// The forge protocol version on the client
content.readByte();
return new MessageForgeHandshakeInOutHello();
case FML_HANDSHAKE_MOD_LIST:
int size = content.readVarInt();
Map<String, String> entries = Maps.newHashMapWithExpectedSize(size);
for (int i = 0; i < size; i++) {
entries.put(content.readString(), content.readString());
}
return new MessageForgeHandshakeInOutModList(entries);
case FML_HANDSHAKE_REGISTRY_DATA:
// server -> client message: ignore
break;
default:
throw new DecoderException("Unknown forge handshake message with opcode: " + type);
}
throw new DecoderException("Received an unexpected forge message with opcode: " + type);
} else {
throw new DecoderException("Received an unexpected message with channel: " + channel);
}
}
use of io.netty.handler.codec.DecoderException in project netty by netty.
the class HttpContentDecoderTest method testCleanupThrows.
@Test
public void testCleanupThrows() {
HttpContentDecoder decoder = new HttpContentDecoder() {
@Override
protected EmbeddedChannel newContentDecoder(String contentEncoding) throws Exception {
return new EmbeddedChannel(new ChannelInboundHandlerAdapter() {
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
ctx.fireExceptionCaught(new DecoderException());
ctx.fireChannelInactive();
}
});
}
};
final AtomicBoolean channelInactiveCalled = new AtomicBoolean();
EmbeddedChannel channel = new EmbeddedChannel(decoder, new ChannelInboundHandlerAdapter() {
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
assertTrue(channelInactiveCalled.compareAndSet(false, true));
super.channelInactive(ctx);
}
});
assertTrue(channel.writeInbound(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/")));
HttpContent content = new DefaultHttpContent(Unpooled.buffer().writeZero(10));
assertTrue(channel.writeInbound(content));
assertEquals(1, content.refCnt());
try {
channel.finishAndReleaseAll();
fail();
} catch (CodecException expected) {
// expected
}
assertTrue(channelInactiveCalled.get());
assertEquals(0, content.refCnt());
}
use of io.netty.handler.codec.DecoderException in project netty by netty.
the class Socks5PasswordAuthRequestDecoder method fail.
private void fail(List<Object> out, Exception cause) {
if (!(cause instanceof DecoderException)) {
cause = new DecoderException(cause);
}
checkpoint(State.FAILURE);
Socks5Message m = new DefaultSocks5PasswordAuthRequest("", "");
m.setDecoderResult(DecoderResult.failure(cause));
out.add(m);
}
use of io.netty.handler.codec.DecoderException in project netty by netty.
the class Socks5CommandRequestDecoder method fail.
private void fail(List<Object> out, Exception cause) {
if (!(cause instanceof DecoderException)) {
cause = new DecoderException(cause);
}
checkpoint(State.FAILURE);
Socks5Message m = new DefaultSocks5CommandRequest(Socks5CommandType.CONNECT, Socks5AddressType.IPv4, "0.0.0.0", 1);
m.setDecoderResult(DecoderResult.failure(cause));
out.add(m);
}
use of io.netty.handler.codec.DecoderException in project netty by netty.
the class Socks5CommandResponseDecoder method fail.
private void fail(List<Object> out, Exception cause) {
if (!(cause instanceof DecoderException)) {
cause = new DecoderException(cause);
}
checkpoint(State.FAILURE);
Socks5Message m = new DefaultSocks5CommandResponse(Socks5CommandStatus.FAILURE, Socks5AddressType.IPv4, null, 0);
m.setDecoderResult(DecoderResult.failure(cause));
out.add(m);
}
Aggregations