- [HTTP] Add
HttpFileSystemConfigBuilder.setConnectionTimeout(FileSystemOptions,
Duration) and deprecate Integer version.
- [HTTP] Add HttpFileSystemConfigBuilder.setSoTimeout(FileSystemOptions,
Duration) and deprecate Integer version.
- [HTTP] Add
HttpFileSystemConfigBuilder.getConnectionTimeout(FileSystemOptions) and
deprecate Integer version.
- [HTTP] Add
HttpFileSystemConfigBuilder.getSoTimeoutDuration(FileSystemOptions) and
deprecate Integer version.
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java
index 807e595..f4de4a9 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java
@@ -16,6 +16,8 @@
*/
package org.apache.commons.vfs2.provider.http;
+import java.time.Duration;
+
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
@@ -29,6 +31,7 @@
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.UserAuthenticationData;
import org.apache.commons.vfs2.UserAuthenticator;
+import org.apache.commons.vfs2.util.DurationUtils;
import org.apache.commons.vfs2.util.UserAuthenticatorUtils;
/**
@@ -62,7 +65,7 @@
*/
public static HttpClient createConnection(final HttpFileSystemConfigBuilder builder, final String scheme,
final String hostname, final int port, final String username, final String password,
- final FileSystemOptions fileSystemOptions) throws FileSystemException {
+ final FileSystemOptions fileSystemOptions) throws FileSystemException {
final HttpClient client;
try {
final HttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
@@ -84,15 +87,15 @@
final UserAuthenticator proxyAuth = builder.getProxyAuthenticator(fileSystemOptions);
if (proxyAuth != null) {
final UserAuthenticationData authData = UserAuthenticatorUtils.authenticate(proxyAuth,
- new UserAuthenticationData.Type[] { UserAuthenticationData.USERNAME,
- UserAuthenticationData.PASSWORD });
+ new UserAuthenticationData.Type[] {UserAuthenticationData.USERNAME,
+ UserAuthenticationData.PASSWORD});
if (authData != null) {
final UsernamePasswordCredentials proxyCreds = new UsernamePasswordCredentials(
- UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
- UserAuthenticationData.USERNAME, null)),
- UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
- UserAuthenticationData.PASSWORD, null)));
+ UserAuthenticatorUtils.toString(
+ UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, null)),
+ UserAuthenticatorUtils.toString(
+ UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, null)));
final AuthScope scope = new AuthScope(proxyHost, AuthScope.ANY_PORT);
client.getState().setProxyCredentials(scope, proxyCreds);
@@ -111,15 +114,17 @@
}
}
/*
- ConnectionManager set methods must be called after the host & port and proxy host & port are set in the
- HostConfiguration. They are all used as part of the key when HttpConnectionManagerParams tries to locate
- the host configuration.
+ * ConnectionManager set methods must be called after the host & port and proxy host & port are set in the
+ * HostConfiguration. They are all used as part of the key when HttpConnectionManagerParams tries to locate
+ * the host configuration.
*/
connectionMgrParams.setMaxConnectionsPerHost(config, builder.getMaxConnectionsPerHost(fileSystemOptions));
connectionMgrParams.setMaxTotalConnections(builder.getMaxTotalConnections(fileSystemOptions));
- connectionMgrParams.setConnectionTimeout(builder.getConnectionTimeout(fileSystemOptions));
- connectionMgrParams.setSoTimeout(builder.getSoTimeout(fileSystemOptions));
+ connectionMgrParams.setConnectionTimeout(
+ DurationUtils.toMillisInt(builder.getConnectionTimeoutDuration(fileSystemOptions)));
+ connectionMgrParams
+ .setSoTimeout(DurationUtils.toMillisInt(builder.getSoTimeoutDuration(fileSystemOptions)));
client.setHostConfiguration(config);
@@ -134,4 +139,5 @@
return client;
}
+
}
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java
index 3179fe3..0d5a6c4 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java
@@ -16,6 +16,8 @@
*/
package org.apache.commons.vfs2.provider.http;
+import java.time.Duration;
+
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.apache.commons.httpclient.params.HttpConnectionParams;
@@ -39,9 +41,9 @@
private static final int DEFAULT_MAX_CONNECTIONS = 50;
- private static final int DEFAULT_CONNECTION_TIMEOUT = 0;
+ private static final Duration DEFAULT_CONNECTION_TIMEOUT = Duration.ZERO;
- private static final int DEFAULT_SO_TIMEOUT = 0;
+ private static final Duration DEFAULT_SO_TIMEOUT = Duration.ZERO;
private static final boolean DEFAULT_FOLLOW_REDIRECT = true;
@@ -277,11 +279,24 @@
* The connection timeout.
*
* @param opts The FileSystem options.
- * @param connectionTimeout The connection timeout.
- * @since 2.1
+ * @param duration The connection timeout.
+ * @since 2.8.0
*/
- public void setConnectionTimeout(final FileSystemOptions opts, final int connectionTimeout) {
- setParam(opts, HttpConnectionParams.CONNECTION_TIMEOUT, Integer.valueOf(connectionTimeout));
+ public void setConnectionTimeout(final FileSystemOptions opts, final Duration duration) {
+ setParam(opts, HttpConnectionParams.CONNECTION_TIMEOUT, duration);
+ }
+
+ /**
+ * The connection timeout.
+ *
+ * @param opts The FileSystem options.
+ * @param duration The connection timeout.
+ * @since 2.1
+ * @deprecated Use {@link #setConnectionTimeout(FileSystemOptions, Duration)}.
+ */
+ @Deprecated
+ public void setConnectionTimeout(final FileSystemOptions opts, final int duration) {
+ setConnectionTimeout(opts, Duration.ofMillis(duration));
}
/**
@@ -290,20 +305,46 @@
* @param opts The FileSystem options.
* @return The connection timeout.
* @since 2.1
+ * @deprecated Use {@link #getConnectionTimeoutDuration(FileSystemOptions)}.
*/
+ @Deprecated
public int getConnectionTimeout(final FileSystemOptions opts) {
- return getInteger(opts, HttpConnectionParams.CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
+ return getDurationInteger(opts, HttpConnectionParams.CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
+ }
+
+ /**
+ * Gets the connection timeout.
+ *
+ * @param opts The FileSystem options.
+ * @return The connection timeout.
+ * @since 2.8.0
+ */
+ public Duration getConnectionTimeoutDuration(final FileSystemOptions opts) {
+ return getDuration(opts, HttpConnectionParams.CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
}
/**
* The socket timeout.
*
* @param opts The FileSystem options.
- * @param soTimeout socket timeout.
- * @since 2.1
+ * @param duration socket timeout.
+ * @since 2.8.0
*/
- public void setSoTimeout(final FileSystemOptions opts, final int soTimeout) {
- setParam(opts, HttpConnectionParams.SO_TIMEOUT, Integer.valueOf(soTimeout));
+ public void setSoTimeout(final FileSystemOptions opts, final Duration duration) {
+ setParam(opts, HttpConnectionParams.SO_TIMEOUT, duration);
+ }
+
+ /**
+ * The socket timeout.
+ *
+ * @param opts The FileSystem options.
+ * @param duration socket timeout.
+ * @since 2.1
+ * @deprecated Use {@link #setSoTimeout(FileSystemOptions, Duration)}.
+ */
+ @Deprecated
+ public void setSoTimeout(final FileSystemOptions opts, final int duration) {
+ setSoTimeout(opts, Duration.ofMillis(duration));
}
/**
@@ -312,9 +353,22 @@
* @param opts The FileSystemOptions.
* @return The socket timeout.
* @since 2.1
+ * @deprecated Use {@link #getSoTimeoutDuration(FileSystemOptions)}.
*/
+ @Deprecated
public int getSoTimeout(final FileSystemOptions opts) {
- return getInteger(opts, HttpConnectionParams.SO_TIMEOUT, DEFAULT_SO_TIMEOUT);
+ return getDurationInteger(opts, HttpConnectionParams.SO_TIMEOUT, DEFAULT_SO_TIMEOUT);
+ }
+
+ /**
+ * Gets the socket timeout.
+ *
+ * @param opts The FileSystemOptions.
+ * @return The socket timeout.
+ * @since 2.8.0
+ */
+ public Duration getSoTimeoutDuration(final FileSystemOptions opts) {
+ return getDuration(opts, HttpConnectionParams.SO_TIMEOUT, DEFAULT_SO_TIMEOUT);
}
/**
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/HttpProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/HttpProviderTestCase.java
index c9108b9..f701f96 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/HttpProviderTestCase.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/HttpProviderTestCase.java
@@ -17,6 +17,7 @@
package org.apache.commons.vfs2.provider.http;
import java.io.File;
+import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.apache.commons.vfs2.AbstractProviderTestConfig;
@@ -38,6 +39,8 @@
*
*/
public class HttpProviderTestCase extends AbstractProviderTestConfig {
+ private static final Duration ONE_MINUTE = Duration.ofMinutes(1);
+
private static NHttpFileServer Server;
private static int SocketPort;
@@ -170,22 +173,36 @@
/** Ensure VFS-453 options are present. */
public void testHttpTimeoutConfig() {
- final FileSystemOptions opts = new FileSystemOptions();
+ final FileSystemOptions options = new FileSystemOptions();
final HttpFileSystemConfigBuilder builder = HttpFileSystemConfigBuilder.getInstance();
// ensure defaults are 0
- assertEquals(0, builder.getConnectionTimeout(opts));
- assertEquals(0, builder.getSoTimeout(opts));
- assertEquals("Jakarta-Commons-VFS", builder.getUserAgent(opts));
+ assertEquals(0, builder.getConnectionTimeout(options));
+ assertEquals(0, builder.getConnectionTimeoutDuration(options).toMillis());
+ assertEquals(0, builder.getSoTimeout(options));
+ assertEquals("Jakarta-Commons-VFS", builder.getUserAgent(options));
- builder.setConnectionTimeout(opts, 60000);
- builder.setSoTimeout(opts, 60000);
- builder.setUserAgent(opts, "foo/bar");
+ // Set with deprecated milliseconds APIs.
+ builder.setConnectionTimeout(options, 60000);
+ builder.setSoTimeout(options, 60000);
+ builder.setUserAgent(options, "foo/bar");
// ensure changes are visible
- assertEquals(60000, builder.getConnectionTimeout(opts));
- assertEquals(60000, builder.getSoTimeout(opts));
- assertEquals("foo/bar", builder.getUserAgent(opts));
+ assertEquals(60000, builder.getConnectionTimeout(options));
+ assertEquals(ONE_MINUTE, builder.getConnectionTimeoutDuration(options));
+ assertEquals(60000, builder.getSoTimeout(options));
+ assertEquals("foo/bar", builder.getUserAgent(options));
+
+ // Set with Duration APIs.
+ builder.setConnectionTimeout(options, ONE_MINUTE);
+ builder.setSoTimeout(options, ONE_MINUTE);
+
+ // ensure changes are visible
+ assertEquals(60000, builder.getConnectionTimeout(options));
+ assertEquals(ONE_MINUTE, builder.getConnectionTimeoutDuration(options));
+ assertEquals(60000, builder.getSoTimeout(options));
+ assertEquals(ONE_MINUTE, builder.getSoTimeoutDuration(options));
+ assertEquals("foo/bar", builder.getUserAgent(options));
// TODO: should also check the created HTTPClient
}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 81a10ed..61b6e9f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -77,31 +77,46 @@
Add and use VFS.close().
</action>
<action dev="ggregory" due-to="Gary Gregory, xiaqingyun" type="add">
- Add support for FTP ControlKeepAliveReplyTimeout and ControlKeepAliveTimeout.
+ [FTP] Add support for ControlKeepAliveReplyTimeout and ControlKeepAliveTimeout.
</action>
<action dev="ggregory" due-to="Gary Gregory, Michael Graham" type="add">
- FTP tests can be configured with a custom FTP server command factory.
+ [FTP] Tests can be configured with a custom FTP server command factory.
</action>
<action issue="VFS-257" dev="ggregory" due-to="Andrew Franklin, Michael Graham, Gary Gregory" type="add">
[FTP] Add support for MDTM to get more accurate last modified times.
</action>
<action dev="ggregory" due-to="Gary Gregory" type="add">
- Add FtpFileSystemConfigBuilder.setConnectTimeout(FileSystemOptions, Duration) and deprecate Integer version.
+ [FTP] Add FtpFileSystemConfigBuilder.setConnectTimeout(FileSystemOptions, Duration) and deprecate Integer version.
</action>
<action dev="ggregory" due-to="Gary Gregory" type="add">
- Add FtpFileSystemConfigBuilder.setDataTimeout(FileSystemOptions, Duration) and deprecate Integer version.
+ [FTP] Add FtpFileSystemConfigBuilder.setDataTimeout(FileSystemOptions, Duration) and deprecate Integer version.
</action>
<action dev="ggregory" due-to="Gary Gregory" type="add">
- Add FtpFileSystemConfigBuilder.setSoTimeout(FileSystemOptions, Duration) and deprecate Integer version.
+ [FTP] Add FtpFileSystemConfigBuilder.setSoTimeout(FileSystemOptions, Duration) and deprecate Integer version.
</action>
<action dev="ggregory" due-to="Gary Gregory" type="add">
- Add FtpFileSystemConfigBuilder.getConnectTimeoutDuration(FileSystemOptions) and deprecate Integer version.
+ [FTP] Add FtpFileSystemConfigBuilder.getConnectTimeoutDuration(FileSystemOptions) and deprecate Integer version.
</action>
<action dev="ggregory" due-to="Gary Gregory" type="add">
- Add FtpFileSystemConfigBuilder.getDataTimeoutDuration(FileSystemOptions) and deprecate Integer version.
+ [FTP] Add FtpFileSystemConfigBuilder.getDataTimeoutDuration(FileSystemOptions) and deprecate Integer version.
</action>
<action dev="ggregory" due-to="Gary Gregory" type="add">
- Add FtpFileSystemConfigBuilder.getSoTimeoutDuration(FileSystemOptions) and deprecate Integer version.
+ [FTP] Add FtpFileSystemConfigBuilder.getSoTimeoutDuration(FileSystemOptions) and deprecate Integer version.
+ </action>
+ <action dev="ggregory" due-to="Gary Gregory" type="add">
+ [FTP] Add FtpFileSystemConfigBuilder.getSoTimeoutDuration(FileSystemOptions) and deprecate Integer version.
+ </action>
+ <action dev="ggregory" due-to="Gary Gregory" type="add">
+ [HTTP] Add HttpFileSystemConfigBuilder.setConnectionTimeout(FileSystemOptions, Duration) and deprecate Integer version.
+ </action>
+ <action dev="ggregory" due-to="Gary Gregory" type="add">
+ [HTTP] Add HttpFileSystemConfigBuilder.setSoTimeout(FileSystemOptions, Duration) and deprecate Integer version.
+ </action>
+ <action dev="ggregory" due-to="Gary Gregory" type="add">
+ [HTTP] Add HttpFileSystemConfigBuilder.getConnectionTimeout(FileSystemOptions) and deprecate Integer version.
+ </action>
+ <action dev="ggregory" due-to="Gary Gregory" type="add">
+ [HTTP] Add HttpFileSystemConfigBuilder.getSoTimeoutDuration(FileSystemOptions) and deprecate Integer version.
</action>
<!-- UPDATES -->
<action dev="ggregory" due-to="PeterAlfredLee" type="update">