1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.example.http.snoop;
17
18 import static org.jboss.netty.channel.Channels.*;
19
20 import javax.net.ssl.SSLEngine;
21
22 import org.jboss.netty.channel.ChannelPipeline;
23 import org.jboss.netty.channel.ChannelPipelineFactory;
24 import org.jboss.netty.example.securechat.SecureChatSslContextFactory;
25 import org.jboss.netty.handler.codec.http.HttpClientCodec;
26 import org.jboss.netty.handler.codec.http.HttpContentDecompressor;
27 import org.jboss.netty.handler.ssl.SslHandler;
28
29
30
31
32
33
34
35
36 public class HttpClientPipelineFactory implements ChannelPipelineFactory {
37
38 private final boolean ssl;
39
40 public HttpClientPipelineFactory(boolean ssl) {
41 this.ssl = ssl;
42 }
43
44 public ChannelPipeline getPipeline() throws Exception {
45
46 ChannelPipeline pipeline = pipeline();
47
48
49 if (ssl) {
50 SSLEngine engine =
51 SecureChatSslContextFactory.getClientContext().createSSLEngine();
52 engine.setUseClientMode(true);
53
54 pipeline.addLast("ssl", new SslHandler(engine));
55 }
56
57 pipeline.addLast("codec", new HttpClientCodec());
58
59
60 pipeline.addLast("inflater", new HttpContentDecompressor());
61
62
63
64
65 pipeline.addLast("handler", new HttpResponseHandler());
66 return pipeline;
67 }
68 }