FullHttpRequestHandler.java 845 B

12345678910111213141516171819202122232425
  1. package cn.nosum.gateway.handler;
  2. import cn.nosum.common.http.entity.Context;
  3. import cn.nosum.common.http.factory.ContextFactory;
  4. import io.netty.channel.ChannelHandlerContext;
  5. import io.netty.channel.SimpleChannelInboundHandler;
  6. import io.netty.handler.codec.http.FullHttpRequest;
  7. import io.netty.util.ReferenceCountUtil;
  8. public class FullHttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
  9. @Override
  10. protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
  11. // 构建上下文对象
  12. Context context= ContextFactory.build(ctx,req);
  13. ctx.fireChannelRead(context);
  14. ReferenceCountUtil.release(req);
  15. }
  16. @Override
  17. public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
  18. ctx.close();
  19. }
  20. }