1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.example.securechat;
17
18 import org.jboss.netty.channel.ChannelPipeline;
19 import org.jboss.netty.channel.ChannelPipelineFactory;
20 import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
21 import org.jboss.netty.handler.codec.frame.Delimiters;
22 import org.jboss.netty.handler.codec.string.StringDecoder;
23 import org.jboss.netty.handler.codec.string.StringEncoder;
24 import org.jboss.netty.handler.ssl.SslContext;
25
26 import static org.jboss.netty.channel.Channels.*;
27
28
29
30
31 public class SecureChatServerPipelineFactory implements ChannelPipelineFactory {
32
33 private final SslContext sslCtx;
34
35 public SecureChatServerPipelineFactory(SslContext sslCtx) {
36 this.sslCtx = sslCtx;
37 }
38
39 public ChannelPipeline getPipeline() {
40 ChannelPipeline pipeline = pipeline();
41
42
43
44
45
46
47 pipeline.addLast("ssl", sslCtx.newHandler());
48
49
50 pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
51 pipeline.addLast("decoder", new StringDecoder());
52 pipeline.addLast("encoder", new StringEncoder());
53
54
55 pipeline.addLast("handler", new SecureChatServerHandler());
56
57 return pipeline;
58 }
59 }