1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package openr66.protocol.http;
22
23 import static org.jboss.netty.channel.Channels.pipeline;
24 import openr66.protocol.configuration.Configuration;
25
26 import org.jboss.netty.channel.ChannelPipeline;
27 import org.jboss.netty.channel.ChannelPipelineFactory;
28 import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
29 import org.jboss.netty.handler.codec.http.HttpContentCompressor;
30 import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
31 import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
32 import org.jboss.netty.handler.execution.ExecutionHandler;
33
34
35
36
37
38
39 public class HttpPipelineFactory implements ChannelPipelineFactory {
40 public boolean useHttpCompression = false;
41 public HttpPipelineFactory(boolean useHttpCompression) {
42 this.useHttpCompression = useHttpCompression;
43 }
44 public ChannelPipeline getPipeline() throws Exception {
45
46 ChannelPipeline pipeline = pipeline();
47
48 pipeline.addLast("decoder", new HttpRequestDecoder());
49 pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
50 pipeline.addLast("encoder", new HttpResponseEncoder());
51 pipeline.addLast("pipelineExecutor", new ExecutionHandler(
52 Configuration.configuration.getHttpPipelineExecutor()));
53 if (useHttpCompression) {
54 pipeline.addLast("deflater", new HttpContentCompressor());
55 }
56 pipeline.addLast("handler", new HttpFormattedHandler());
57 return pipeline;
58 }
59 }