You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ec...@apache.org on 2014/05/05 03:26:48 UTC
svn commit: r1592435 - in /commons/proper/vfs/trunk/core/src:
main/java/org/apache/commons/vfs2/provider/http/
test/java/org/apache/commons/vfs2/provider/http/test/
Author: ecki
Date: Mon May 5 01:26:47 2014
New Revision: 1592435
URL: http://svn.apache.org/r1592435
Log:
[VFS-453] Set socket and connect timeout for HTTP, HTTPS and WebDAV providers.
(contributed by Jiri Syrovy in https://github.com/apache/commons-vfs/pull/6)
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java?rev=1592435&r1=1592434&r2=1592435&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java Mon May 5 01:26:47 2014
@@ -133,6 +133,9 @@ public final class HttpClientFactory
connectionMgrParams.setMaxConnectionsPerHost(config, builder.getMaxConnectionsPerHost(fileSystemOptions));
connectionMgrParams.setMaxTotalConnections(builder.getMaxTotalConnections(fileSystemOptions));
+ connectionMgrParams.setConnectionTimeout(builder.getConnectionTimeout(fileSystemOptions));
+ connectionMgrParams.setSoTimeout(builder.getSoTimeout(fileSystemOptions));
+
client.setHostConfiguration(config);
if (username != null)
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java?rev=1592435&r1=1592434&r2=1592435&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java Mon May 5 01:26:47 2014
@@ -35,6 +35,10 @@ public class HttpFileSystemConfigBuilder
private static final int DEFAULT_MAX_HOST_CONNECTIONS = 5;
private static final int DEFAULT_MAX_CONNECTIONS = 50;
+
+ private static final int DEFAULT_CONNECTION_TIMEOUT = 0;
+
+ private static final int DEFAULT_SO_TIMEOUT = 0;
private static final boolean DEFAULT_FOLLOW_REDIRECT = true;
@@ -273,6 +277,54 @@ public class HttpFileSystemConfigBuilder
{
setParam(opts, KEY_PREEMPTIVE_AUTHENTICATION, Boolean.valueOf(preemptiveAuth));
}
+
+ /**
+ * The connection timeout.
+ *
+ * @param opts The FileSystem options.
+ * @param connectionTimeout The connection timeout.
+ * @since 2.1
+ */
+ public void setConnectionTimeout(final FileSystemOptions opts, final int connectionTimeout)
+ {
+ setParam(opts, HttpConnectionManagerParams.CONNECTION_TIMEOUT, Integer.valueOf(connectionTimeout));
+ }
+
+ /**
+ * Retrieve the connection timeout.
+ *
+ * @param opts The FileSystem options.
+ * @return The connection timeout.
+ * @since 2.1
+ */
+ public int getConnectionTimeout(final FileSystemOptions opts)
+ {
+ return getInteger(opts, HttpConnectionManagerParams.CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
+ }
+
+ /**
+ * The socket timeout.
+ *
+ * @param opts The FileSystem options.
+ * @param soTimeout socket timeout.
+ * @since 2.1
+ */
+ public void setSoTimeout(final FileSystemOptions opts, final int soTimeout)
+ {
+ setParam(opts, HttpConnectionManagerParams.SO_TIMEOUT, Integer.valueOf(soTimeout));
+ }
+
+ /**
+ * Retrieve the socket timeout.
+ *
+ * @param opts The FileSystemOptions.
+ * @return The socket timeout.
+ * @since 2.1
+ */
+ public int getSoTimeout(final FileSystemOptions opts)
+ {
+ return getInteger(opts, HttpConnectionManagerParams.SO_TIMEOUT, DEFAULT_SO_TIMEOUT);
+ }
@Override
protected Class<? extends FileSystem> getConfigClass()
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java?rev=1592435&r1=1592434&r2=1592435&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java Mon May 5 01:26:47 2014
@@ -201,4 +201,24 @@ public class HttpProviderTestCase extend
{
testResloveFolderSlash(ConnectionUri + "/read-tests/", true);
}
+
+ /** Ensure VFS-453 options are present. */
+ public void testHttpTimeoutConfig() throws FileSystemException
+ {
+ final FileSystemOptions opts = new FileSystemOptions();
+ final HttpFileSystemConfigBuilder builder = HttpFileSystemConfigBuilder.getInstance();
+
+ // ensure defaults are 0
+ assertEquals(0, builder.getConnectionTimeout(opts));
+ assertEquals(0, builder.getSoTimeout(opts));
+
+ builder.setConnectionTimeout(opts, 60000);
+ builder.setSoTimeout(opts, 60000);
+
+ // ensure changes are visible
+ assertEquals(60000, builder.getConnectionTimeout(opts));
+ assertEquals(60000, builder.getSoTimeout(opts));
+
+ // TODO: should also check the created HTTPClient
+ }
}