You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2012/10/29 15:00:12 UTC
svn commit: r1403298 -
/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java
Author: ggregory
Date: Mon Oct 29 14:00:11 2012
New Revision: 1403298
URL: http://svn.apache.org/viewvc?rev=1403298&view=rev
Log:
Checkstyle: Method length is 199 lines (max allowed is 150). Refactor Proxy instantiation into createProxy* methods.
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java?rev=1403298&r1=1403297&r2=1403298&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java Mon Oct 29 14:00:11 2012
@@ -200,33 +200,19 @@ public final class SftpClientFactory
if (proxyHost != null)
{
int proxyPort = builder.getProxyPort(fileSystemOptions);
- SftpFileSystemConfigBuilder.ProxyType proxyType =
- builder.getProxyType(fileSystemOptions);
+ SftpFileSystemConfigBuilder.ProxyType proxyType = builder.getProxyType(fileSystemOptions);
Proxy proxy = null;
if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType))
{
- proxy = proxyPort == 0 ? new ProxyHTTP(proxyHost) : new ProxyHTTP(proxyHost, proxyPort);
+ proxy = createProxyHTTP(proxyHost, proxyPort);
}
else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType))
{
- proxy = proxyPort == 0 ? new ProxySOCKS5(proxyHost) : new ProxySOCKS5(proxyHost, proxyPort);
+ proxy = createProxySOCKS5(proxyHost, proxyPort);
}
else if (SftpFileSystemConfigBuilder.PROXY_STREAM.equals(proxyType))
{
- // Use a stream proxy, i.e. it will use a remote host as a proxy
- // and run a command (e.g. netcat) that forwards input/output
- // to the target host.
-
- // Here we get the settings for connecting to the proxy:
- // user, password, options and a command
- String proxyUser = builder.getProxyUser(fileSystemOptions);
- String proxyPassword = builder.getProxyPassword(fileSystemOptions);
- FileSystemOptions proxyOptions = builder.getProxyOptions(fileSystemOptions);
-
- String proxyCommand = builder.getProxyCommand(fileSystemOptions);
-
- // Create the stream proxy
- proxy = new SftpStreamProxy(proxyCommand, proxyUser, proxyHost, proxyPort, proxyPassword, proxyOptions);
+ proxy = createStreamProxy(proxyHost, proxyPort, fileSystemOptions, builder);
}
if (proxy != null)
@@ -251,6 +237,37 @@ public final class SftpClientFactory
return session;
}
+ private static Proxy createStreamProxy(String proxyHost, int proxyPort, FileSystemOptions fileSystemOptions,
+ final SftpFileSystemConfigBuilder builder)
+ {
+ Proxy proxy;
+ // Use a stream proxy, i.e. it will use a remote host as a proxy
+ // and run a command (e.g. netcat) that forwards input/output
+ // to the target host.
+
+ // Here we get the settings for connecting to the proxy:
+ // user, password, options and a command
+ String proxyUser = builder.getProxyUser(fileSystemOptions);
+ String proxyPassword = builder.getProxyPassword(fileSystemOptions);
+ FileSystemOptions proxyOptions = builder.getProxyOptions(fileSystemOptions);
+
+ String proxyCommand = builder.getProxyCommand(fileSystemOptions);
+
+ // Create the stream proxy
+ proxy = new SftpStreamProxy(proxyCommand, proxyUser, proxyHost, proxyPort, proxyPassword, proxyOptions);
+ return proxy;
+ }
+
+ private static ProxySOCKS5 createProxySOCKS5(String proxyHost, int proxyPort)
+ {
+ return proxyPort == 0 ? new ProxySOCKS5(proxyHost) : new ProxySOCKS5(proxyHost, proxyPort);
+ }
+
+ private static ProxyHTTP createProxyHTTP(String proxyHost, int proxyPort)
+ {
+ return proxyPort == 0 ? new ProxyHTTP(proxyHost) : new ProxyHTTP(proxyHost, proxyPort);
+ }
+
/**
* Finds the .ssh directory.
* <p>The lookup order is:</p>