FrontendSessionNettyHandler extends AbstractSessionNettyHandler { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if(msg instanceof ByteBuf) { if(tunnel != null) { tunnel.forwardToBackend((ByteBuf) msg); } else { logger.error("[doChannelRead] send non-proxy-protocol from channel {}: {} from channel: {}", ChannelUtil.getDesc(ctx.channel()), formatByteBuf("RECEIVE", (ByteBuf) msg)); ctx.channel().close(); } } else { throw new ResourceIncorrectException("Unexpected type for read: " + msg.getClass().getName()); } ctx.fireChannelRead(msg); } FrontendSessionNettyHandler(Tunnel tunnel); @Override void channelRead(ChannelHandlerContext ctx, Object msg);  }
@Test public void testChannelRead() { Throwable throwable = null; logger.info("[channelRead] exception expected"); try { channel.writeInbound(new DefaultProxyConnectProtocolParser().read("PROXY ROUTE TCP: channel.checkException(); } catch (Exception e) { throwable = e; } Assert.assertNotNull(throwable); Assert.assertTrue(throwable instanceof ResourceIncorrectException); verify(session).release(); }