You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by im...@apache.org on 2006/10/03 20:25:24 UTC
svn commit: r452591 - in
/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp:
SftpClientFactory.java SftpFileSystemConfigBuilder.java
Author: imario
Date: Tue Oct 3 11:25:24 2006
New Revision: 452591
URL: http://svn.apache.org/viewvc?view=rev&rev=452591
Log:
VFS-84: added proxy configuration for sftp
Modified:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpClientFactory.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpClientFactory.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpClientFactory.java?view=diff&rev=452591&r1=452590&r2=452591
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpClientFactory.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpClientFactory.java Tue Oct 3 11:25:24 2006
@@ -19,6 +19,9 @@
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.UserInfo;
+import com.jcraft.jsch.Proxy;
+import com.jcraft.jsch.ProxyHTTP;
+import com.jcraft.jsch.ProxySOCKS5;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.util.Os;
@@ -157,6 +160,41 @@
{
config.setProperty("compression.s2c", compression);
config.setProperty("compression.c2s", compression);
+ }
+
+ String proxyHost = SftpFileSystemConfigBuilder.getInstance().getProxyHost(fileSystemOptions);
+ if (proxyHost != null)
+ {
+ int proxyPort = SftpFileSystemConfigBuilder.getInstance().getProxyPort(fileSystemOptions);
+ SftpFileSystemConfigBuilder.ProxyType proxyType = SftpFileSystemConfigBuilder.getInstance().getProxyType(fileSystemOptions);
+ Proxy proxy = null;
+ if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType))
+ {
+ if (proxyPort != 0)
+ {
+ proxy = new ProxyHTTP(proxyHost, proxyPort);
+ }
+ else
+ {
+ proxy = new ProxyHTTP(proxyHost);
+ }
+ }
+ else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType))
+ {
+ if (proxyPort != 0)
+ {
+ proxy = new ProxySOCKS5(proxyHost, proxyPort);
+ }
+ else
+ {
+ proxy = new ProxySOCKS5(proxyHost);
+ }
+ }
+
+ if (proxy != null)
+ {
+ session.setProxy(proxy);
+ }
}
//set properties for the session
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java?view=diff&rev=452591&r1=452590&r2=452591
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/sftp/SftpFileSystemConfigBuilder.java Tue Oct 3 11:25:24 2006
@@ -21,6 +21,7 @@
import org.apache.commons.vfs.FileSystemOptions;
import java.io.File;
+import java.io.Serializable;
/**
* The config builder for various sftp configuration options
@@ -35,6 +36,46 @@
private final static String USER_DIR_IS_ROOT = SftpFileSystemConfigBuilder.class.getName() + ".USER_DIR_IS_ROOT";
private final static String TIMEOUT = SftpFileSystemConfigBuilder.class.getName() + ".TIMEOUT";
+ public final static ProxyType PROXY_HTTP = new ProxyType("http");
+ public final static ProxyType PROXY_SOCKS5 = new ProxyType("socks");
+
+ public static class ProxyType implements Serializable, Comparable
+ {
+ private final String proxyType;
+
+ private ProxyType(final String proxyType)
+ {
+ this.proxyType = proxyType;
+ }
+
+ public int compareTo(Object o)
+ {
+ return proxyType.compareTo(((ProxyType) o).proxyType);
+ }
+
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ ProxyType proxyType1 = (ProxyType) o;
+
+ if (proxyType != null ? !proxyType.equals(proxyType1.proxyType) : proxyType1.proxyType != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+ }
+
public static SftpFileSystemConfigBuilder getInstance()
{
return builder;
@@ -202,5 +243,74 @@
protected Class getConfigClass()
{
return SftpFileSystem.class;
+ }
+
+ /**
+ * Set the proxy to use for sftp connection.<br>
+ * You have to set the ProxyPort too if you would like to have the proxy relly used.
+ *
+ * @param proxyHost the host
+ * @see #setProxyPort
+ */
+ public void setProxyHost(FileSystemOptions opts, String proxyHost)
+ {
+ setParam(opts, "proxyHost", proxyHost);
+ }
+
+ /**
+ * Set the proxy-port to use for sftp connection
+ * You have to set the ProxyHost too if you would like to have the proxy relly used.
+ *
+ * @param proxyPort the port
+ * @see #setProxyHost
+ */
+ public void setProxyPort(FileSystemOptions opts, int proxyPort)
+ {
+ setParam(opts, "proxyPort", new Integer(proxyPort));
+ }
+
+ /**
+ * Get the proxy to use for sftp connection
+ * You have to set the ProxyPort too if you would like to have the proxy relly used.
+ *
+ * @return proxyHost
+ * @see #setProxyPort
+ */
+ public String getProxyHost(FileSystemOptions opts)
+ {
+ return (String) getParam(opts, "proxyHost");
+ }
+
+ /**
+ * Get the proxy-port to use for sftp the connection
+ * You have to set the ProxyHost too if you would like to have the proxy relly used.
+ *
+ * @return proxyPort: the port number or 0 if it is not set
+ * @see #setProxyHost
+ */
+ public int getProxyPort(FileSystemOptions opts)
+ {
+ if (!hasParam(opts, "proxyPort"))
+ {
+ return 0;
+ }
+
+ return ((Number) getParam(opts, "proxyPort")).intValue();
+ }
+
+ /**
+ * Set the proxy type to use for sftp connection.
+ */
+ public void setProxyType(FileSystemOptions opts, ProxyType proxyType)
+ {
+ setParam(opts, "proxyType", proxyType);
+ }
+
+ /**
+ * Get the proxy type to use for sftp connection.
+ */
+ public ProxyType getProxyType(FileSystemOptions opts)
+ {
+ return (ProxyType) getParam(opts, "proxyType");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org