Ignore:
Timestamp:
Aug 13, 2008, 1:17:55 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

References #114. Upgrading to 1.0.0-M2 release of Apache FTP server.

Location:
extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/BaseFtpServer.java

    r719 r741  
    2525
    2626import java.util.EnumSet;
    27 import java.util.Iterator;
    28 import java.util.Properties;
    29 
    30 import org.apache.ftpserver.ConfigurableFtpServerContext;
     27
     28//import org.apache.ftpserver.ConfigurableFtpServerContext;
    3129import org.apache.ftpserver.FtpServer;
    32 import org.apache.ftpserver.config.PropertiesConfiguration;
    33 import org.apache.ftpserver.ftplet.Configuration;
    34 import org.apache.ftpserver.ftplet.FtpException;
    35 import org.apache.ftpserver.ftplet.Ftplet;
    36 import org.apache.ftpserver.interfaces.FtpServerContext;
     30//import org.apache.ftpserver.config.PropertiesConfiguration;
     31//import org.apache.ftpserver.ftplet.Configuration;
    3732import org.slf4j.Logger;
    3833import org.slf4j.LoggerFactory;
     34import org.springframework.beans.factory.support.DefaultListableBeanFactory;
     35import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
     36import org.springframework.core.io.ClassPathResource;
     37import org.springframework.core.io.DefaultResourceLoader;
    3938
    4039import net.sf.basedb.core.Application;
     
    138137  }
    139138
    140   private final Configuration config;
     139  private final String configFile;
    141140  private FtpServer server;
    142141 
     
    146145    added. To start the FTP server call {@link #start()}.
    147146   
    148     @param config The configuration settings
     147    @param config The path to configuration file (classpath based)
    149148    @throws Exception If there is any problem
    150149  */
    151   public BaseFtpServer(Properties config)
     150  public BaseFtpServer(String configFile)
    152151    throws Exception
    153152  {
    154     this.config = setPropertiesRequiredByBase(config);
     153    this.configFile = configFile;
    155154  }
    156155
     
    170169    if (isRunning()) return;
    171170    log.info("Starting BASE FTP Server");
    172     if (log.isDebugEnabled())
    173     {
    174       Iterator<String> keys = config.getKeys();
    175       while (keys.hasNext())
    176       {
    177         String key = keys.next();
    178         try
    179         {
    180           log.debug(key + "=" + config.getString(key));
    181         }
    182         catch (FtpException ex)
    183         {} // Should never happen
    184       }
    185     }
     171
    186172    try
    187173    {
    188       FtpServerContext context = new ConfigurableFtpServerContext(config);
    189       Ftplet baseFtplet = new BaseFtplet();
    190       baseFtplet.init(context);
    191       context.getFtpletContainer().addFtplet("base", baseFtplet);
    192       server = new FtpServer(context);
     174      ClassLoader classLoader = FtpServer.class.getClassLoader();
     175     
     176      DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
     177      factory.setBeanClassLoader(classLoader);
     178      XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
     179      reader.setResourceLoader(new DefaultResourceLoader(classLoader));
     180      reader.loadBeanDefinitions(new ClassPathResource(configFile, classLoader));
     181      server = (FtpServer)factory.getBean("server");
     182     
     183      //System.out.println("Start FTP server: " + server);
     184      //System.out.println("port: " + server.getListener("default").getPort());
     185     
    193186      server.start();
    194187    }
     
    221214    }
    222215    log.info("BASE FTP Server has been stopped");
    223   }
    224 
    225   /**
    226     Makes a copy of the properties and set BASE-specific ones. Returned
    227     as a {@link Configuration} object.
    228   */
    229   private Configuration setPropertiesRequiredByBase(Properties config)
    230   {
    231     Properties cfg = (Properties)config.clone();
    232     cfg.setProperty("config.create-default-user", "false");
    233     cfg.setProperty("config.connection-manager.anonymous-login-enabled", "false");
    234     cfg.setProperty("config.user-manager.class", "net.sf.basedb.clients.ftp.BaseUserManager");
    235     cfg.setProperty("config.file-system-manager.class", "net.sf.basedb.clients.ftp.BaseFileSystem");
    236     if (log.isDebugEnabled())
    237     {
    238       log.debug("Creating new FTP Server configuration");
    239       for (Object key : cfg.keySet())
    240       {
    241         log.debug(key + "=" + cfg.getProperty(key.toString()));
    242       }
    243     }
    244     return new PropertiesConfiguration(cfg);
    245   }
    246  
    247  
     216  }
    248217}
  • extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/BaseUser.java

    r716 r741  
    177177
    178178  @Override
    179   public Authority[] getAuthorities(Class<Authority> clazz)
     179  public Authority[] getAuthorities(Class<? extends Authority> clazz)
    180180  {
    181181    List<Authority> selected = new ArrayList<Authority>();
  • extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/FtpServiceController.java

    r719 r741  
    2626import java.io.InputStream;
    2727import java.net.URL;
    28 import java.util.Properties;
    2928
    3029import org.slf4j.Logger;
     
    4948  private static final Logger log = LoggerFactory.getLogger(FtpServiceController.class);
    5049
    51   private final String config;
     50  private final String configFile;
    5251  private BaseFtpServer server;
    5352 
     
    5554    Creates a new service controller action for controlling
    5655    a single ftp server service
    57     @param server The server to control with this action
     56    @param configFile The path to configuration file (classpath based),
     57      if null the default (/ftp-config.xml) is used
    5858  */
    59   public FtpServiceController(String config)
     59  public FtpServiceController(String configFile)
    6060  {
    61     this.config = config == null ? "/ftp.config" : config;
     61    this.configFile = configFile == null ? "/ftp-config.xml" : configFile;
    6262  }
    6363 
     
    119119      try
    120120      {
    121         log.debug("config=" + config);
    122         URL configUrl = BaseFtpServer.class.getResource(config);
     121        log.debug("configuration file=" + configFile);
     122        URL configUrl = BaseFtpServer.class.getResource(configFile);
    123123        InputStream is = configUrl == null ? null : configUrl.openStream();
    124124        if (is == null)
    125125        {
    126           throw new ConfigurationException("Can't find the properties file. " +
    127               "Make sure '" + config + "' is in the CLASSPATH.");
     126          throw new ConfigurationException("Can't find the configuration file. " +
     127              "Make sure '" + configFile + "' is in the CLASSPATH.");
    128128        }
    129         Properties config = new Properties();
    130         config.load(is);
    131         is.close();
    132         server = new BaseFtpServer(config);
     129        server = new BaseFtpServer(configFile);
    133130        log.info("BASE FTP Server created successfully");
    134131      }
  • extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/FtpServiceControllerFactory.java

    r717 r741  
    4040  <ul>
    4141  <li>{@link #setConfig(String)}: The path to the configuration file. The
    42     default is: <code>/ftp.config</code>
     42    default is: <code>/ftp-config.xml</code>
    4343  </ul>
    4444 
     
    8383    Set the path to the configuration file to use. The path
    8484    should be a path on the CLASSPATH.
    85     @param config The path, or null to use the default path (/ftp.config)
     85    @param config The path, or null to use the default path (/ftp-config.xml)
    8686  */
    8787  public void setConfig(String config)
Note: See TracChangeset for help on using the changeset viewer.