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 goldengate.ftp.exec.adminssl;
22  
23  import goldengate.common.crypto.ssl.GgSecureKeyStore;
24  import goldengate.common.crypto.ssl.GgSslContextFactory;
25  import goldengate.ftp.exec.config.FileBasedConfiguration;
26  
27  import java.util.concurrent.ExecutorService;
28  
29  import org.jboss.netty.channel.ChannelPipeline;
30  import org.jboss.netty.channel.ChannelPipelineFactory;
31  import org.jboss.netty.channel.Channels;
32  import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
33  import org.jboss.netty.handler.codec.http.HttpContentCompressor;
34  import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
35  import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
36  import org.jboss.netty.handler.execution.ExecutionHandler;
37  
38  /**
39   * @author Frederic Bregier
40   *
41   */
42  public class HttpSslPipelineFactory implements ChannelPipelineFactory {
43      public static GgSslContextFactory ggSslContextFactory;
44      public static GgSecureKeyStore ggSecureKeyStore;
45      private final ExecutorService executorService;
46      public boolean useHttpCompression = false;
47      public boolean enableRenegotiation = false;
48  
49      public HttpSslPipelineFactory(boolean useHttpCompression,
50              boolean enableRenegotiation,
51              ExecutorService executor) {
52          this.useHttpCompression = useHttpCompression;
53          this.enableRenegotiation = enableRenegotiation;
54          this.executorService = executor;
55      }
56  
57      @Override
58      public ChannelPipeline getPipeline() {
59          final ChannelPipeline pipeline = Channels.pipeline();
60          // Add SSL handler first to encrypt and decrypt everything.
61          pipeline.addLast("ssl",
62                  ggSslContextFactory.initPipelineFactory(true,
63                          false,
64                          enableRenegotiation, executorService));
65  
66          pipeline.addLast("decoder", new HttpRequestDecoder());
67          pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
68          pipeline.addLast("encoder", new HttpResponseEncoder());
69          pipeline.addLast("pipelineExecutor", new ExecutionHandler(
70                  FileBasedConfiguration.fileBasedConfiguration.getHttpPipelineExecutor()));
71          if (useHttpCompression) {
72              pipeline.addLast("deflater", new HttpContentCompressor());
73          }
74          pipeline.addLast("handler", new HttpSslHandler());
75          return pipeline;
76      }
77  }