HttpHelloWorldServerHandler Class — netty Architecture
Architecture documentation for the HttpHelloWorldServerHandler class in HttpHelloWorldServerHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD d21156b2_704d_97ce_4792_ad34bc69e57f["HttpHelloWorldServerHandler"] f695e699_4a7b_06f2_02b2_8d5300e4bcfe["HttpHelloWorldServerHandler.java"] d21156b2_704d_97ce_4792_ad34bc69e57f -->|defined in| f695e699_4a7b_06f2_02b2_8d5300e4bcfe 69479d53_a61b_c1a7_55f9_15bf16a403c0["channelReadComplete()"] d21156b2_704d_97ce_4792_ad34bc69e57f -->|method| 69479d53_a61b_c1a7_55f9_15bf16a403c0 dfe99b30_4ec0_fab2_6dc2_b98b1d6e8b87["channelRead0()"] d21156b2_704d_97ce_4792_ad34bc69e57f -->|method| dfe99b30_4ec0_fab2_6dc2_b98b1d6e8b87 1d26ed78_1a8f_c116_ffbd_4d9687f6efce["exceptionCaught()"] d21156b2_704d_97ce_4792_ad34bc69e57f -->|method| 1d26ed78_1a8f_c116_ffbd_4d9687f6efce
Relationship Graph
Source Code
example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServerHandler.java lines 37–79
public class HttpHelloWorldServerHandler extends SimpleChannelInboundHandler<HttpObject> {
private static final byte[] CONTENT = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' };
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
ctx.flush();
}
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
if (msg instanceof HttpRequest) {
HttpRequest req = (HttpRequest) msg;
boolean keepAlive = HttpUtil.isKeepAlive(req);
FullHttpResponse response = new DefaultFullHttpResponse(req.protocolVersion(), OK,
Unpooled.wrappedBuffer(CONTENT));
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();
}
}
Source
Frequently Asked Questions
What is the HttpHelloWorldServerHandler class?
HttpHelloWorldServerHandler is a class in the netty codebase, defined in example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServerHandler.java.
Where is HttpHelloWorldServerHandler defined?
HttpHelloWorldServerHandler is defined in example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServerHandler.java at line 37.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free