Home / Class/ HttpHelloWorldServerHandler Class — netty Architecture

HttpHelloWorldServerHandler Class — netty Architecture

Architecture documentation for the HttpHelloWorldServerHandler class in HttpHelloWorldServerHandler.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  ecd87b1b_17db_6be0_8c18_3e5736e61a40["HttpHelloWorldServerHandler"]
  2066eaf4_0038_0567_b7fa_57f4a67ad62c["HttpHelloWorldServerHandler.java"]
  ecd87b1b_17db_6be0_8c18_3e5736e61a40 -->|defined in| 2066eaf4_0038_0567_b7fa_57f4a67ad62c
  e39616bc_a299_d8a2_6914_bc8e009a5d38["channelReadComplete()"]
  ecd87b1b_17db_6be0_8c18_3e5736e61a40 -->|method| e39616bc_a299_d8a2_6914_bc8e009a5d38
  6ff65132_2bf7_69bc_0218_fa069113dc87["channelRead0()"]
  ecd87b1b_17db_6be0_8c18_3e5736e61a40 -->|method| 6ff65132_2bf7_69bc_0218_fa069113dc87
  65e83f14_b46f_6d00_6bf2_4906938a01c1["exceptionCaught()"]
  ecd87b1b_17db_6be0_8c18_3e5736e61a40 -->|method| 65e83f14_b46f_6d00_6bf2_4906938a01c1

Relationship Graph

Source Code

testsuite-jpms/src/main/java/io/netty/testsuite_jpms/main/HttpHelloWorldServerHandler.java lines 40–84

public class HttpHelloWorldServerHandler extends SimpleChannelInboundHandler<HttpObject> {

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) {
        ctx.flush();
    }

    @Override
    public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
        if (msg instanceof HttpRequest) {
            HttpRequest req = (HttpRequest) msg;

            String hello = HttpHelloWorldServer.content(ctx);

            boolean keepAlive = HttpUtil.isKeepAlive(req);
            FullHttpResponse response = new DefaultFullHttpResponse(
                    req.protocolVersion(), OK,
                    Unpooled.copiedBuffer(hello, StandardCharsets.UTF_8));
            response.headers()
                    .set(CONTENT_TYPE, TEXT_PLAIN)
                    .setInt(CONTENT_LENGTH, response.content().readableBytes());

            if (keepAlive) {
                if (!req.protocolVersion().isKeepAliveDefault()) {
                    response.headers().set(CONNECTION, KEEP_ALIVE);
                }
            } else {
                // Tell the client we're going to close the connection.
                response.headers().set(CONNECTION, CLOSE);
            }

            ChannelFuture f = ctx.write(response);

            if (!keepAlive) {
                f.addListener(ChannelFutureListener.CLOSE);
            }
        }
    }

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

Frequently Asked Questions

What is the HttpHelloWorldServerHandler class?
HttpHelloWorldServerHandler is a class in the netty codebase, defined in testsuite-jpms/src/main/java/io/netty/testsuite_jpms/main/HttpHelloWorldServerHandler.java.
Where is HttpHelloWorldServerHandler defined?
HttpHelloWorldServerHandler is defined in testsuite-jpms/src/main/java/io/netty/testsuite_jpms/main/HttpHelloWorldServerHandler.java at line 40.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free