1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.example.http.helloworld;
17
18 import io.netty.channel.ChannelInitializer;
19 import io.netty.channel.ChannelPipeline;
20 import io.netty.channel.socket.SocketChannel;
21 import io.netty.handler.codec.http.HttpServerCodec;
22 import io.netty.handler.ssl.SslContext;
23
24 public class HttpHelloWorldServerInitializer extends ChannelInitializer<SocketChannel> {
25
26 private final SslContext sslCtx;
27
28 public HttpHelloWorldServerInitializer(SslContext sslCtx) {
29 this.sslCtx = sslCtx;
30 }
31
32 @Override
33 public void initChannel(SocketChannel ch) {
34 ChannelPipeline p = ch.pipeline();
35 if (sslCtx != null) {
36 p.addLast(sslCtx.newHandler(ch.alloc()));
37 }
38 p.addLast(new HttpServerCodec());
39 p.addLast(new HttpHelloWorldServerHandler());
40 }
41 }