View Javadoc

1   /**
2      This file is part of GoldenGate Project (named also GoldenGate or GG).
3   
4      Copyright 2009, Frederic Bregier, and individual contributors by the @author
5      tags. See the COPYRIGHT.txt in the distribution for a full listing of
6      individual contributors.
7   
8      All GoldenGate Project is free software: you can redistribute it and/or 
9      modify it under the terms of the GNU General Public License as published 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     GoldenGate is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with GoldenGate .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package openr66.protocol.http.adminssl;
22  
23  
24  import java.util.concurrent.ExecutorService;
25  
26  import openr66.protocol.configuration.Configuration;
27  
28  import org.jboss.netty.channel.ChannelPipeline;
29  import org.jboss.netty.channel.ChannelPipelineFactory;
30  import org.jboss.netty.channel.Channels;
31  import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
32  import org.jboss.netty.handler.codec.http.HttpContentCompressor;
33  import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
34  import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
35  import org.jboss.netty.handler.execution.ExecutionHandler;
36  
37  /**
38   * @author Frederic Bregier
39   *
40   */
41  public class HttpSslPipelineFactory implements ChannelPipelineFactory {
42      private final ExecutorService executorService;
43      public boolean useHttpCompression = false;
44      public boolean enableRenegotiation = false;
45  
46      public HttpSslPipelineFactory(boolean useHttpCompression,
47              boolean enableRenegotiation,
48              ExecutorService executor) {
49          this.useHttpCompression = useHttpCompression;
50          this.enableRenegotiation = enableRenegotiation;
51          this.executorService = executor;
52      }
53  
54      @Override
55      public ChannelPipeline getPipeline() {
56          final ChannelPipeline pipeline = Channels.pipeline();
57          // Add SSL handler first to encrypt and decrypt everything.
58          pipeline.addLast("ssl",
59                  Configuration.ggSslContextFactory.initPipelineFactory(true,
60                          false,
61                          enableRenegotiation, executorService));
62  
63          pipeline.addLast("decoder", new HttpRequestDecoder());
64          pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
65          pipeline.addLast("encoder", new HttpResponseEncoder());
66          pipeline.addLast("pipelineExecutor", new ExecutionHandler(
67                  Configuration.configuration.getHttpPipelineExecutor()));
68          if (useHttpCompression) {
69              pipeline.addLast("deflater", new HttpContentCompressor());
70          }
71          pipeline.addLast("handler", new HttpSslHandler());
72          return pipeline;
73      }
74  }