'netty-readtimeout and return customized response to front end

I have a question regarding configuration of timeouts on a netty TCP server.

Currently we have configured readTimeOut as 120s. Set the connect timout like this:
socketChannel.pipeline().addLast(new ReadTimeoutHandler(120, TimeUnit.SECONDS));

But if the read time exceeds 120s, service doesn't response to front end correctly. If tested from postman, got the "Could not get any response" as response.

Following is the netty config we using:

public class EventLoopNettyCustomizer implements NettyServerCustomizer {

    @Override
    public HttpServer apply(HttpServer httpServer) {
        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
        EventLoopGroup workGroup = new NioEventLoopGroup();
        return httpServer.tcpConfiguration(tcpServer -> tcpServer
                .bootstrap(serverBootstrap -> serverBootstrap
                        .group(bossGroup, workGroup)
                        .option(ChannelOption.SO_BACKLOG, 10000)
                        .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30000)
                        .childHandler(new ChannelInitializer<SocketChannel>() {
                            @Override
                            protected void initChannel(SocketChannel socketChannel) throws Exception {
                                socketChannel.pipeline().addLast(new ReadTimeoutHandler(120, TimeUnit.SECONDS));
                                socketChannel.pipeline().addLast(new WriteTimeoutHandler(120, TimeUnit.SECONDS));
                            }
                        })
                        .channel(NioServerSocketChannel.class)));
    }
}

How can I config the netty so that it is able to return customized response? Including http status and message.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source