You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jo...@apache.org on 2013/02/20 19:32:16 UTC
svn commit: r1448341 - in /commons/proper/vfs/trunk:
core/src/main/java/org/apache/commons/vfs2/provider/ftp/
core/src/main/java/org/apache/commons/vfs2/provider/ftps/
core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/ src/changes/
Author: joehni
Date: Wed Feb 20 18:32:16 2013
New Revision: 1448341
URL: http://svn.apache.org/r1448341
Log:
FTPS provider missed functionality and bug fixes already available for the FTP provider.
Added:
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/AbstractFtpsProviderTestCase.java
- copied, changed from r1448031, commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderTestCase_Disabled.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderExplicitTestCase.java (with props)
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderImplicitTestCase_Disabled.java (with props)
Removed:
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderTestCase_Disabled.java
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientFactory.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientWrapper.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderPROTTestCase_Disabled.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/MultipleConnectionTestCase.java
commons/proper/vfs/trunk/src/changes/changes.xml
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java?rev=1448341&r1=1448340&r2=1448341&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java Wed Feb 20 18:32:16 2013
@@ -32,16 +32,15 @@ import org.apache.commons.vfs2.util.User
/**
* A wrapper to the FTPClient to allow automatic reconnect on connection loss.<br />
* I decided to not to use eg. noop() to determine the state of the connection to avoid
- * unnecesary server round-trips.
+ * unnecessary server round-trips.
*/
-class FTPClientWrapper implements FtpClient
+public class FTPClientWrapper implements FtpClient
{
private final GenericFileName root;
- private final FileSystemOptions fileSystemOptions;
-
+ protected final FileSystemOptions fileSystemOptions;
private FTPClient ftpClient;
- FTPClientWrapper(final GenericFileName root, final FileSystemOptions fileSystemOptions) throws FileSystemException
+ protected FTPClientWrapper(final GenericFileName root, final FileSystemOptions fileSystemOptions) throws FileSystemException
{
this.root = root;
this.fileSystemOptions = fileSystemOptions;
@@ -67,14 +66,7 @@ class FTPClientWrapper implements FtpCli
{
authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, FtpFileProvider.AUTHENTICATOR_TYPES);
- return FtpClientFactory.createConnection(rootName.getHostName(),
- rootName.getPort(),
- UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
- UserAuthenticatorUtils.toChar(rootName.getUserName())),
- UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
- UserAuthenticatorUtils.toChar(rootName.getPassword())),
- rootName.getPath(),
- getFileSystemOptions());
+ return createClient(rootName, authData);
}
finally
{
@@ -82,6 +74,19 @@ class FTPClientWrapper implements FtpCli
}
}
+ protected FTPClient createClient(final GenericFileName rootName, final UserAuthenticationData authData)
+ throws FileSystemException
+ {
+ return FtpClientFactory.createConnection(
+ rootName.getHostName(),
+ rootName.getPort(),
+ UserAuthenticatorUtils.getData(
+ authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())),
+ UserAuthenticatorUtils.getData(
+ authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())),
+ rootName.getPath(), getFileSystemOptions());
+ }
+
private FTPClient getFtpClient() throws FileSystemException
{
if (ftpClient == null)
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java?rev=1448341&r1=1448340&r2=1448341&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java Wed Feb 20 18:32:16 2013
@@ -31,12 +31,10 @@ import org.apache.commons.vfs2.util.User
*/
public final class FtpClientFactory
{
- private static final int BUFSZ = 40;
-
private FtpClientFactory()
{
}
-
+
/**
* Creates a new connection to the server.
*
@@ -53,171 +51,205 @@ public final class FtpClientFactory
final String workingDirectory, final FileSystemOptions fileSystemOptions)
throws FileSystemException
{
- // Determine the username and password to use
- if (username == null)
- {
- username = "anonymous".toCharArray();
- }
-
- if (password == null)
- {
- password = "anonymous".toCharArray();
- }
-
- try
- {
- final FTPClient client = new FTPClient();
-
- configureClient(fileSystemOptions, client);
-
- final FTPFileEntryParserFactory myFactory =
- FtpFileSystemConfigBuilder.getInstance().getEntryParserFactory(fileSystemOptions);
- if (myFactory != null)
- {
- client.setParserFactory(myFactory);
- }
-
- try
- {
- // Set connect timeout
- final Integer connectTimeout = FtpFileSystemConfigBuilder.getInstance().getConnectTimeout(fileSystemOptions);
- if (connectTimeout != null)
- {
- client.setDefaultTimeout(connectTimeout.intValue());
- }
-
- final String controlEncoding = FtpFileSystemConfigBuilder.getInstance().getControlEncoding(fileSystemOptions);
- if (controlEncoding != null)
- {
- client.setControlEncoding(controlEncoding);
- }
-
- client.connect(hostname, port);
-
- final int reply = client.getReplyCode();
- if (!FTPReply.isPositiveCompletion(reply))
- {
- throw new FileSystemException("vfs.provider.ftp/connect-rejected.error", hostname);
- }
-
- // Login
- if (!client.login(
- UserAuthenticatorUtils.toString(username),
- UserAuthenticatorUtils.toString(password)))
- {
- throw new FileSystemException("vfs.provider.ftp/login.error",
- hostname, UserAuthenticatorUtils.toString(username));
- }
-
- FtpFileType fileType = FtpFileSystemConfigBuilder.getInstance().getFileType(fileSystemOptions);
- if (fileType == null)
- {
- fileType = FtpFileType.BINARY;
- }
- // Set binary mode
- if (!client.setFileType(fileType.getValue()))
- {
- throw new FileSystemException("vfs.provider.ftp/set-file-type.error", fileType);
- }
-
- // Set dataTimeout value
- final Integer dataTimeout = FtpFileSystemConfigBuilder.getInstance().getDataTimeout(fileSystemOptions);
- if (dataTimeout != null)
- {
- client.setDataTimeout(dataTimeout.intValue());
- }
-
- final Integer socketTimeout = FtpFileSystemConfigBuilder.getInstance().getSoTimeout(fileSystemOptions);
- if (socketTimeout != null)
- {
- client.setSoTimeout(socketTimeout.intValue());
- }
-
- // Change to root by default
- // All file operations a relative to the filesystem-root
- // String root = getRoot().getName().getPath();
-
- final Boolean userDirIsRoot = FtpFileSystemConfigBuilder.getInstance().getUserDirIsRoot(fileSystemOptions);
- if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue()))
- {
- if (!client.changeWorkingDirectory(workingDirectory))
- {
- throw new FileSystemException("vfs.provider.ftp/change-work-directory.error", workingDirectory);
- }
- }
-
- final Boolean passiveMode = FtpFileSystemConfigBuilder.getInstance().getPassiveMode(fileSystemOptions);
- if (passiveMode != null && passiveMode.booleanValue())
- {
- client.enterLocalPassiveMode();
- }
-
- }
- catch (final IOException e)
- {
- if (client.isConnected())
- {
- client.disconnect();
- }
- throw e;
- }
-
- return client;
- }
- catch (final Exception exc)
- {
- throw new FileSystemException("vfs.provider.ftp/connect.error", exc, hostname);
- }
+ final FtpConnectionFactory factory = new FtpConnectionFactory(FtpFileSystemConfigBuilder.getInstance());
+ return factory.createConnection(hostname, port, username, password, workingDirectory, fileSystemOptions);
}
+
+ public static class FtpConnectionFactory extends ConnectionFactory<FTPClient, FtpFileSystemConfigBuilder> {
+ private FtpConnectionFactory(FtpFileSystemConfigBuilder builder)
+ {
+ super(builder);
+ }
+
+ @Override
+ protected FTPClient createClient(final FileSystemOptions fileSystemOptions)
+ {
+ return new FTPClient();
+ }
+ }
+
+ public static abstract class ConnectionFactory<C extends FTPClient, B extends FtpFileSystemConfigBuilder> {
+ private static final char[] ANON_CHAR_ARRAY = "anonymous".toCharArray();
+ private static final int BUFSZ = 40;
- private static void configureClient(final FileSystemOptions fileSystemOptions, final FTPClient client)
- {
- final String key = FtpFileSystemConfigBuilder.getInstance().getEntryParser(fileSystemOptions);
- if (key != null)
- {
- final FTPClientConfig config = new FTPClientConfig(key);
-
- final String serverLanguageCode =
- FtpFileSystemConfigBuilder.getInstance().getServerLanguageCode(fileSystemOptions);
- if (serverLanguageCode != null)
- {
- config.setServerLanguageCode(serverLanguageCode);
- }
- final String defaultDateFormat =
- FtpFileSystemConfigBuilder.getInstance().getDefaultDateFormat(fileSystemOptions);
- if (defaultDateFormat != null)
- {
- config.setDefaultDateFormatStr(defaultDateFormat);
- }
- final String recentDateFormat =
- FtpFileSystemConfigBuilder.getInstance().getRecentDateFormat(fileSystemOptions);
- if (recentDateFormat != null)
- {
- config.setRecentDateFormatStr(recentDateFormat);
- }
- final String serverTimeZoneId =
- FtpFileSystemConfigBuilder.getInstance().getServerTimeZoneId(fileSystemOptions);
- if (serverTimeZoneId != null)
- {
- config.setServerTimeZoneId(serverTimeZoneId);
- }
- final String[] shortMonthNames =
- FtpFileSystemConfigBuilder.getInstance().getShortMonthNames(fileSystemOptions);
- if (shortMonthNames != null)
- {
- final StringBuilder shortMonthNamesStr = new StringBuilder(BUFSZ);
- for (final String shortMonthName : shortMonthNames)
- {
- if (shortMonthNamesStr.length() > 0)
- {
- shortMonthNamesStr.append("|");
- }
- shortMonthNamesStr.append(shortMonthName);
- }
- config.setShortMonthNames(shortMonthNamesStr.toString());
- }
+ protected B builder;
- client.configure(config);
+ protected ConnectionFactory(B builder)
+ {
+ this.builder = builder;
}
+
+ public C createConnection(final String hostname, final int port, char[] username, char[] password,
+ final String workingDirectory, final FileSystemOptions fileSystemOptions) throws FileSystemException
+ {
+ // Determine the username and password to use
+ if (username == null)
+ {
+ username = ANON_CHAR_ARRAY;
+ }
+
+ if (password == null)
+ {
+ password = ANON_CHAR_ARRAY;
+ }
+
+ try
+ {
+ final C client = createClient(fileSystemOptions);
+
+ configureClient(fileSystemOptions, client);
+
+ final FTPFileEntryParserFactory myFactory =
+ builder.getEntryParserFactory(fileSystemOptions);
+ if (myFactory != null)
+ {
+ client.setParserFactory(myFactory);
+ }
+
+ try
+ {
+ // Set connect timeout
+ final Integer connectTimeout = builder.getConnectTimeout(fileSystemOptions);
+ if (connectTimeout != null)
+ {
+ client.setDefaultTimeout(connectTimeout.intValue());
+ }
+
+ final String controlEncoding = builder.getControlEncoding(fileSystemOptions);
+ if (controlEncoding != null)
+ {
+ client.setControlEncoding(controlEncoding);
+ }
+
+ client.connect(hostname, port);
+
+ final int reply = client.getReplyCode();
+ if (!FTPReply.isPositiveCompletion(reply))
+ {
+ throw new FileSystemException("vfs.provider.ftp/connect-rejected.error", hostname);
+ }
+
+ // Login
+ if (!client.login(
+ UserAuthenticatorUtils.toString(username),
+ UserAuthenticatorUtils.toString(password)))
+ {
+ throw new FileSystemException("vfs.provider.ftp/login.error",
+ hostname, UserAuthenticatorUtils.toString(username));
+ }
+
+ FtpFileType fileType = builder.getFileType(fileSystemOptions);
+ if (fileType == null)
+ {
+ fileType = FtpFileType.BINARY;
+ }
+ // Set binary mode
+ if (!client.setFileType(fileType.getValue()))
+ {
+ throw new FileSystemException("vfs.provider.ftp/set-file-type.error", fileType);
+ }
+
+ // Set dataTimeout value
+ final Integer dataTimeout = builder.getDataTimeout(fileSystemOptions);
+ if (dataTimeout != null)
+ {
+ client.setDataTimeout(dataTimeout.intValue());
+ }
+
+ final Integer socketTimeout = builder.getSoTimeout(fileSystemOptions);
+ if (socketTimeout != null)
+ {
+ client.setSoTimeout(socketTimeout.intValue());
+ }
+
+ // Change to root by default
+ // All file operations a relative to the filesystem-root
+ // String root = getRoot().getName().getPath();
+
+ final Boolean userDirIsRoot = builder.getUserDirIsRoot(fileSystemOptions);
+ if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue()))
+ {
+ if (!client.changeWorkingDirectory(workingDirectory))
+ {
+ throw new FileSystemException("vfs.provider.ftp/change-work-directory.error", workingDirectory);
+ }
+ }
+
+ final Boolean passiveMode = builder.getPassiveMode(fileSystemOptions);
+ if (passiveMode != null && passiveMode.booleanValue())
+ {
+ client.enterLocalPassiveMode();
+ }
+
+ }
+ catch (final IOException e)
+ {
+ if (client.isConnected())
+ {
+ client.disconnect();
+ }
+ throw e;
+ }
+
+ return client;
+ }
+ catch (final Exception exc)
+ {
+ throw new FileSystemException("vfs.provider.ftp/connect.error", exc, hostname);
+ }
+ }
+
+ protected abstract C createClient(final FileSystemOptions fileSystemOptions) throws FileSystemException;
+
+ private void configureClient(final FileSystemOptions fileSystemOptions, final C client)
+ {
+ final String key = builder.getEntryParser(fileSystemOptions);
+ if (key != null)
+ {
+ final FTPClientConfig config = new FTPClientConfig(key);
+
+ final String serverLanguageCode =
+ builder.getServerLanguageCode(fileSystemOptions);
+ if (serverLanguageCode != null)
+ {
+ config.setServerLanguageCode(serverLanguageCode);
+ }
+ final String defaultDateFormat =
+ builder.getDefaultDateFormat(fileSystemOptions);
+ if (defaultDateFormat != null)
+ {
+ config.setDefaultDateFormatStr(defaultDateFormat);
+ }
+ final String recentDateFormat =
+ builder.getRecentDateFormat(fileSystemOptions);
+ if (recentDateFormat != null)
+ {
+ config.setRecentDateFormatStr(recentDateFormat);
+ }
+ final String serverTimeZoneId =
+ builder.getServerTimeZoneId(fileSystemOptions);
+ if (serverTimeZoneId != null)
+ {
+ config.setServerTimeZoneId(serverTimeZoneId);
+ }
+ final String[] shortMonthNames =
+ builder.getShortMonthNames(fileSystemOptions);
+ if (shortMonthNames != null)
+ {
+ final StringBuilder shortMonthNamesStr = new StringBuilder(BUFSZ);
+ for (final String shortMonthName : shortMonthNames)
+ {
+ if (shortMonthNamesStr.length() > 0)
+ {
+ shortMonthNamesStr.append("|");
+ }
+ shortMonthNamesStr.append(shortMonthName);
+ }
+ config.setShortMonthNames(shortMonthNamesStr.toString());
+ }
+
+ client.configure(config);
+ }
+ }
}
}
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java?rev=1448341&r1=1448340&r2=1448341&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java Wed Feb 20 18:32:16 2013
@@ -24,7 +24,7 @@ import org.apache.commons.vfs2.FileSyste
/**
* The config builder for various ftp configuration options.
*/
-public final class FtpFileSystemConfigBuilder extends FileSystemConfigBuilder
+public class FtpFileSystemConfigBuilder extends FileSystemConfigBuilder
{
private static final String _PREFIX = FtpFileSystemConfigBuilder.class.getName();
@@ -59,6 +59,11 @@ public final class FtpFileSystemConfigBu
{
super("ftp.");
}
+
+ /** @since 2.1 */
+ protected FtpFileSystemConfigBuilder(String prefix) {
+ super(prefix);
+ }
@Override
protected Class<? extends FileSystem> getConfigClass()
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientFactory.java?rev=1448341&r1=1448340&r2=1448341&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientFactory.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientFactory.java Wed Feb 20 18:32:16 2013
@@ -16,16 +16,14 @@
*/
package org.apache.commons.vfs2.provider.ftps;
-import java.io.IOException;
-import org.apache.commons.net.ftp.FTP;
-import org.apache.commons.net.ftp.FTPClientConfig;
-import org.apache.commons.net.ftp.FTPReply;
+import javax.net.ssl.TrustManager;
+
import org.apache.commons.net.ftp.FTPSClient;
-import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
+import org.apache.commons.net.util.TrustManagerUtils;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemOptions;
-import org.apache.commons.vfs2.util.UserAuthenticatorUtils;
+import org.apache.commons.vfs2.provider.ftp.FtpClientFactory;
/**
* Create FTPSClient instances.
@@ -34,8 +32,9 @@ import org.apache.commons.vfs2.util.User
*/
public final class FtpsClientFactory
{
- private static final char[] ANON_CHAR_ARRAY = "anonymous".toCharArray();
- private static final int SHORT_MONTH_NAME_LEN = 40;
+ private FtpsClientFactory()
+ {
+ }
/**
* Creates a new connection to the server.
@@ -51,178 +50,39 @@ public final class FtpsClientFactory
public static FTPSClient createConnection(final String hostname, final int port, char[] username, char[] password,
final String workingDirectory, final FileSystemOptions fileSystemOptions) throws FileSystemException
{
- // Determine the username and password to use
- if (username == null)
- {
- username = ANON_CHAR_ARRAY;
- }
-
- if (password == null)
- {
- password = ANON_CHAR_ARRAY;
- }
-
- try
- {
-
- final FTPSClient client = createFTPSClient(fileSystemOptions);
-
- final String key = FtpsFileSystemConfigBuilder.getInstance().getEntryParser(fileSystemOptions);
- if (key != null)
- {
- final FTPClientConfig config = createFTPClientConfig(fileSystemOptions, key);
- client.configure(config);
- }
-
- final FTPFileEntryParserFactory myFactory = FtpsFileSystemConfigBuilder.getInstance().getEntryParserFactory(
- fileSystemOptions);
- if (myFactory != null)
- {
- client.setParserFactory(myFactory);
- }
-
- try
- {
- client.connect(hostname, port);
-
- // For VFS-412
- // String execPROT = FtpsFileSystemConfigBuilder.getInstance().getDataChannelProtectionLevel(
- // fileSystemOptions);
- // if (execPROT != null)
- // {
- // client.execPROT(execPROT);
- // }
-
- final int reply = client.getReplyCode();
- if (!FTPReply.isPositiveCompletion(reply))
- {
- throw new FileSystemException("vfs.provider.ftp/connect-rejected.error", hostname);
- }
-
- // Login
- if (!client.login(UserAuthenticatorUtils.toString(username), UserAuthenticatorUtils.toString(password)))
- {
- throw new FileSystemException("vfs.provider.ftp/login.error", hostname,
- UserAuthenticatorUtils.toString(username));
- }
-
- // Set binary mode
- if (!client.setFileType(FTP.BINARY_FILE_TYPE))
- {
- throw new FileSystemException("vfs.provider.ftp/set-binary.error", hostname);
- }
-
- // Set dataTimeout value
- final Integer dataTimeout = FtpsFileSystemConfigBuilder.getInstance().getDataTimeout(fileSystemOptions);
- if (dataTimeout != null)
- {
- client.setDataTimeout(dataTimeout.intValue());
- }
-
- // Change to root by default
- // All file operations a relative to the filesystem-root
- // String root = getRoot().getName().getPath();
-
- final Boolean userDirIsRoot = FtpsFileSystemConfigBuilder.getInstance().getUserDirIsRoot(fileSystemOptions);
- if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue()))
- {
- if (!client.changeWorkingDirectory(workingDirectory))
- {
- throw new FileSystemException("vfs.provider.ftp/change-work-directory.error", workingDirectory);
- }
- }
-
- final Boolean passiveMode = FtpsFileSystemConfigBuilder.getInstance().getPassiveMode(fileSystemOptions);
- if (passiveMode != null && passiveMode.booleanValue())
- {
- client.enterLocalPassiveMode();
- }
- }
- catch (final IOException e)
- {
- if (client.isConnected())
- {
- client.disconnect();
- }
- throw e;
- }
-
- return client;
- }
- catch (final Exception exc)
- {
- throw new FileSystemException("vfs.provider.sftp/connect.error", exc, hostname);
- }
- }
-
- private static FTPClientConfig createFTPClientConfig(final FileSystemOptions fileSystemOptions, final String key)
- {
- final FTPClientConfig config = new FTPClientConfig(key);
-
- final String serverLanguageCode = FtpsFileSystemConfigBuilder.getInstance().getServerLanguageCode(
- fileSystemOptions);
- if (serverLanguageCode != null)
- {
- config.setServerLanguageCode(serverLanguageCode);
- }
- final String defaultDateFormat = FtpsFileSystemConfigBuilder.getInstance().getDefaultDateFormat(
- fileSystemOptions);
- if (defaultDateFormat != null)
- {
- config.setDefaultDateFormatStr(defaultDateFormat);
- }
- final String recentDateFormat = FtpsFileSystemConfigBuilder.getInstance().getRecentDateFormat(
- fileSystemOptions);
- if (recentDateFormat != null)
- {
- config.setRecentDateFormatStr(recentDateFormat);
- }
- final String serverTimeZoneId = FtpsFileSystemConfigBuilder.getInstance().getServerTimeZoneId(
- fileSystemOptions);
- if (serverTimeZoneId != null)
- {
- config.setServerTimeZoneId(serverTimeZoneId);
- }
- final String[] shortMonthNames = FtpsFileSystemConfigBuilder.getInstance().getShortMonthNames(
- fileSystemOptions);
- if (shortMonthNames != null)
- {
- final StringBuilder shortMonthNamesStr = new StringBuilder(SHORT_MONTH_NAME_LEN);
- for (final String shortMonthName : shortMonthNames)
- {
- if (shortMonthNamesStr.length() > 0)
- {
- shortMonthNamesStr.append("|");
- }
- shortMonthNamesStr.append(shortMonthName);
- }
- config.setShortMonthNames(shortMonthNamesStr.toString());
- }
- return config;
- }
-
- private static FTPSClient createFTPSClient(final FileSystemOptions fileSystemOptions)
- throws FileSystemException
- {
- if (FtpsFileSystemConfigBuilder.getInstance().getFtpsType(fileSystemOptions)
- .equals(FtpsFileSystemConfigBuilder.FTPS_TYPE_EXPLICIT))
- {
- return new FTPSClient();
- }
- else if (FtpsFileSystemConfigBuilder.getInstance().getFtpsType(fileSystemOptions)
- .equals(FtpsFileSystemConfigBuilder.FTPS_TYPE_IMPLICIT))
- {
- return new FTPSClient(true);
- }
- else
- {
- throw new FileSystemException("Invalid FTPS type of "
- + FtpsFileSystemConfigBuilder.getInstance().getFtpsType(fileSystemOptions)
- + " specified. Must be 'implicit' or 'explicit'");
- }
+ final FtpsConnectionFactory factory = new FtpsConnectionFactory(FtpsFileSystemConfigBuilder.getInstance());
+ return factory.createConnection(hostname, port, username, password, workingDirectory, fileSystemOptions);
}
+
+ private static final class FtpsConnectionFactory extends FtpClientFactory.ConnectionFactory<FTPSClient, FtpsFileSystemConfigBuilder> {
- private FtpsClientFactory()
- {
- }
+ private FtpsConnectionFactory(final FtpsFileSystemConfigBuilder builder)
+ {
+ super(builder);
+ }
+
+ @Override
+ protected FTPSClient createClient(final FileSystemOptions fileSystemOptions) throws FileSystemException
+ {
+ final FTPSClient client;
+ if (builder.getFtpsType(fileSystemOptions).equals(FtpsFileSystemConfigBuilder.FTPS_TYPE_EXPLICIT))
+ {
+ client = new FTPSClient();
+ }
+ else if (builder.getFtpsType(fileSystemOptions).equals(FtpsFileSystemConfigBuilder.FTPS_TYPE_IMPLICIT))
+ {
+ client = new FTPSClient(true);
+ }
+ else
+ {
+ throw new FileSystemException("Invalid FTPS type of "
+ + FtpsFileSystemConfigBuilder.getInstance().getFtpsType(fileSystemOptions)
+ + " specified. Must be 'implicit' or 'explicit'");
+ }
+
+ final TrustManager trustManager = TrustManagerUtils.getValidateServerCertificateTrustManager();
+ client.setTrustManager(trustManager);
+ return client;
+ }
}
+}
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientWrapper.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientWrapper.java?rev=1448341&r1=1448340&r2=1448341&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientWrapper.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientWrapper.java Wed Feb 20 18:32:16 2013
@@ -17,268 +17,38 @@
package org.apache.commons.vfs2.provider.ftps;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.apache.commons.net.ftp.FTPFile;
-import org.apache.commons.net.ftp.FTPSClient;
+import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.UserAuthenticationData;
import org.apache.commons.vfs2.provider.GenericFileName;
-import org.apache.commons.vfs2.provider.ftp.FtpClient;
-import org.apache.commons.vfs2.provider.ftp.FtpFileProvider;
+import org.apache.commons.vfs2.provider.ftp.FTPClientWrapper;
import org.apache.commons.vfs2.util.UserAuthenticatorUtils;
/**
- * A wrapper to the FTPClient to allow automatic reconnect on connection loss.<br />
- * I decided to not to use eg. noop() to determine the state of the connection to avoid unnecesary server round-trips.
+ * A wrapper to the FTPSClient to allow automatic reconnect on connection loss.<br />
+ * The only difference to the FtpCLientWrapper is the creation of a FTPSClient instead of a FTPClient.
* @since 2.0
*/
-class FtpsClientWrapper implements FtpClient
+class FtpsClientWrapper extends FTPClientWrapper
{
- private final GenericFileName root;
- private final FileSystemOptions fileSystemOptions;
-
- private FTPSClient ftpClient = null;
-
FtpsClientWrapper(final GenericFileName root, final FileSystemOptions fileSystemOptions) throws FileSystemException
{
- this.root = root;
- this.fileSystemOptions = fileSystemOptions;
- getFtpsClient(); // fail-fast
- }
-
- public GenericFileName getRoot()
- {
- return root;
- }
-
- public FileSystemOptions getFileSystemOptions()
- {
- return fileSystemOptions;
- }
-
- private FTPSClient createClient() throws FileSystemException
- {
- final GenericFileName rootName = getRoot();
-
- UserAuthenticationData authData = null;
- try
- {
- authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, FtpFileProvider.AUTHENTICATOR_TYPES);
-
- return FtpsClientFactory.createConnection(rootName.getHostName(),
- rootName.getPort(),
- UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
- UserAuthenticatorUtils.toChar(rootName.getUserName())),
- UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
- UserAuthenticatorUtils.toChar(rootName.getPassword())),
- rootName.getPath(),
- getFileSystemOptions());
- }
- finally
- {
- UserAuthenticatorUtils.cleanup(authData);
- }
- }
-
- private FTPSClient getFtpsClient() throws FileSystemException
- {
- if (ftpClient == null)
- {
- ftpClient = createClient();
- }
-
- return ftpClient;
- }
-
- @Override
- public boolean isConnected() throws FileSystemException
- {
- return getFtpsClient().isConnected();
- }
-
- @Override
- public void disconnect() throws IOException
- {
- try
- {
- getFtpsClient().disconnect();
- }
- finally
- {
- ftpClient = null;
- }
- }
-
- @Override
- public FTPFile[] listFiles(final String relPath) throws IOException
- {
- try
- {
- return getFtpsClient().listFiles(relPath);
- }
- catch (final IOException e)
- {
- disconnect();
- return getFtpsClient().listFiles(relPath);
- }
- }
-
- @Override
- public boolean removeDirectory(final String relPath) throws IOException
- {
- try
- {
- return getFtpsClient().removeDirectory(relPath);
- }
- catch (final IOException e)
- {
- disconnect();
- return getFtpsClient().removeDirectory(relPath);
- }
- }
-
- @Override
- public boolean deleteFile(final String relPath) throws IOException
- {
- try
- {
- return getFtpsClient().deleteFile(relPath);
- }
- catch (final IOException e)
- {
- disconnect();
- return getFtpsClient().deleteFile(relPath);
- }
- }
-
- @Override
- public boolean rename(final String oldName, final String newName) throws IOException
- {
- try
- {
- return getFtpsClient().rename(oldName, newName);
- }
- catch (final IOException e)
- {
- disconnect();
- return getFtpsClient().rename(oldName, newName);
- }
- }
-
- @Override
- public boolean makeDirectory(final String relPath) throws IOException
- {
- try
- {
- return getFtpsClient().makeDirectory(relPath);
- }
- catch (final IOException e)
- {
- disconnect();
- return getFtpsClient().makeDirectory(relPath);
- }
- }
-
- @Override
- public boolean completePendingCommand() throws IOException
- {
- if (ftpClient != null)
- {
- return getFtpsClient().completePendingCommand();
- }
-
- return true;
- }
-
- @Override
- public InputStream retrieveFileStream(final String relPath) throws IOException
- {
- try
- {
- return getFtpsClient().retrieveFileStream(relPath);
- }
- catch (final IOException e)
- {
- disconnect();
- return getFtpsClient().retrieveFileStream(relPath);
- }
- }
-
- @Override
- public InputStream retrieveFileStream(final String relPath, final long restartOffset) throws IOException
- {
- try
- {
- final FTPSClient client = getFtpsClient();
- client.setRestartOffset(restartOffset);
- return client.retrieveFileStream(relPath);
- }
- catch (final IOException e)
- {
- disconnect();
-
- final FTPSClient client = getFtpsClient();
- client.setRestartOffset(restartOffset);
- return client.retrieveFileStream(relPath);
- }
- }
-
- @Override
- public OutputStream appendFileStream(final String relPath) throws IOException
- {
- try
- {
- return getFtpsClient().appendFileStream(relPath);
- }
- catch (final IOException e)
- {
- disconnect();
- return getFtpsClient().appendFileStream(relPath);
- }
- }
-
- @Override
- public OutputStream storeFileStream(final String relPath) throws IOException
- {
- try
- {
- return getFtpsClient().storeFileStream(relPath);
- }
- catch (final IOException e)
- {
- disconnect();
- return getFtpsClient().storeFileStream(relPath);
- }
- }
-
- @Override
- public boolean abort() throws IOException
- {
- try
- {
- // imario@apache.org: 2005-02-14
- // it should be better to really "abort" the transfer, but
- // currently I didnt manage to make it work - so lets "abort" the hard way.
- // return getFtpsClient().abort();
-
- disconnect();
- return true;
- }
- catch (final IOException e)
- {
- disconnect();
- }
- return true;
+ super(root, fileSystemOptions);
}
@Override
- public String getReplyString() throws IOException
+ protected FTPClient createClient(final GenericFileName rootName, final UserAuthenticationData authData)
+ throws FileSystemException
{
- return getFtpsClient().getReplyString();
+ return FtpsClientFactory.createConnection(
+ rootName.getHostName(),
+ rootName.getPort(),
+ UserAuthenticatorUtils.getData(
+ authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())),
+ UserAuthenticatorUtils.getData(
+ authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())),
+ rootName.getPath(), getFileSystemOptions());
}
}
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java?rev=1448341&r1=1448340&r2=1448341&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java Wed Feb 20 18:32:16 2013
@@ -16,34 +16,22 @@
*/
package org.apache.commons.vfs2.provider.ftps;
-import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
-import org.apache.commons.vfs2.FileSystem;
-import org.apache.commons.vfs2.FileSystemConfigBuilder;
import org.apache.commons.vfs2.FileSystemOptions;
-import org.apache.commons.vfs2.provider.ftp.FtpFileSystem;
+import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder;
/**
* The configuration builder for various FTPS configuration options.
*
* @since 2.0
*/
-public final class FtpsFileSystemConfigBuilder extends FileSystemConfigBuilder
+public final class FtpsFileSystemConfigBuilder extends FtpFileSystemConfigBuilder
{
private static final String _PREFIX = FtpsFileSystemConfigBuilder.class.getName();
private static final FtpsFileSystemConfigBuilder BUILDER =
new FtpsFileSystemConfigBuilder();
- private static final String FACTORY_KEY = FTPFileEntryParserFactory.class.getName() + ".KEY";
- private static final String PASSIVE_MODE = _PREFIX + ".PASSIVE";
- private static final String USER_DIR_IS_ROOT = _PREFIX + ".USER_DIR_IS_ROOT";
- private static final String DATA_TIMEOUT = _PREFIX + ".DATA_TIMEOUT";
private static final String FTPS_TYPE = _PREFIX + ".FTPS_TYPE";
- private static final String SERVER_LANGUAGE_CODE = _PREFIX + ".SERVER_LANGUAGE_CODE";
- private static final String DEFAULT_DATE_FORMAT = _PREFIX + ".DEFAULT_DATE_FORMAT";
- private static final String RECENT_DATE_FORMAT = _PREFIX + ".RECENT_DATE_FORMAT";
- private static final String SERVER_TIME_ZONE_ID = _PREFIX + ".SERVER_TIME_ZONE_ID";
- private static final String SHORT_MONTH_NAMES = _PREFIX + ".SHORT_MONTH_NAMES";
/**
* FTPS implicit file type.
@@ -61,7 +49,7 @@ public final class FtpsFileSystemConfigB
private FtpsFileSystemConfigBuilder()
{
- // no init.
+ super("ftps.");
}
/**
@@ -75,101 +63,6 @@ public final class FtpsFileSystemConfigB
}
/**
- * FTPFileEntryParserFactory which will be used for ftp-entry parsing.
- *
- * @param opts The FileSystemOptions.
- * @param factory instance of your factory
- */
- public void setEntryParserFactory(final FileSystemOptions opts, final FTPFileEntryParserFactory factory)
- {
- setParam(opts, FTPFileEntryParserFactory.class.getName(), factory);
- }
-
- /**
- * @param opts The FileSystemOptions
- * @return The FTPFileEntryParserFactory.
- * @see #setEntryParserFactory
- */
- public FTPFileEntryParserFactory getEntryParserFactory(final FileSystemOptions opts)
- {
- return (FTPFileEntryParserFactory) getParam(opts, FTPFileEntryParserFactory.class.getName());
- }
-
- /**
- * set the FQCN of your FileEntryParser used to parse the directory listing from your server.<br />
- * <br />
- * <i>If you do not use the default commons-net FTPFileEntryParserFactory e.g. by using
- * {@link #setEntryParserFactory}
- * this is the "key" parameter passed as argument into your custom factory</i>
- *
- * @param opts The FileSystemOptions.
- * @param key The key.
- */
- public void setEntryParser(final FileSystemOptions opts, final String key)
- {
- setParam(opts, FACTORY_KEY, key);
- }
-
- /**
- * @param opts The FileSystemOptions.
- * @return The key.
- * @see #setEntryParser
- */
- public String getEntryParser(final FileSystemOptions opts)
- {
- return (String) getParam(opts, FACTORY_KEY);
- }
-
- @Override
- protected Class<? extends FileSystem> getConfigClass()
- {
- return FtpFileSystem.class;
- }
-
- /**
- * Enter into passive mode.
- *
- * @param opts The FileSystemOptions.
- * @param passiveMode true if passive mode should be used, false otherwise.
- */
- public void setPassiveMode(final FileSystemOptions opts, final boolean passiveMode)
- {
- setParam(opts, PASSIVE_MODE, passiveMode ? Boolean.TRUE : Boolean.FALSE);
- }
-
- /**
- * @param opts The FileSystemOptions.
- * @return true if passive mode is being used.
- * @see #setPassiveMode
- */
- public Boolean getPassiveMode(final FileSystemOptions opts)
- {
- return (Boolean) getParam(opts, PASSIVE_MODE);
- }
-
- /**
- * use user directory as root (do not change to fs root).
- *
- * @param opts The FileSystemOptions.
- * @param userDirIsRoot true if the user directory should be the root.
- */
- public void setUserDirIsRoot(final FileSystemOptions opts, final boolean userDirIsRoot)
- {
- setParam(opts, USER_DIR_IS_ROOT,
- userDirIsRoot ? Boolean.TRUE : Boolean.FALSE);
- }
-
- /**
- * @param opts The FileSystemOptions.
- * @return true if the user directory is the root.
- * @see #setUserDirIsRoot
- */
- public Boolean getUserDirIsRoot(final FileSystemOptions opts)
- {
- return getBoolean(opts, USER_DIR_IS_ROOT, Boolean.TRUE);
- }
-
- /**
* Set FTPS security mode, either "implicit" or "explicit".
*
* @param opts The FileSystemOptions.
@@ -192,145 +85,6 @@ public final class FtpsFileSystemConfigB
return getString(opts, FTPS_TYPE, FtpsFileSystemConfigBuilder.FTPS_TYPE_EXPLICIT);
}
- /**
- * @param opts The FileSystemOptions.
- * @return The timeout value.
- * @see #setDataTimeout
- */
- public Integer getDataTimeout(final FileSystemOptions opts)
- {
- return (Integer) getParam(opts, DATA_TIMEOUT);
- }
-
- /**
- * set the data timeout for the ftp client.<br />
- * If you set the dataTimeout to {@code null} no dataTimeout will be set on the
- * ftp client.
- *
- * @param opts The FileSystemOptions.
- * @param dataTimeout The timeout value.
- */
- public void setDataTimeout(final FileSystemOptions opts, final Integer dataTimeout)
- {
- setParam(opts, DATA_TIMEOUT, dataTimeout);
- }
-
- /**
- * get the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
- * for details and examples.
- * @param opts The FileSystemOptions.
- * @return The language code.
- */
- public String getServerLanguageCode(final FileSystemOptions opts)
- {
- return (String) getParam(opts, SERVER_LANGUAGE_CODE);
- }
-
- /**
- * set the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
- * for details and examples.
- * @param opts The FileSystemOptions.
- * @param serverLanguageCode the language code.
- */
- public void setServerLanguageCode(final FileSystemOptions opts,
- final String serverLanguageCode)
- {
- setParam(opts, SERVER_LANGUAGE_CODE, serverLanguageCode);
- }
-
- /**
- * get the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
- * for details and examples.
- * @param opts The FileSystemOptions.
- * @return The default date format.
- */
- public String getDefaultDateFormat(final FileSystemOptions opts)
- {
- return (String) getParam(opts, DEFAULT_DATE_FORMAT);
- }
-
- /**
- * set the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
- * for details and examples.
- * @param opts The FileSystemOptions.
- * @param defaultDateFormat The default date format.
- */
- public void setDefaultDateFormat(final FileSystemOptions opts,
- final String defaultDateFormat)
- {
- setParam(opts, DEFAULT_DATE_FORMAT, defaultDateFormat);
- }
-
- /**
- * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
- * @param opts The FileSystemOptions.
- * @return The recent date format.
- */
- public String getRecentDateFormat(final FileSystemOptions opts)
- {
- return (String) getParam(opts, RECENT_DATE_FORMAT);
- }
-
- /**
- * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
- * @param opts The FileSystemOptions
- * @param recentDateFormat The recent date format.
- */
- public void setRecentDateFormat(final FileSystemOptions opts,
- final String recentDateFormat)
- {
- setParam(opts, RECENT_DATE_FORMAT, recentDateFormat);
- }
-
- /**
- * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
- * @param opts The FileSystemOptions.
- * @return The server timezone id.
- */
- public String getServerTimeZoneId(final FileSystemOptions opts)
- {
- return (String) getParam(opts, SERVER_TIME_ZONE_ID);
- }
-
- /**
- * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
- * @param opts The FileSystemOptions.
- * @param serverTimeZoneId The server's timezone id.
- */
- public void setServerTimeZoneId(final FileSystemOptions opts,
- final String serverTimeZoneId)
- {
- setParam(opts, SERVER_TIME_ZONE_ID, serverTimeZoneId);
- }
-
- /**
- * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
- * @param opts The FileSystemOptions.
- * @return An array of short month names.
- */
- public String[] getShortMonthNames(final FileSystemOptions opts)
- {
- return (String[]) getParam(opts, SHORT_MONTH_NAMES);
- }
-
- /**
- * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
- * @param opts The FileSystemOptions.
- * @param shortMonthNames An array of short month names.
- */
- public void setShortMonthNames(final FileSystemOptions opts,
- final String[] shortMonthNames)
- {
- String[] clone = null;
- if (shortMonthNames != null)
- {
- clone = new String[shortMonthNames.length];
- System.arraycopy(shortMonthNames, 0, clone, 0, shortMonthNames.length);
- }
-
- setParam(opts, SHORT_MONTH_NAMES, clone);
- }
-
// For VFS-412
// /**
Copied: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/AbstractFtpsProviderTestCase.java (from r1448031, commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderTestCase_Disabled.java)
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/AbstractFtpsProviderTestCase.java?p2=commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/AbstractFtpsProviderTestCase.java&p1=commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderTestCase_Disabled.java&r1=1448031&r2=1448341&rev=1448341&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderTestCase_Disabled.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/AbstractFtpsProviderTestCase.java Wed Feb 20 18:32:16 2013
@@ -19,9 +19,6 @@ package org.apache.commons.vfs2.provider
import java.io.File;
import java.io.IOException;
import java.net.URL;
-import java.net.URLDecoder;
-
-import junit.framework.Test;
import org.apache.commons.io.FileUtils;
import org.apache.commons.vfs2.FileObject;
@@ -45,13 +42,10 @@ import org.apache.ftpserver.usermanager.
import org.junit.Assert;
/**
- * Tests for FTP file systems.
- *
- * This is test fails because we cannot read from more than two input streams at the same time.
+ * Abstract tests for FTP file systems.
*/
-public class FtpsProviderTestCase_Disabled extends AbstractProviderTestConfig implements ProviderTestConfig
+abstract class AbstractFtpsProviderTestCase extends AbstractProviderTestConfig implements ProviderTestConfig
{
-
private static int SocketPort;
/**
@@ -79,8 +73,7 @@ public class FtpsProviderTestCase_Disabl
return SocketPort;
}
- private static String getSystemTestUriOverride()
-
+ static String getSystemTestUriOverride()
{
return System.getProperty(TEST_URI);
}
@@ -94,11 +87,12 @@ public class FtpsProviderTestCase_Disabl
/**
* Creates and starts an embedded Apache FTP Server (MINA).
- *
+ *
+ * @param implicit FTPS connection mode
* @throws FtpException
* @throws IOException
*/
- static void setUpClass() throws FtpException, IOException
+ static void setUpClass(boolean implicit) throws FtpException, IOException
{
if (Server != null)
{
@@ -131,7 +125,7 @@ public class FtpsProviderTestCase_Disabl
// set the SSL configuration for the listener
factory.setSslConfiguration(ssl.createSslConfiguration());
- factory.setImplicitSsl(true);
+ factory.setImplicitSsl(implicit);
// replace the default listener
serverFactory.addListener("default", factory.createListener());
@@ -142,32 +136,6 @@ public class FtpsProviderTestCase_Disabl
}
/**
- * Creates the test suite for the ftp file system.
- */
- public static Test suite() throws Exception
- {
- return new ProviderTestSuite(new FtpsProviderTestCase_Disabled())
- {
- @Override
- protected void setUp() throws Exception
- {
- if (getSystemTestUriOverride() == null)
- {
- setUpClass();
- }
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- tearDownClass();
- super.tearDown();
- }
- };
- }
-
- /**
* Stops the embedded Apache FTP Server (MINA).
*/
static void tearDownClass()
@@ -178,6 +146,35 @@ public class FtpsProviderTestCase_Disabl
Server = null;
}
}
+
+ static final class FtpProviderTestSuite extends ProviderTestSuite {
+ private boolean implicit;
+
+ public FtpProviderTestSuite(AbstractFtpsProviderTestCase providerConfig) throws Exception
+ {
+ super(providerConfig);
+ this.implicit = providerConfig.isImplicit();
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ if (getSystemTestUriOverride() == null)
+ {
+ setUpClass(implicit);
+ }
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ tearDownClass();
+ super.tearDown();
+ }
+ }
+
+ protected abstract boolean isImplicit();
/**
* Returns the base folder for tests. You can override the DEFAULT_URI by using the system property name defined by
@@ -200,9 +197,11 @@ public class FtpsProviderTestCase_Disabl
{
fileSystemOptions = new FileSystemOptions();
final FtpsFileSystemConfigBuilder builder = FtpsFileSystemConfigBuilder.getInstance();
- builder.setPassiveMode(fileSystemOptions, true);
+ builder.setConnectTimeout(fileSystemOptions, Integer.valueOf(1000));
builder.setDataTimeout(fileSystemOptions, Integer.valueOf(2000));
- builder.setFtpsType(fileSystemOptions, FtpsFileSystemConfigBuilder.FTPS_TYPE_IMPLICIT);
+ builder.setFtpsType(fileSystemOptions, isImplicit()
+ ? FtpsFileSystemConfigBuilder.FTPS_TYPE_IMPLICIT
+ : FtpsFileSystemConfigBuilder.FTPS_TYPE_EXPLICIT);
}
return fileSystemOptions;
}
Added: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderExplicitTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderExplicitTestCase.java?rev=1448341&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderExplicitTestCase.java (added)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderExplicitTestCase.java Wed Feb 20 18:32:16 2013
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs2.provider.ftps.test;
+
+import junit.framework.Test;
+
+/**
+ * Tests for FTPS file systems with explicit FTPS connection.
+ */
+public class FtpsProviderExplicitTestCase extends AbstractFtpsProviderTestCase
+{
+ @Override
+ protected boolean isImplicit()
+ {
+ return false;
+ }
+
+ /**
+ * Creates the test suite for the ftps file system.
+ */
+ public static Test suite() throws Exception
+ {
+ return new FtpProviderTestSuite(new FtpsProviderExplicitTestCase());
+ }
+}
Propchange: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderExplicitTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderExplicitTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Id HeadURL Revision
Added: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderImplicitTestCase_Disabled.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderImplicitTestCase_Disabled.java?rev=1448341&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderImplicitTestCase_Disabled.java (added)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderImplicitTestCase_Disabled.java Wed Feb 20 18:32:16 2013
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs2.provider.ftps.test;
+
+import junit.framework.Test;
+
+/**
+ * Tests for FTPS file systems with implicit FTPS connection.
+ *
+ * TODO: Fails for concurrent access.
+ * Note, that the implicit mode is not standardized and the protocol may differ between the FTPS servers.
+ */
+public class FtpsProviderImplicitTestCase_Disabled extends AbstractFtpsProviderTestCase
+{
+ @Override
+ protected boolean isImplicit()
+ {
+ return true;
+ }
+
+ /**
+ * Creates the test suite for the ftps file system.
+ */
+ public static Test suite() throws Exception
+ {
+ return new FtpProviderTestSuite(new FtpsProviderImplicitTestCase_Disabled());
+ }
+}
Propchange: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderImplicitTestCase_Disabled.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderImplicitTestCase_Disabled.java
------------------------------------------------------------------------------
svn:keywords = Author Id HeadURL Revision
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderPROTTestCase_Disabled.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderPROTTestCase_Disabled.java?rev=1448341&r1=1448340&r2=1448341&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderPROTTestCase_Disabled.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderPROTTestCase_Disabled.java Wed Feb 20 18:32:16 2013
@@ -22,7 +22,7 @@ import org.apache.commons.vfs2.provider.
/**
* Tests VFS-412.
*/
-public class FtpsProviderPROTTestCase_Disabled extends FtpsProviderTestCase_Disabled
+public class FtpsProviderPROTTestCase_Disabled extends FtpsProviderImplicitTestCase_Disabled
{
@Override
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/MultipleConnectionTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/MultipleConnectionTestCase.java?rev=1448341&r1=1448340&r2=1448341&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/MultipleConnectionTestCase.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/MultipleConnectionTestCase.java Wed Feb 20 18:32:16 2013
@@ -17,7 +17,6 @@
package org.apache.commons.vfs2.provider.ftps.test;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.SocketException;
import org.apache.commons.net.ftp.FTPSClient;
@@ -35,13 +34,13 @@ public class MultipleConnectionTestCase
@BeforeClass
public static void setUpClass() throws FtpException, IOException
{
- FtpsProviderTestCase_Disabled.setUpClass();
+ AbstractFtpsProviderTestCase.setUpClass(true);
}
@AfterClass
- public static void tearDownClass() throws MalformedURLException, FtpException
+ public static void tearDownClass()
{
- FtpsProviderTestCase_Disabled.tearDownClass();
+ AbstractFtpsProviderTestCase.tearDownClass();
}
private FTPSClient init(final FTPSClient client)
@@ -52,12 +51,12 @@ public class MultipleConnectionTestCase
private FileObject resolveRoot() throws FileSystemException
{
- return VFS.getManager().resolveFile(FtpsProviderTestCase_Disabled.getConnectionUri(),
- new FtpsProviderTestCase_Disabled().getFileSystemOptions());
+ return VFS.getManager().resolveFile(AbstractFtpsProviderTestCase.getConnectionUri(),
+ new FtpsProviderImplicitTestCase_Disabled().getFileSystemOptions());
}
@Test
- public void testConnectRoot() throws SocketException, IOException
+ public void testConnectRoot() throws IOException
{
resolveRoot();
resolveRoot();
@@ -71,8 +70,8 @@ public class MultipleConnectionTestCase
try
{
final String hostname = "localhost";
- client1.connect(hostname, FtpsProviderTestCase_Disabled.getSocketPort());
- client2.connect(hostname, FtpsProviderTestCase_Disabled.getSocketPort());
+ client1.connect(hostname, AbstractFtpsProviderTestCase.getSocketPort());
+ client2.connect(hostname, AbstractFtpsProviderTestCase.getSocketPort());
} finally
{
if (client1 != null)
Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1448341&r1=1448340&r2=1448341&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Wed Feb 20 18:32:16 2013
@@ -26,6 +26,9 @@
<!-- <action issue="VFS-443" dev="ggregory" type="update" due-to="nickallen"> -->
<!-- [Local] Need an easy way to convert from a FileObject to a File. -->
<!-- </action> -->
+ <action issue="VFS-458" dev="jos" type="fix">
+ FTPS provider missed functionality and bug fixes already available for the FTP provider.
+ </action>
<action issue="VFS-452" dev="ggregory" type="fix" due-to="Jean-Marc Borer">
HttpFileObject read/write attributes should reflect underlying FileSystem capabilities.
</action>
@@ -87,6 +90,9 @@
<action issue="VFS-405" dev="ggregory" type="add" due-to="dwaszak">
Get/set the file permissions.
</action>
+ <action issue="VFS-457" dev="joehni" type="update">
+ Update test dependencies: sshd-core to version 0.8.0 from version 0.7.0; mina-core from version 2.0.4 to version 2.0.7.
+ </action>
<action issue="VFS-456" dev="joehni" type="update">
Use org.bouncycastel:bcprov-jdk16 instead of org.bouncycastle:bcprof-jdk15on since Java 1.6 is required.
</action>