Netty Server not processing HTTP Requests after using Server Bootstrap for customizing

I have a spring reactive based Microservice which is using Netty Server version 4.1.101.Final. It was working completely fine and processing all the HTTP requests which I fire . Now I want to catch the connection-ids to figure out which connection is getting used and which is getting closed. For this I have written a custom Connection Logging handler. Following is my ConnectionLoggingHandler :

public class ConnectionLoggingHandler extends ChannelInboundHandlerAdapter{
    private static final AtomicInteger connectionIdCounter = new AtomicInteger(0);
    
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception{
        int connectionId=connectionIdCounter.incrementAndGet();
        System.out.println("Connection established : ID = " + connectionId);
        ctx.channel().attr(AttributeKey.valueOf("connectionId")).set(connectionId);
        super.channelActive(ctx);
    }
    
    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception{
        //retrieve connectionID
        Integer connectionId = (Integer) ctx.channel().attr(AttributeKey.valueOf("connectionId")).get();
        if(connectionId!=null){
          System.out.println("Connection closed : ID = " + connectionId);  
        }
        super.channelInactive(ctx);
    }
    
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{
        //retrieve connectionID
        Integer connectionId = (Integer) ctx.channel().attr(AttributeKey.valueOf("connectionId")).get();
        if(connectionId!=null){
          System.out.println("Exception in Connection: ID = " + connectionId);  
        }
        cause.printStackTrace();
        ctx.close();
    }
}

Now I want to add this handler to my Netty Server. I tried this using two ways.

Code for Custom Netty Server:

public class CustomNettyServer{
    private int port =8080;
    
    @PostConstruct
    public void startServer() throws InterruptedException{
        EventLoopGroup boss= new NioEventLoopGroup();
        EventLoopGroup worker=new NioEventLoopGroup();
        try{
            ServerBootstrap bootstrap new ServerBootstrap();
            bootstrap.group(boss,worker)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<Channel>(){
                    @Override
                    protected void initChannel(Channel ch) throws Exception{
                        ch.pipeline().addLast(new HttpServerCodec(),new HttpRequestDecoder(),new HttpContentDecompressor(),new HttpResponseEncoder(),new HttpContentCompressor(),new HttpObjectAggregator(512*1024),new ConnectionLoggingHandler());
                        
                    }
                });
            Channel channel = bootstarp.bind(port).sync().channel();
            channel.closeFuture().sync();
        }
        finally{
            boss.shutdownGracefully();
            worker.shutdownGracefully();
        }
    }
}

When I use this server, then I can see the logs present in my custom handler when I hit a request through postman for establishment of connection. But my HTTP request is not getting processed.
It says Discarded inbound message. Please check your pipeline configuration. I don’t know what am I missing here.

Then I also tried another way to customize my netty server. Below is my code for CustomNettyServer.

public class CustomNettyServer implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory>{
    @Override
    public void customize(NettyReactiveWebServerFactory factory){
        factory.addServerCustomizers(server->
        server.tcpConfiguration(tcp->
        tcp.doOnConnection(connection->
        connection.addHandlerLast(new ConnectionLoggingHandler()))));
    }
}

Using this method, I cannot see logs getting printed due to my ConnectionLoggingHandler whenever I hit a request and the request is getting prcoessed successfully. I can see Handler getting added to the pipeline when the request is made and removed when the request is served. But the logs are not getting generated. I have also kept the logging level to DEBUG.

I don’t know what I am doing wrong in these two ways and I am stuck here.
So I want to know how can I get the logs for the Connection-IDs which are being opened, used and closed.
Thanks.

New contributor

Satyam Pareek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật