Netty ChannelHandler- How to get DefaultFullHttpResponse in channelRead0?

Viewed 72

I am trying to setup a request/response client ChannelHandler. At this point I'm able to get the DefaultHttpResponse in my channelRead0 method, but I don't know how to get the DefaultFullHttpResponse.

The reason I need the DefaultFullHttpResponse is that the DefaultHttpResponse doesn't appear to contain the response body returned from the server.

My ChannelHander-

public class NettyClientHandler extends SimpleChannelInboundHandler<DefaultHttpResponse> {

    private ChannelHandlerContext ctx;
    private BlockingQueue<Promise<DefaultHttpResponse>> messageList = new LinkedBlockingQueue<>(1_000_000);

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        super.channelActive(ctx);
        this.ctx = ctx;
    }

    @Override
    public void channelRead0(ChannelHandlerContext ctx, DefaultHttpResponse msg) {
        synchronized (this) {
            messageList.poll().setSuccess(msg);
            System.out.println(msg);
        }
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx)
            throws Exception {
        super.channelReadComplete(ctx);
        System.out.println("channelReadComplete");

    }
}

And how the channel pipeline is configured in the ChannelPoolHandler-

@Override
public void channelCreated(Channel channel) throws Exception {
    channel.pipeline().addLast(sslContext.newHandler(channel.alloc()));
    channel.pipeline().addLast(new HttpClientCodec());
    channel.pipeline().addLast(new HttpContentDecompressor());
    channel.pipeline().addLast(new NettyClientHandler());
}

I looked around but I couldn't find any FullHttpClientCodec or options in the HttpClientCodec that would allow me to do this.

How can I get the DefaultFullHttpResponse to be passed to the channelRead0 method?

0 Answers
Related