View Javadoc

1   /**
2    * Copyright 2009, Frederic Bregier, and individual contributors by the @author
3    * tags. See the COPYRIGHT.txt in the distribution for a full listing of
4    * individual contributors.
5    *
6    * This is free software; you can redistribute it and/or modify it under the
7    * terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation; either version 3.0 of the License, or (at your option)
9    * any later version.
10   *
11   * This software is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14   * details.
15   *
16   * You should have received a copy of the GNU Lesser General Public License
17   * along with this software; if not, write to the Free Software Foundation,
18   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
19   * site: http://www.fsf.org.
20   */
21  package goldengate.ftp.exec;
22  
23  import goldengate.common.file.filesystembased.FilesystemBasedDirImpl;
24  import goldengate.common.file.filesystembased.FilesystemBasedFileParameterImpl;
25  import goldengate.common.file.filesystembased.specific.FilesystemBasedDirJdk5;
26  import goldengate.common.file.filesystembased.specific.FilesystemBasedDirJdk6;
27  import goldengate.common.logging.GgInternalLogger;
28  import goldengate.common.logging.GgInternalLoggerFactory;
29  import goldengate.common.logging.GgSlf4JLoggerFactory;
30  import goldengate.ftp.core.config.FtpConfiguration;
31  import goldengate.ftp.core.exception.FtpNoConnectionException;
32  import goldengate.ftp.exec.config.FileBasedConfiguration;
33  import goldengate.ftp.exec.control.ExecBusinessHandler;
34  import goldengate.ftp.exec.data.FileSystemBasedDataBusinessHandler;
35  import goldengate.ftp.exec.exec.AbstractExecutor;
36  
37  import openr66.protocol.configuration.Configuration;
38  
39  import org.jboss.netty.logging.InternalLoggerFactory;
40  
41  /**
42   * Exec FTP Server using simple authentication (XML FileInterface based),
43   * and standard Directory and FileInterface implementation (Filesystem based).
44   *
45   * @author Frederic Bregier
46   *
47   */
48  public class ExecGatewayFtpServer {
49      /**
50       * Internal Logger
51       */
52      private static GgInternalLogger logger = null;
53  
54      /**
55       * Take a simple XML file as configuration.
56       *
57       * @param args
58       */
59      public static void main(String[] args) {
60          if (args.length < 1) {
61              System.err.println("Usage: " +
62                      ExecGatewayFtpServer.class.getName() + " <config-file> [<r66config-file>]");
63              return;
64          }
65          InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(null));
66          logger = GgInternalLoggerFactory
67                  .getLogger(ExecGatewayFtpServer.class);
68          String config = args[0];
69          FileBasedConfiguration configuration = new FileBasedConfiguration(
70                  ExecGatewayFtpServer.class, ExecBusinessHandler.class,
71                  FileSystemBasedDataBusinessHandler.class,
72                  new FilesystemBasedFileParameterImpl());
73          if (!configuration.setConfigurationServerFromXml(config)) {
74              System.err.println("Bad main configuration");
75              return;
76          }
77          Configuration.configuration.useLocalExec = configuration.useLocalExec;
78          // Init according JDK
79          if (FtpConfiguration.USEJDK6) {
80              FilesystemBasedDirImpl.initJdkDependent(new FilesystemBasedDirJdk6());
81          } else {
82              FilesystemBasedDirImpl.initJdkDependent(new FilesystemBasedDirJdk5());
83          }
84          if (AbstractExecutor.useDatabase) {
85              // Use R66 module
86              if (args.length > 1) {
87                  if (! openr66.configuration.FileBasedConfiguration.setSubmitClientConfigurationFromXml(Configuration.configuration, 
88                          args[1])) {
89                  //if (!R66FileBasedConfiguration.setSimpleClientConfigurationFromXml(args[1])) {
90                      System.err.println("Bad R66 configuration");
91                      return;
92                  }
93              } else {
94                  // Cannot get R66 functional
95                  System.err.println("No R66PrepareTransfer configuration file");
96              }
97          }
98          FileBasedConfiguration.fileBasedConfiguration = configuration;
99          // Start server.
100         configuration.configureLExec();
101         configuration.serverStartup();
102         configuration.configureHttps();
103         configuration.configureConstraint();
104         try {
105             configuration.configureSnmp();
106         } catch (FtpNoConnectionException e) {
107             System.err.println("Cannot start SNMP support: "+e.getMessage());
108         }
109         logger.warn("FTP started");
110     }
111 
112 }