Changeset 741 for extensions/net.sf.basedb.ftp/trunk/src/net
- Timestamp:
- Aug 13, 2008, 1:17:55 PM (15 years ago)
- 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 25 25 26 26 import 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; 31 29 import 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; 37 32 import org.slf4j.Logger; 38 33 import org.slf4j.LoggerFactory; 34 import org.springframework.beans.factory.support.DefaultListableBeanFactory; 35 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; 36 import org.springframework.core.io.ClassPathResource; 37 import org.springframework.core.io.DefaultResourceLoader; 39 38 40 39 import net.sf.basedb.core.Application; … … 138 137 } 139 138 140 private final Configuration config;139 private final String configFile; 141 140 private FtpServer server; 142 141 … … 146 145 added. To start the FTP server call {@link #start()}. 147 146 148 @param config The configuration settings147 @param config The path to configuration file (classpath based) 149 148 @throws Exception If there is any problem 150 149 */ 151 public BaseFtpServer( Properties config)150 public BaseFtpServer(String configFile) 152 151 throws Exception 153 152 { 154 this.config = setPropertiesRequiredByBase(config);153 this.configFile = configFile; 155 154 } 156 155 … … 170 169 if (isRunning()) return; 171 170 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 186 172 try 187 173 { 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 193 186 server.start(); 194 187 } … … 221 214 } 222 215 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 } 248 217 } -
extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/BaseUser.java
r716 r741 177 177 178 178 @Override 179 public Authority[] getAuthorities(Class< Authority> clazz)179 public Authority[] getAuthorities(Class<? extends Authority> clazz) 180 180 { 181 181 List<Authority> selected = new ArrayList<Authority>(); -
extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/FtpServiceController.java
r719 r741 26 26 import java.io.InputStream; 27 27 import java.net.URL; 28 import java.util.Properties;29 28 30 29 import org.slf4j.Logger; … … 49 48 private static final Logger log = LoggerFactory.getLogger(FtpServiceController.class); 50 49 51 private final String config ;50 private final String configFile; 52 51 private BaseFtpServer server; 53 52 … … 55 54 Creates a new service controller action for controlling 56 55 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 58 58 */ 59 public FtpServiceController(String config )59 public FtpServiceController(String configFile) 60 60 { 61 this.config = config == null ? "/ftp.config" : config;61 this.configFile = configFile == null ? "/ftp-config.xml" : configFile; 62 62 } 63 63 … … 119 119 try 120 120 { 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); 123 123 InputStream is = configUrl == null ? null : configUrl.openStream(); 124 124 if (is == null) 125 125 { 126 throw new ConfigurationException("Can't find the propertiesfile. " +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."); 128 128 } 129 Properties config = new Properties(); 130 config.load(is); 131 is.close(); 132 server = new BaseFtpServer(config); 129 server = new BaseFtpServer(configFile); 133 130 log.info("BASE FTP Server created successfully"); 134 131 } -
extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/FtpServiceControllerFactory.java
r717 r741 40 40 <ul> 41 41 <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> 43 43 </ul> 44 44 … … 83 83 Set the path to the configuration file to use. The path 84 84 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) 86 86 */ 87 87 public void setConfig(String config)
Note: See TracChangeset
for help on using the changeset viewer.