Netty ChannelHandler-如何在channelRead0中获取DefaultFullHttpResponse?

时间:2019-06-26 15:32:25

标签: java netty nio

我正在尝试设置请求/响应客户端ChannelHandler。此时,我可以在SELECT CLIENT_EMAIL FROM CLIENT_TABLE WHERE MONTH(DATE_CLIENT_ADDED) = MONTH(CURDATE() - INTERVAL 1 MONTH); 方法中获取DefaultHttpResponse,但是我不知道如何获取DefaultFullHttpResponse。

我需要DefaultFullHttpResponse的原因是DefaultHttpResponse似乎不包含从服务器返回的响应正文。

我的ChannelHander-

channelRead0

以及如何在ChannelPoolHandler中配置通道管道-

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");

    }
}

我环顾四周,但是在@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()); } 中找不到任何FullHttpClientCodec或其他允许我执行此操作的选项。

如何获取DefaultFullHttpResponse传递给channelRead0方法?

0 个答案:

没有答案