View Javadoc

1   /**
2      This file is part of Waarp Project.
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 Waarp 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     Waarp 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 Waarp .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package org.waarp.ftp.core.data.handler.ftps;
22  
23  import io.netty.channel.ChannelPipeline;
24  import io.netty.channel.socket.SocketChannel;
25  import io.netty.handler.traffic.ChannelTrafficShapingHandler;
26  
27  import org.waarp.ftp.core.command.FtpArgumentCode.TransferMode;
28  import org.waarp.ftp.core.command.FtpArgumentCode.TransferStructure;
29  import org.waarp.ftp.core.config.FtpConfiguration;
30  import org.waarp.ftp.core.data.handler.DataBusinessHandler;
31  import org.waarp.ftp.core.data.handler.DataNetworkHandler;
32  import org.waarp.ftp.core.data.handler.FtpDataModeCodec;
33  import org.waarp.ftp.core.data.handler.FtpDataInitializer;
34  
35  /**
36   * @author "Frederic Bregier"
37   *
38   */
39  public class FtpsDataInitializer extends FtpDataInitializer {
40  
41      /**
42       * Constructor which Initializes some data
43       * 
44       * @param dataBusinessHandler
45       * @param configuration
46       * @param active
47       */
48      public FtpsDataInitializer(
49              Class<? extends DataBusinessHandler> dataBusinessHandler,
50              FtpConfiguration configuration, boolean active) {
51          super(dataBusinessHandler, configuration, active);
52      }
53  
54      /**
55       * Create the pipeline with Handler, ObjectDecoder, ObjectEncoder.
56       * 
57       */
58      @Override
59      public void initChannel(SocketChannel ch) throws Exception {
60          ChannelPipeline pipeline = ch.pipeline();
61          // SSL will be added in this handler during channelActive
62          pipeline.addLast(new FtpsTemporaryFirstHandler(configuration, isActive));
63          // Add default codec but they will change during the channelActive
64          pipeline.addLast(FtpDataInitializer.CODEC_MODE, new FtpDataModeCodec(TransferMode.STREAM,
65                  TransferStructure.FILE));
66          pipeline.addLast(FtpDataInitializer.CODEC_LIMIT, configuration
67                  .getFtpInternalConfiguration()
68                  .getGlobalTrafficShapingHandler());
69          ChannelTrafficShapingHandler limitChannel =
70                  configuration
71                          .getFtpInternalConfiguration()
72                          .newChannelTrafficShapingHandler();
73          if (limitChannel != null) {
74              pipeline.addLast(FtpDataInitializer.CODEC_LIMIT + "CHANNEL", limitChannel);
75          }
76          pipeline.addLast(FtpDataInitializer.CODEC_TYPE, ftpDataTypeCodec);
77          pipeline.addLast(FtpDataInitializer.CODEC_STRUCTURE, ftpDataStructureCodec);
78          // and then business logic. New one on every connection
79          DataBusinessHandler newbusiness = dataBusinessHandler.newInstance();
80          DataNetworkHandler newNetworkHandler = new DataNetworkHandler(configuration, newbusiness, isActive);
81          pipeline.addLast(configuration.getFtpInternalConfiguration().getDataExecutor(),
82                  FtpDataInitializer.HANDLER, newNetworkHandler);
83      }
84  }