This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
The following commit(s) were added to refs/heads/master by this push:
new f59e0b1 VFS-687: adding http5 and http5s providers (#74)
f59e0b1 is described below
commit f59e0b1ce0fcd09298ec66fe6dd5025b9ca8b565
Author: Woonsan Ko <[email protected]>
AuthorDate: Mon Oct 28 23:05:35 2019 +0900
VFS-687: adding http5 and http5s providers (#74)
* VFS-687: adding http5 and http5s providers
* VFS-687: adding since tags
* VFS-687: adding since tags in http4 too
* VFS-687: no need to add since tag in package private type
---
commons-vfs2-examples/README.md | 20 ++-
commons-vfs2-examples/pom.xml | 17 +++
commons-vfs2/pom.xml | 5 +
.../http4/Http4FileContentInfoFactory.java | 2 +
.../vfs2/provider/http4/Http4FileNameParser.java | 2 +
.../vfs2/provider/http4/Http4FileObject.java | 4 +
.../vfs2/provider/http4/Http4FileProvider.java | 2 +
.../vfs2/provider/http4/Http4FileSystem.java | 2 +
.../http4/Http4FileSystemConfigBuilder.java | 2 +
.../vfs2/provider/http4s/Http4sFileNameParser.java | 2 +
.../vfs2/provider/http4s/Http4sFileProvider.java | 2 +
.../Http5FileContentInfoFactory.java} | 20 +--
.../Http5FileNameParser.java} | 12 +-
.../Http5FileObject.java} | 61 ++++----
.../Http5FileProvider.java} | 165 ++++++++++++---------
.../Http5FileSystem.java} | 20 +--
.../Http5FileSystemConfigBuilder.java} | 58 ++++++--
.../provider/http5/Http5RandomAccessContent.java | 143 ++++++++++++++++++
.../MonitoredHttpResponseContentInputStream.java | 46 ++++++
.../commons/vfs2/provider/http5/package.html | 19 +++
.../Http5sFileNameParser.java} | 12 +-
.../Http5sFileProvider.java} | 14 +-
.../commons/vfs2/provider/http5s/package.html | 19 +++
.../org/apache/commons/vfs2/impl/providers.xml | 4 +-
.../http4/test/Http4FilesCacheTestCase.java | 11 --
.../http4/test/Http4GetContentInfoTest.java | 11 --
.../provider/http4/test/Http4ProviderTestCase.java | 9 --
.../http4s/test/Http4sGetContentInfoTest.java | 19 +--
.../test/Http5FilesCacheTestCase.java} | 21 +--
.../test/Http5GetContentInfoTest.java} | 21 +--
.../test/Http5ProviderTestCase.java} | 37 ++---
.../test/Http5sGetContentInfoTest.java} | 29 +---
pom.xml | 5 +
33 files changed, 542 insertions(+), 274 deletions(-)
diff --git a/commons-vfs2-examples/README.md b/commons-vfs2-examples/README.md
index d7ab8fa..8603ffe 100644
--- a/commons-vfs2-examples/README.md
+++ b/commons-vfs2-examples/README.md
@@ -29,9 +29,13 @@
mvn -Pshell -Dhttp4
-## Test `http3`, `http3s`, `http4` and `http4s` providers together
+## Test `http5` and `http5s` providers
- mvn -Pshell -Dhttp3 -Dhttp4
+ mvn -Pshell -Dhttp5
+
+## Test all `http*` and `http*s` providers together
+
+ mvn -Pshell -Dhttp3 -Dhttp4 -Dhttp5
## Test `webdav3` providers
@@ -41,9 +45,9 @@
mvn -Pshell -Dwebdav4
-## Example Test Scenario with HTTP3 / HTTP4
+## Example Test Scenario with HTTP3 / HTTP4 / HTTP5
- mvn -Pshell -Dhttp3 -Dhttp4
+ mvn -Pshell -Dhttp3 -Dhttp4 -Dhttp5
...
cd http3://repo1.maven.org/maven2/org/apache/commons/commons-vfs2/
...
@@ -61,6 +65,14 @@
...
cat maven-metadata.xml
...
+ cd http5://repo1.maven.org/maven2/org/apache/commons/commons-vfs2/
+ ...
+ cat maven-metadata.xml
+ ...
+ cd http5s://repo1.maven.org/maven2/org/apache/commons/commons-vfs2/
+ ...
+ cat maven-metadata.xml
+ ...
cd http://repo1.maven.org/maven2/org/apache/commons/commons-vfs2/
...
cat maven-metadata.xml
diff --git a/commons-vfs2-examples/pom.xml b/commons-vfs2-examples/pom.xml
index cd6d64d..70ae661 100644
--- a/commons-vfs2-examples/pom.xml
+++ b/commons-vfs2-examples/pom.xml
@@ -139,6 +139,23 @@
</profile>
<profile>
+ <id>with-http5</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ <property>
+ <name>http5</name>
+ </property>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.httpcomponents.client5</groupId>
+ <artifactId>httpclient5</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ <profile>
<id>with-webdav3</id>
<activation>
<property>
diff --git a/commons-vfs2/pom.xml b/commons-vfs2/pom.xml
index 88adc5c..57de855 100644
--- a/commons-vfs2/pom.xml
+++ b/commons-vfs2/pom.xml
@@ -85,6 +85,11 @@
<optional>true</optional>
</dependency>
<dependency>
+ <groupId>org.apache.httpcomponents.client5</groupId>
+ <artifactId>httpclient5</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<optional>true</optional>
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileContentInfoFactory.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileContentInfoFactory.java
index f8fc3d4..b75d074 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileContentInfoFactory.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileContentInfoFactory.java
@@ -31,6 +31,8 @@ import org.apache.http.protocol.HTTP;
/**
* Creates <code>FileContentInfoFactory</code> instances for http4 provider.
+ *
+ * @since 2.3
*/
public class Http4FileContentInfoFactory implements FileContentInfoFactory {
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileNameParser.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileNameParser.java
index 4c6d78a..1eb578d 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileNameParser.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileNameParser.java
@@ -21,6 +21,8 @@ import
org.apache.commons.vfs2.provider.GenericURLFileNameParser;
/**
* <code>FileNameParser</code> implementation for http4 provider, setting
default port to 80.
+ *
+ * @since 2.3
*/
public class Http4FileNameParser extends GenericURLFileNameParser {
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileObject.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileObject.java
index 8115092..6bd7e71 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileObject.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileObject.java
@@ -47,6 +47,8 @@ import org.apache.http.protocol.HTTP;
* A file object backed by Apache HttpComponents HttpClient.
*
* @param <FS> An {@link Http4FileSystem} subclass
+ *
+ * @since 2.3
*/
public class Http4FileObject<FS extends Http4FileSystem> extends
AbstractFileObject<FS> {
@@ -220,6 +222,8 @@ public class Http4FileObject<FS extends Http4FileSystem>
extends AbstractFileObj
* @param httpRequest <code>HttpUriRequest</code> object
* @return <code>HttpResponse</code> from the execution
* @throws IOException if IO error occurs
+ *
+ * @since 2.5.0
*/
protected HttpResponse executeHttpUriRequest(final HttpUriRequest
httpRequest) throws IOException {
final HttpClient httpClient = getAbstractFileSystem().getHttpClient();
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java
index 4ac7a2f..67ad6f3 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java
@@ -78,6 +78,8 @@ import org.apache.http.ssl.SSLContextBuilder;
/**
* <code>FileProvider</code> implementation using HttpComponents HttpClient
library.
+ *
+ * @since 2.3
*/
public class Http4FileProvider extends AbstractOriginatingFileProvider {
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystem.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystem.java
index 2afbcc1..9274b7e 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystem.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystem.java
@@ -32,6 +32,8 @@ import org.apache.http.impl.client.CloseableHttpClient;
/**
* http4 file system.
+ *
+ * @since 2.3
*/
public class Http4FileSystem extends AbstractFileSystem {
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystemConfigBuilder.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystemConfigBuilder.java
index 7360b7c..d2da590 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystemConfigBuilder.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystemConfigBuilder.java
@@ -24,6 +24,8 @@ import org.apache.http.cookie.Cookie;
/**
* Configuration options builder utility for http4 provider.
+ *
+ * @since 2.3
*/
public class Http4FileSystemConfigBuilder extends FileSystemConfigBuilder {
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileNameParser.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileNameParser.java
index 6946ea7..50284e8 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileNameParser.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileNameParser.java
@@ -21,6 +21,8 @@ import
org.apache.commons.vfs2.provider.GenericURLFileNameParser;
/**
* <code>FileNameParser</code> implementation for http4s provider, setting
default port to 443.
+ *
+ * @since 2.3
*/
public class Http4sFileNameParser extends GenericURLFileNameParser {
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileProvider.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileProvider.java
index 277c97c..4f2f40d 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileProvider.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileProvider.java
@@ -20,6 +20,8 @@ import
org.apache.commons.vfs2.provider.http4.Http4FileProvider;
/**
* http4s provider that uses HttpComponents HttpClient.
+ *
+ * @since 2.3
*/
public class Http4sFileProvider extends Http4FileProvider {
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileContentInfoFactory.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileContentInfoFactory.java
similarity index 82%
copy from
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileContentInfoFactory.java
copy to
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileContentInfoFactory.java
index f8fc3d4..9a5aa6c 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileContentInfoFactory.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileContentInfoFactory.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.vfs2.provider.http4;
+package org.apache.commons.vfs2.provider.http5;
import java.io.IOException;
@@ -24,15 +24,17 @@ import org.apache.commons.vfs2.FileContentInfoFactory;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.impl.DefaultFileContentInfo;
import org.apache.commons.vfs2.util.FileObjectUtils;
-import org.apache.http.Header;
-import org.apache.http.HttpResponse;
-import org.apache.http.entity.ContentType;
-import org.apache.http.protocol.HTTP;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpResponse;
/**
- * Creates <code>FileContentInfoFactory</code> instances for http4 provider.
+ * Creates <code>FileContentInfoFactory</code> instances for http5 provider.
+ *
+ * @since 2.5.0
*/
-public class Http4FileContentInfoFactory implements FileContentInfoFactory {
+public class Http5FileContentInfoFactory implements FileContentInfoFactory {
@SuppressWarnings("unchecked")
@Override
@@ -40,11 +42,11 @@ public class Http4FileContentInfoFactory implements
FileContentInfoFactory {
String contentMimeType = null;
String contentCharset = null;
- try (final Http4FileObject<Http4FileSystem> http4File =
(Http4FileObject<Http4FileSystem>) FileObjectUtils
+ try (final Http5FileObject<Http5FileSystem> http4File =
(Http5FileObject<Http5FileSystem>) FileObjectUtils
.getAbstractFileObject(fileContent.getFile())) {
final HttpResponse lastHeadResponse =
http4File.getLastHeadResponse();
- final Header header =
lastHeadResponse.getFirstHeader(HTTP.CONTENT_TYPE);
+ final Header header =
lastHeadResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE);
if (header != null) {
final ContentType contentType =
ContentType.parse(header.getValue());
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileNameParser.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileNameParser.java
similarity index 78%
copy from
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileNameParser.java
copy to
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileNameParser.java
index 4c6d78a..0ba13f1 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileNameParser.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileNameParser.java
@@ -14,21 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.vfs2.provider.http4;
+package org.apache.commons.vfs2.provider.http5;
import org.apache.commons.vfs2.provider.FileNameParser;
import org.apache.commons.vfs2.provider.GenericURLFileNameParser;
/**
- * <code>FileNameParser</code> implementation for http4 provider, setting
default port to 80.
+ * <code>FileNameParser</code> implementation for http5 provider, setting
default port to 80.
+ *
+ * @since 2.5.0
*/
-public class Http4FileNameParser extends GenericURLFileNameParser {
+public class Http5FileNameParser extends GenericURLFileNameParser {
private static final int DEFAULT_PORT = 80;
- private static final Http4FileNameParser INSTANCE = new
Http4FileNameParser();
+ private static final Http5FileNameParser INSTANCE = new
Http5FileNameParser();
- public Http4FileNameParser() {
+ public Http5FileNameParser() {
super(DEFAULT_PORT);
}
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileObject.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileObject.java
similarity index 78%
copy from
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileObject.java
copy to
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileObject.java
index 8115092..a43a661 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileObject.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileObject.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.vfs2.provider.http4;
+package org.apache.commons.vfs2.provider.http5;
import java.io.IOException;
import java.io.InputStream;
@@ -31,24 +31,27 @@ import org.apache.commons.vfs2.provider.AbstractFileName;
import org.apache.commons.vfs2.provider.AbstractFileObject;
import org.apache.commons.vfs2.provider.GenericURLFileName;
import org.apache.commons.vfs2.util.RandomAccessMode;
-import org.apache.http.Header;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpHead;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.client.utils.DateUtils;
-import org.apache.http.client.utils.URIUtils;
-import org.apache.http.protocol.HTTP;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.classic.methods.HttpHead;
+import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.client5.http.utils.DateUtils;
+import org.apache.hc.client5.http.utils.URIUtils;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.HttpStatus;
/**
- * A file object backed by Apache HttpComponents HttpClient.
+ * A file object backed by Apache HttpComponents HttpClient v5.
*
- * @param <FS> An {@link Http4FileSystem} subclass
+ * @param <FS> An {@link Http5FileSystem} subclass
+ *
+ * @since 2.5.0
*/
-public class Http4FileObject<FS extends Http4FileSystem> extends
AbstractFileObject<FS> {
+public class Http5FileObject<FS extends Http5FileSystem> extends
AbstractFileObject<FS> {
/**
* URL charset string.
@@ -74,9 +77,9 @@ public class Http4FileObject<FS extends Http4FileSystem>
extends AbstractFileObj
* @throws FileSystemException if any error occurs
* @throws URISyntaxException if given file name cannot be converted to a
URI due to URI syntax error
*/
- protected Http4FileObject(final AbstractFileName name, final FS fileSystem)
+ protected Http5FileObject(final AbstractFileName name, final FS fileSystem)
throws FileSystemException, URISyntaxException {
- this(name, fileSystem, Http4FileSystemConfigBuilder.getInstance());
+ this(name, fileSystem, Http5FileSystemConfigBuilder.getInstance());
}
/**
@@ -88,8 +91,8 @@ public class Http4FileObject<FS extends Http4FileSystem>
extends AbstractFileObj
* @throws FileSystemException if any error occurs
* @throws URISyntaxException if given file name cannot be converted to a
URI due to URI syntax error
*/
- protected Http4FileObject(final AbstractFileName name, final FS fileSystem,
- final Http4FileSystemConfigBuilder builder) throws
FileSystemException, URISyntaxException {
+ protected Http5FileObject(final AbstractFileName name, final FS fileSystem,
+ final Http5FileSystemConfigBuilder builder) throws
FileSystemException, URISyntaxException {
super(name, fileSystem);
final FileSystemOptions fileSystemOptions =
fileSystem.getFileSystemOptions();
urlCharset = builder.getUrlCharset(fileSystemOptions);
@@ -100,7 +103,7 @@ public class Http4FileObject<FS extends Http4FileSystem>
extends AbstractFileObj
@Override
protected FileType doGetType() throws Exception {
lastHeadResponse = executeHttpUriRequest(new
HttpHead(getInternalURI()));
- final int status = lastHeadResponse.getStatusLine().getStatusCode();
+ final int status = lastHeadResponse.getCode();
if (status == HttpStatus.SC_OK
|| status == HttpStatus.SC_METHOD_NOT_ALLOWED /* method is not
allowed, but resource exist */) {
@@ -118,7 +121,7 @@ public class Http4FileObject<FS extends Http4FileSystem>
extends AbstractFileObj
return 0L;
}
- final Header header =
lastHeadResponse.getFirstHeader(HTTP.CONTENT_LEN);
+ final Header header =
lastHeadResponse.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
if (header == null) {
// Assume 0 content-length
@@ -143,8 +146,8 @@ public class Http4FileObject<FS extends Http4FileSystem>
extends AbstractFileObj
@Override
protected InputStream doGetInputStream(final int bufferSize) throws
Exception {
final HttpGet getRequest = new HttpGet(getInternalURI());
- final HttpResponse httpResponse = executeHttpUriRequest(getRequest);
- final int status = httpResponse.getStatusLine().getStatusCode();
+ final ClassicHttpResponse httpResponse =
executeHttpUriRequest(getRequest);
+ final int status = httpResponse.getCode();
if (status == HttpStatus.SC_NOT_FOUND) {
throw new FileNotFoundException(getName());
@@ -159,7 +162,7 @@ public class Http4FileObject<FS extends Http4FileSystem>
extends AbstractFileObj
@Override
protected RandomAccessContent doGetRandomAccessContent(final
RandomAccessMode mode) throws Exception {
- return new Http4RandomAccessContent<>(this, mode);
+ return new Http5RandomAccessContent<>(this, mode);
}
@Override
@@ -174,7 +177,7 @@ public class Http4FileObject<FS extends Http4FileSystem>
extends AbstractFileObj
@Override
protected FileContentInfoFactory getFileContentInfoFactory() {
- return new Http4FileContentInfoFactory();
+ return new Http5FileContentInfoFactory();
}
@Override
@@ -215,14 +218,14 @@ public class Http4FileObject<FS extends Http4FileSystem>
extends AbstractFileObj
}
/**
- * Execute the request using the given {@code httpRequest} and return a
<code>HttpResponse</code> from the execution.
+ * Execute the request using the given {@code httpRequest} and return a
<code>ClassicHttpResponse</code> from the execution.
*
* @param httpRequest <code>HttpUriRequest</code> object
- * @return <code>HttpResponse</code> from the execution
+ * @return <code>ClassicHttpResponse</code> from the execution
* @throws IOException if IO error occurs
*/
- protected HttpResponse executeHttpUriRequest(final HttpUriRequest
httpRequest) throws IOException {
- final HttpClient httpClient = getAbstractFileSystem().getHttpClient();
+ protected ClassicHttpResponse executeHttpUriRequest(final HttpUriRequest
httpRequest) throws IOException {
+ final CloseableHttpClient httpClient = (CloseableHttpClient)
getAbstractFileSystem().getHttpClient();
final HttpClientContext httpClientContext =
getAbstractFileSystem().getHttpClientContext();
return httpClient.execute(httpRequest, httpClientContext);
}
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileProvider.java
similarity index 71%
copy from
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java
copy to
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileProvider.java
index 4ac7a2f..ea7922e 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileProvider.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.vfs2.provider.http4;
+package org.apache.commons.vfs2.provider.http5;
import java.io.File;
import java.io.IOException;
@@ -28,6 +28,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
@@ -43,43 +44,49 @@ import org.apache.commons.vfs2.UserAuthenticator;
import org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider;
import org.apache.commons.vfs2.provider.GenericFileName;
import org.apache.commons.vfs2.util.UserAuthenticatorUtils;
-import org.apache.http.ConnectionReuseStrategy;
-import org.apache.http.Header;
-import org.apache.http.HttpHost;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.AuthCache;
-import org.apache.http.client.CookieStore;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.config.SocketConfig;
-import org.apache.http.conn.HttpClientConnectionManager;
-import org.apache.http.conn.routing.HttpRoutePlanner;
-import org.apache.http.conn.ssl.DefaultHostnameVerifier;
-import org.apache.http.conn.ssl.NoopHostnameVerifier;
-import org.apache.http.conn.ssl.TrustAllStrategy;
-import org.apache.http.cookie.Cookie;
-import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.impl.NoConnectionReuseStrategy;
-import org.apache.http.impl.auth.BasicScheme;
-import org.apache.http.impl.client.BasicAuthCache;
-import org.apache.http.impl.client.BasicCookieStore;
-import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.conn.DefaultProxyRoutePlanner;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
-import org.apache.http.message.BasicHeader;
-import org.apache.http.protocol.HTTP;
-import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.hc.client5.http.auth.AuthCache;
+import org.apache.hc.client5.http.auth.AuthScope;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
+import org.apache.hc.client5.http.classic.HttpClient;
+import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.client5.http.cookie.BasicCookieStore;
+import org.apache.hc.client5.http.cookie.Cookie;
+import org.apache.hc.client5.http.cookie.CookieStore;
+import org.apache.hc.client5.http.impl.auth.BasicAuthCache;
+import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
+import org.apache.hc.client5.http.impl.auth.BasicScheme;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import
org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
+import org.apache.hc.client5.http.impl.routing.DefaultProxyRoutePlanner;
+import org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner;
+import org.apache.hc.client5.http.io.HttpClientConnectionManager;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.client5.http.routing.HttpRoutePlanner;
+import org.apache.hc.client5.http.ssl.DefaultHostnameVerifier;
+import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
+import org.apache.hc.client5.http.ssl.TrustAllStrategy;
+import org.apache.hc.core5.http.ConnectionReuseStrategy;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.hc.core5.http.io.SocketConfig;
+import org.apache.hc.core5.http.message.BasicHeader;
+import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.http.ssl.TLS;
+import org.apache.hc.core5.ssl.SSLContextBuilder;
/**
- * <code>FileProvider</code> implementation using HttpComponents HttpClient
library.
+ * <code>FileProvider</code> implementation using HttpComponents HttpClient v5
library.
+ *
+ * @since 2.5.0
*/
-public class Http4FileProvider extends AbstractOriginatingFileProvider {
+public class Http5FileProvider extends AbstractOriginatingFileProvider {
/** Authenticator information. */
static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES =
@@ -105,14 +112,14 @@ public class Http4FileProvider extends
AbstractOriginatingFileProvider {
/**
* Constructs a new provider.
*/
- public Http4FileProvider() {
+ public Http5FileProvider() {
super();
- setFileNameParser(Http4FileNameParser.getInstance());
+ setFileNameParser(Http5FileNameParser.getInstance());
}
@Override
public FileSystemConfigBuilder getConfigBuilder() {
- return Http4FileSystemConfigBuilder.getInstance();
+ return Http5FileSystemConfigBuilder.getInstance();
}
@Override
@@ -130,7 +137,7 @@ public class Http4FileProvider extends
AbstractOriginatingFileProvider {
HttpClientContext httpClientContext = null;
try {
- final Http4FileSystemConfigBuilder builder =
Http4FileSystemConfigBuilder.getInstance();
+ final Http5FileSystemConfigBuilder builder =
Http5FileSystemConfigBuilder.getInstance();
authData = UserAuthenticatorUtils.authenticate(fileSystemOptions,
AUTHENTICATOR_TYPES);
httpClientContext = createHttpClientContext(builder, rootName,
fileSystemOptions, authData);
httpClient = createHttpClient(builder, rootName,
fileSystemOptions);
@@ -138,7 +145,7 @@ public class Http4FileProvider extends
AbstractOriginatingFileProvider {
UserAuthenticatorUtils.cleanup(authData);
}
- return new Http4FileSystem(rootName, fileSystemOptions, httpClient,
httpClientContext);
+ return new Http5FileSystem(rootName, fileSystemOptions, httpClient,
httpClientContext);
}
/**
@@ -150,13 +157,13 @@ public class Http4FileProvider extends
AbstractOriginatingFileProvider {
* @return an {@link HttpClient} object
* @throws FileSystemException if an error occurs.
*/
- protected HttpClient createHttpClient(final Http4FileSystemConfigBuilder
builder, final GenericFileName rootName,
+ protected HttpClient createHttpClient(final Http5FileSystemConfigBuilder
builder, final GenericFileName rootName,
final FileSystemOptions fileSystemOptions) throws
FileSystemException {
return createHttpClientBuilder(builder, rootName,
fileSystemOptions).build();
}
/**
- * Create an {@link HttpClientBuilder} object. Invoked by {@link
#createHttpClient(Http4FileSystemConfigBuilder, GenericFileName,
FileSystemOptions)}.
+ * Create an {@link HttpClientBuilder} object. Invoked by {@link
#createHttpClient(Http5FileSystemConfigBuilder, GenericFileName,
FileSystemOptions)}.
*
* @param builder Configuration options builder for HTTP4 provider
* @param rootName The root path
@@ -164,21 +171,25 @@ public class Http4FileProvider extends
AbstractOriginatingFileProvider {
* @return an {@link HttpClientBuilder} object
* @throws FileSystemException if an error occurs
*/
- protected HttpClientBuilder createHttpClientBuilder(final
Http4FileSystemConfigBuilder builder, final GenericFileName rootName,
+ protected HttpClientBuilder createHttpClientBuilder(final
Http5FileSystemConfigBuilder builder, final GenericFileName rootName,
final FileSystemOptions fileSystemOptions) throws
FileSystemException {
final List<Header> defaultHeaders = new ArrayList<>();
- defaultHeaders.add(new BasicHeader(HTTP.USER_AGENT,
builder.getUserAgent(fileSystemOptions)));
+ defaultHeaders.add(new BasicHeader(HttpHeaders.USER_AGENT,
builder.getUserAgent(fileSystemOptions)));
final ConnectionReuseStrategy connectionReuseStrategy =
builder.isKeepAlive(fileSystemOptions)
? DefaultConnectionReuseStrategy.INSTANCE
- : NoConnectionReuseStrategy.INSTANCE;
+ : new ConnectionReuseStrategy() {
+ @Override
+ public boolean keepAlive(
+ final HttpRequest request, final HttpResponse
response, final HttpContext context) {
+ return false;
+ }
+ };
final HttpClientBuilder httpClientBuilder =
HttpClients.custom()
.setRoutePlanner(createHttpRoutePlanner(builder,
fileSystemOptions))
.setConnectionManager(createConnectionManager(builder,
fileSystemOptions))
- .setSSLContext(createSSLContext(builder, fileSystemOptions))
- .setSSLHostnameVerifier(createHostnameVerifier(builder,
fileSystemOptions))
.setConnectionReuseStrategy(connectionReuseStrategy)
.setDefaultRequestConfig(createDefaultRequestConfig(builder,
fileSystemOptions))
.setDefaultHeaders(defaultHeaders)
@@ -192,14 +203,14 @@ public class Http4FileProvider extends
AbstractOriginatingFileProvider {
}
/**
- * Create {@link SSLContext} for HttpClient. Invoked by {@link
#createHttpClientBuilder(Http4FileSystemConfigBuilder, GenericFileName,
FileSystemOptions)}.
+ * Create {@link SSLContext} for HttpClient. Invoked by {@link
#createHttpClientBuilder(Http5FileSystemConfigBuilder, GenericFileName,
FileSystemOptions)}.
*
* @param builder Configuration options builder for HTTP4 provider
* @param fileSystemOptions The FileSystem options
* @return a {@link SSLContext} for HttpClient
* @throws FileSystemException if an error occurs
*/
- protected SSLContext createSSLContext(final Http4FileSystemConfigBuilder
builder,
+ protected SSLContext createSSLContext(final Http5FileSystemConfigBuilder
builder,
final FileSystemOptions fileSystemOptions) throws
FileSystemException {
try {
final SSLContextBuilder sslContextBuilder = new
SSLContextBuilder();
@@ -243,21 +254,22 @@ public class Http4FileProvider extends
AbstractOriginatingFileProvider {
* @return an {@link HttpClientContext} object
* @throws FileSystemException if an error occurs
*/
- protected HttpClientContext createHttpClientContext(final
Http4FileSystemConfigBuilder builder,
+ protected HttpClientContext createHttpClientContext(final
Http5FileSystemConfigBuilder builder,
final GenericFileName rootName, final FileSystemOptions
fileSystemOptions,
final UserAuthenticationData authData) throws FileSystemException {
final HttpClientContext clientContext = HttpClientContext.create();
- final CredentialsProvider credsProvider = new
BasicCredentialsProvider();
+ final BasicCredentialsProvider credsProvider = new
BasicCredentialsProvider();
clientContext.setCredentialsProvider(credsProvider);
final String username =
UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
UserAuthenticationData.USERNAME,
UserAuthenticatorUtils.toChar(rootName.getUserName())));
- final String password =
UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
- UserAuthenticationData.PASSWORD,
UserAuthenticatorUtils.toChar(rootName.getPassword())));
+ final char[] password = UserAuthenticatorUtils.getData(authData,
+ UserAuthenticationData.PASSWORD,
UserAuthenticatorUtils.toChar(rootName.getPassword()));
if (username != null && !username.isEmpty()) {
- credsProvider.setCredentials(new AuthScope(rootName.getHostName(),
AuthScope.ANY_PORT),
+ // -1 for any port
+ credsProvider.setCredentials(new AuthScope(rootName.getHostName(),
-1),
new UsernamePasswordCredentials(username, password));
}
@@ -275,10 +287,10 @@ public class Http4FileProvider extends
AbstractOriginatingFileProvider {
final UsernamePasswordCredentials proxyCreds = new
UsernamePasswordCredentials(
UserAuthenticatorUtils.toString(
UserAuthenticatorUtils.getData(authData,
UserAuthenticationData.USERNAME, null)),
- UserAuthenticatorUtils.toString(
- UserAuthenticatorUtils.getData(authData,
UserAuthenticationData.PASSWORD, null)));
+ UserAuthenticatorUtils.getData(authData,
UserAuthenticationData.PASSWORD, null));
- credsProvider.setCredentials(new
AuthScope(proxyHost.getHostName(), AuthScope.ANY_PORT),
+ // -1 for any port
+ credsProvider.setCredentials(new
AuthScope(proxyHost.getHostName(), -1),
proxyCreds);
}
@@ -294,31 +306,44 @@ public class Http4FileProvider extends
AbstractOriginatingFileProvider {
return clientContext;
}
- private HttpClientConnectionManager createConnectionManager(final
Http4FileSystemConfigBuilder builder,
+ private HttpClientConnectionManager createConnectionManager(final
Http5FileSystemConfigBuilder builder,
final FileSystemOptions fileSystemOptions) throws
FileSystemException {
- final PoolingHttpClientConnectionManager connManager = new
PoolingHttpClientConnectionManager();
-
connManager.setMaxTotal(builder.getMaxTotalConnections(fileSystemOptions));
-
connManager.setDefaultMaxPerRoute(builder.getMaxConnectionsPerHost(fileSystemOptions));
final SocketConfig socketConfig =
SocketConfig
.custom()
- .setSoTimeout(builder.getSoTimeout(fileSystemOptions))
+ .setSoTimeout(builder.getSoTimeout(fileSystemOptions),
TimeUnit.MILLISECONDS)
.build();
- connManager.setDefaultSocketConfig(socketConfig);
+ final String[] tlsVersions =
builder.getTlsVersions(fileSystemOptions).split("\\s*,\\s*");
+ final TLS[] tlsArray = new TLS[tlsVersions.length];
+
+ for (int i = 0; i < tlsVersions.length; i++) {
+ tlsArray[i] = TLS.valueOf(tlsVersions[i]);
+ }
- return connManager;
+ final SSLConnectionSocketFactory sslSocketFactory =
SSLConnectionSocketFactoryBuilder.create()
+ .setSslContext(createSSLContext(builder, fileSystemOptions))
+ .setHostnameVerifier(createHostnameVerifier(builder,
fileSystemOptions))
+ .setTlsVersions(tlsArray)
+ .build();
+
+ return PoolingHttpClientConnectionManagerBuilder.create()
+ .setSSLSocketFactory(sslSocketFactory)
+
.setMaxConnTotal(builder.getMaxTotalConnections(fileSystemOptions))
+
.setMaxConnPerRoute(builder.getMaxConnectionsPerHost(fileSystemOptions))
+ .setDefaultSocketConfig(socketConfig)
+ .build();
}
- private RequestConfig createDefaultRequestConfig(final
Http4FileSystemConfigBuilder builder,
+ private RequestConfig createDefaultRequestConfig(final
Http5FileSystemConfigBuilder builder,
final FileSystemOptions fileSystemOptions) {
return RequestConfig.custom()
-
.setConnectTimeout(builder.getConnectionTimeout(fileSystemOptions))
+
.setConnectTimeout(builder.getConnectionTimeout(fileSystemOptions),
TimeUnit.MILLISECONDS)
.build();
}
- private HttpRoutePlanner createHttpRoutePlanner(final
Http4FileSystemConfigBuilder builder,
+ private HttpRoutePlanner createHttpRoutePlanner(final
Http5FileSystemConfigBuilder builder,
final FileSystemOptions fileSystemOptions) {
final HttpHost proxyHost = getProxyHttpHost(builder,
fileSystemOptions);
@@ -329,7 +354,7 @@ public class Http4FileProvider extends
AbstractOriginatingFileProvider {
return new SystemDefaultRoutePlanner(ProxySelector.getDefault());
}
- private HttpHost getProxyHttpHost(final Http4FileSystemConfigBuilder
builder,
+ private HttpHost getProxyHttpHost(final Http5FileSystemConfigBuilder
builder,
final FileSystemOptions fileSystemOptions) {
final String proxyHost = builder.getProxyHost(fileSystemOptions);
final int proxyPort = builder.getProxyPort(fileSystemOptions);
@@ -341,7 +366,7 @@ public class Http4FileProvider extends
AbstractOriginatingFileProvider {
return null;
}
- private CookieStore createDefaultCookieStore(final
Http4FileSystemConfigBuilder builder,
+ private CookieStore createDefaultCookieStore(final
Http5FileSystemConfigBuilder builder,
final FileSystemOptions fileSystemOptions) {
final CookieStore cookieStore = new BasicCookieStore();
final Cookie[] cookies = builder.getCookies(fileSystemOptions);
@@ -355,7 +380,7 @@ public class Http4FileProvider extends
AbstractOriginatingFileProvider {
return cookieStore;
}
- private HostnameVerifier createHostnameVerifier(final
Http4FileSystemConfigBuilder builder,
+ private HostnameVerifier createHostnameVerifier(final
Http5FileSystemConfigBuilder builder,
final FileSystemOptions fileSystemOptions) throws
FileSystemException {
if (!builder.isHostnameVerificationEnabled(fileSystemOptions)) {
return NoopHostnameVerifier.INSTANCE;
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystem.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileSystem.java
similarity index 88%
copy from
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystem.java
copy to
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileSystem.java
index 2afbcc1..a7e2be1 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystem.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileSystem.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.vfs2.provider.http4;
+package org.apache.commons.vfs2.provider.http5;
import java.io.IOException;
import java.net.URI;
@@ -26,14 +26,16 @@ import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.provider.AbstractFileName;
import org.apache.commons.vfs2.provider.AbstractFileSystem;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.hc.client5.http.classic.HttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
/**
- * http4 file system.
+ * http5 file system.
+ *
+ * @since 2.5.0
*/
-public class Http4FileSystem extends AbstractFileSystem {
+public class Http5FileSystem extends AbstractFileSystem {
/**
* Internal base URI of this file system.
@@ -58,7 +60,7 @@ public class Http4FileSystem extends AbstractFileSystem {
* @param httpClient {@link HttpClient} instance
* @param httpClientContext {@link HttpClientContext} instance
*/
- protected Http4FileSystem(final FileName rootName, final FileSystemOptions
fileSystemOptions, final HttpClient httpClient,
+ protected Http5FileSystem(final FileName rootName, final FileSystemOptions
fileSystemOptions, final HttpClient httpClient,
final HttpClientContext httpClientContext) {
super(rootName, null, fileSystemOptions);
@@ -79,12 +81,12 @@ public class Http4FileSystem extends AbstractFileSystem {
@Override
protected FileObject createFile(final AbstractFileName name) throws
Exception {
- return new Http4FileObject<>(name, this);
+ return new Http5FileObject<>(name, this);
}
@Override
protected void addCapabilities(final Collection<Capability> caps) {
- caps.addAll(Http4FileProvider.capabilities);
+ caps.addAll(Http5FileProvider.capabilities);
}
@Override
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystemConfigBuilder.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileSystemConfigBuilder.java
similarity index 88%
copy from
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystemConfigBuilder.java
copy to
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileSystemConfigBuilder.java
index 7360b7c..cde0ee7 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystemConfigBuilder.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileSystemConfigBuilder.java
@@ -14,20 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.vfs2.provider.http4;
+package org.apache.commons.vfs2.provider.http5;
import org.apache.commons.vfs2.FileSystem;
import org.apache.commons.vfs2.FileSystemConfigBuilder;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.UserAuthenticator;
-import org.apache.http.cookie.Cookie;
+import org.apache.hc.client5.http.cookie.Cookie;
/**
- * Configuration options builder utility for http4 provider.
+ * Configuration options builder utility for http5 provider.
+ *
+ * @since 2.5.0
*/
-public class Http4FileSystemConfigBuilder extends FileSystemConfigBuilder {
+public class Http5FileSystemConfigBuilder extends FileSystemConfigBuilder {
- private static final Http4FileSystemConfigBuilder BUILDER = new
Http4FileSystemConfigBuilder();
+ private static final Http5FileSystemConfigBuilder BUILDER = new
Http5FileSystemConfigBuilder();
/**
* Defines the maximum number of connections allowed overall. This value
only applies
@@ -118,6 +120,15 @@ public class Http4FileSystemConfigBuilder extends
FileSystemConfigBuilder {
private static final String KEY_PREEMPTIVE_AUTHENTICATION =
"preemptiveAuth";
/**
+ * Defines the enabled TLS versions for the underlying HttpClient.
+ * <p>
+ * This parameter expects a value of type {@link String} as a comma
separated string, each token of
+ * which is the name of <code>org.apache.hc.core5.http.ssl.TLS</code>
enum. e.g, "V_1_2, V_1_3".
+ * </p>
+ */
+ private static final String KEY_TLS_VERSIONS = "tlsVersions";
+
+ /**
* The default value for {@link #MAX_TOTAL_CONNECTIONS} configuration.
*/
private static final int DEFAULT_MAX_CONNECTIONS = 50;
@@ -158,15 +169,21 @@ public class Http4FileSystemConfigBuilder extends
FileSystemConfigBuilder {
private static final boolean DEFAULT_HOSTNAME_VERIFICATION_ENABLED = true;
/**
+ * The default value for {@link #KEY_TLS_VERSIONS} configuration as a
comma separated string, each token of
+ * which is the name of <code>org.apache.hc.core5.http.ssl.TLS</code>
enum. e.g, "V_1_2, V_1_3".
+ */
+ private static final String DEFAULT_TLS_VERSIONS = "V_1_2";
+
+ /**
* Construct an <code>Http4FileSystemConfigBuilder</code>.
*
* @param prefix String for properties of this file system.
*/
- protected Http4FileSystemConfigBuilder(final String prefix) {
+ protected Http5FileSystemConfigBuilder(final String prefix) {
super(prefix);
}
- private Http4FileSystemConfigBuilder() {
+ private Http5FileSystemConfigBuilder() {
super("http.");
}
@@ -175,7 +192,7 @@ public class Http4FileSystemConfigBuilder extends
FileSystemConfigBuilder {
*
* @return the singleton builder.
*/
- public static Http4FileSystemConfigBuilder getInstance() {
+ public static Http5FileSystemConfigBuilder getInstance() {
return BUILDER;
}
@@ -510,8 +527,31 @@ public class Http4FileSystemConfigBuilder extends
FileSystemConfigBuilder {
return getBoolean(opts, HOSTNAME_VERIFICATION_ENABLED,
DEFAULT_HOSTNAME_VERIFICATION_ENABLED);
}
+ /**
+ * Sets the enabled TLS versions as a comma separated string, each token
of which is the name of
+ * <code>org.apache.hc.core5.http.ssl.TLS</code> enum. e.g, "V_1_2, V_1_3".
+ *
+ * @param opts the file system options to modify
+ * @param tlsVersions enabled TLS versions
+ */
+ public void setTlsVersions(final FileSystemOptions opts, final String
tlsVersions) {
+ setParam(opts, KEY_TLS_VERSIONS, tlsVersions);
+ }
+
+ /**
+ * Gets the enabled TLS versions as a comma separated string, each token
of which is the name of
+ * <code>org.apache.hc.core5.http.ssl.TLS</code> enum. e.g, "V_1_2, V_1_3".
+ *
+ * @param opts the file system options to modify
+ * @return enabled TLS versions
+ */
+ public String getTlsVersions(final FileSystemOptions opts) {
+ final String tlsVersions = (String) getParam(opts, KEY_TLS_VERSIONS);
+ return tlsVersions != null ? tlsVersions : DEFAULT_TLS_VERSIONS;
+ }
+
@Override
protected Class<? extends FileSystem> getConfigClass() {
- return Http4FileSystem.class;
+ return Http5FileSystem.class;
}
}
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5RandomAccessContent.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5RandomAccessContent.java
new file mode 100644
index 0000000..2751836
--- /dev/null
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5RandomAccessContent.java
@@ -0,0 +1,143 @@
+/*
+ * 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.http5;
+
+import java.io.DataInputStream;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.provider.AbstractRandomAccessStreamContent;
+import org.apache.commons.vfs2.util.MonitorInputStream;
+import org.apache.commons.vfs2.util.RandomAccessMode;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+
+/**
+ * RandomAccess content using <code>Http5FileObject</code>.
+ */
+class Http5RandomAccessContent<FS extends Http5FileSystem> extends
AbstractRandomAccessStreamContent {
+
+ protected long filePointer = 0;
+
+ private final Http5FileObject<FS> fileObject;
+
+ private DataInputStream dis = null;
+ private MonitorInputStream mis = null;
+
+ Http5RandomAccessContent(final Http5FileObject<FS> fileObject, final
RandomAccessMode mode) {
+ super(mode);
+ this.fileObject = fileObject;
+ }
+
+ @Override
+ public long getFilePointer() throws IOException {
+ return filePointer;
+ }
+
+ @Override
+ public void seek(final long pos) throws IOException {
+ if (pos == filePointer) {
+ // no change
+ return;
+ }
+
+ if (pos < 0) {
+ throw new
FileSystemException("vfs.provider/random-access-invalid-position.error",
Long.valueOf(pos));
+ }
+
+ if (dis != null) {
+ close();
+ }
+
+ filePointer = pos;
+ }
+
+ @Override
+ protected DataInputStream getDataInputStream() throws IOException {
+ if (dis != null) {
+ return dis;
+ }
+
+ final HttpGet httpGet = new HttpGet(fileObject.getInternalURI());
+ httpGet.setHeader("Range", "bytes=" + filePointer + "-");
+ final ClassicHttpResponse httpResponse =
fileObject.executeHttpUriRequest(httpGet);
+ final int status = httpResponse.getCode();
+
+ if (status != HttpURLConnection.HTTP_PARTIAL && status !=
HttpURLConnection.HTTP_OK) {
+ throw new FileSystemException("vfs.provider.http/get-range.error",
fileObject.getName(),
+ Long.valueOf(filePointer), Integer.valueOf(status));
+ }
+
+ mis = new MonitoredHttpResponseContentInputStream(httpResponse);
+
+ // If the range request was ignored
+ if (status == HttpURLConnection.HTTP_OK) {
+ final long skipped = mis.skip(filePointer);
+ if (skipped != filePointer) {
+ throw new
FileSystemException("vfs.provider.http/get-range.error", fileObject.getName(),
+ Long.valueOf(filePointer), Integer.valueOf(status));
+ }
+ }
+
+ dis = new DataInputStream(new FilterInputStream(mis) {
+ @Override
+ public int read() throws IOException {
+ final int ret = super.read();
+ if (ret > -1) {
+ filePointer++;
+ }
+ return ret;
+ }
+
+ @Override
+ public int read(final byte[] b) throws IOException {
+ final int ret = super.read(b);
+ if (ret > -1) {
+ filePointer += ret;
+ }
+ return ret;
+ }
+
+ @Override
+ public int read(final byte[] b, final int off, final int len)
throws IOException {
+ final int ret = super.read(b, off, len);
+ if (ret > -1) {
+ filePointer += ret;
+ }
+ return ret;
+ }
+ });
+
+ return dis;
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (dis != null) {
+ dis.close();
+ dis = null;
+ mis = null;
+ }
+ }
+
+ @Override
+ public long length() throws IOException {
+ return fileObject.getContent().getSize();
+ }
+}
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/MonitoredHttpResponseContentInputStream.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/MonitoredHttpResponseContentInputStream.java
new file mode 100644
index 0000000..e1dda19
--- /dev/null
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/MonitoredHttpResponseContentInputStream.java
@@ -0,0 +1,46 @@
+/*
+ * 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.http5;
+
+import java.io.IOException;
+
+import org.apache.commons.vfs2.util.MonitorInputStream;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+
+/**
+ * An InputStream that cleans up the
<code>org.apache.hc.core5.http.ClassicHttpResponse</code> on close.
+ */
+class MonitoredHttpResponseContentInputStream extends MonitorInputStream {
+
+ private final ClassicHttpResponse httpResponse;
+
+ public MonitoredHttpResponseContentInputStream(final ClassicHttpResponse
httpResponse) throws IOException {
+ super(httpResponse.getEntity().getContent());
+ this.httpResponse = httpResponse;
+ }
+
+ public MonitoredHttpResponseContentInputStream(final ClassicHttpResponse
httpResponse, final int bufferSize) throws IOException {
+ super(httpResponse.getEntity().getContent(), bufferSize);
+ this.httpResponse = httpResponse;
+ }
+
+ @Override
+ protected void onClose() throws IOException {
+ httpResponse.close();
+ }
+
+}
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/package.html
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/package.html
new file mode 100644
index 0000000..872b82c
--- /dev/null
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/package.html
@@ -0,0 +1,19 @@
+<!--
+ 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.
+-->
+<body>
+<p>The HTTP5 File Provider</p>
+</body>
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileNameParser.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5s/Http5sFileNameParser.java
similarity index 78%
copy from
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileNameParser.java
copy to
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5s/Http5sFileNameParser.java
index 6946ea7..ed95d4e 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileNameParser.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5s/Http5sFileNameParser.java
@@ -14,21 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.vfs2.provider.http4s;
+package org.apache.commons.vfs2.provider.http5s;
import org.apache.commons.vfs2.provider.FileNameParser;
import org.apache.commons.vfs2.provider.GenericURLFileNameParser;
/**
- * <code>FileNameParser</code> implementation for http4s provider, setting
default port to 443.
+ * <code>FileNameParser</code> implementation for http5s provider, setting
default port to 443.
+ *
+ * @since 2.5.0
*/
-public class Http4sFileNameParser extends GenericURLFileNameParser {
+public class Http5sFileNameParser extends GenericURLFileNameParser {
private static final int DEFAULT_PORT = 443;
- private static final Http4sFileNameParser INSTANCE = new
Http4sFileNameParser();
+ private static final Http5sFileNameParser INSTANCE = new
Http5sFileNameParser();
- public Http4sFileNameParser() {
+ public Http5sFileNameParser() {
super(DEFAULT_PORT);
}
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileProvider.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5s/Http5sFileProvider.java
similarity index 72%
copy from
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileProvider.java
copy to
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5s/Http5sFileProvider.java
index 277c97c..f8a246d 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4s/Http4sFileProvider.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5s/Http5sFileProvider.java
@@ -14,20 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.vfs2.provider.http4s;
+package org.apache.commons.vfs2.provider.http5s;
-import org.apache.commons.vfs2.provider.http4.Http4FileProvider;
+import org.apache.commons.vfs2.provider.http5.Http5FileProvider;
/**
- * http4s provider that uses HttpComponents HttpClient.
+ * http5s provider that uses HttpComponents HttpClient.
+ *
+ * @since 2.5.0
*/
-public class Http4sFileProvider extends Http4FileProvider {
+public class Http5sFileProvider extends Http5FileProvider {
/**
* Construct a <code>Http4sFileProvider</code>.
*/
- public Http4sFileProvider() {
+ public Http5sFileProvider() {
super();
- setFileNameParser(Http4sFileNameParser.getInstance());
+ setFileNameParser(Http5sFileNameParser.getInstance());
}
}
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5s/package.html
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5s/package.html
new file mode 100644
index 0000000..de7045b
--- /dev/null
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5s/package.html
@@ -0,0 +1,19 @@
+<!--
+ 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.
+-->
+<body>
+<p>The HTTP5S File Provider</p>
+</body>
diff --git
a/commons-vfs2/src/main/resources/org/apache/commons/vfs2/impl/providers.xml
b/commons-vfs2/src/main/resources/org/apache/commons/vfs2/impl/providers.xml
index cbc12a2..332f2ff 100644
--- a/commons-vfs2/src/main/resources/org/apache/commons/vfs2/impl/providers.xml
+++ b/commons-vfs2/src/main/resources/org/apache/commons/vfs2/impl/providers.xml
@@ -79,16 +79,14 @@
</provider>
<!-- http5/http5s providers based on HttpClient v5 -->
- <!-- TODO
<provider
class-name="org.apache.commons.vfs2.provider.http5.Http5FileProvider">
<scheme name="http5"/>
<if-available
class-name="org.apache.hc.client5.http.classic.HttpClient"/>
</provider>
- <provider
class-name="org.apache.commons.vfs2.provider.http4s.Http5sFileProvider">
+ <provider
class-name="org.apache.commons.vfs2.provider.http5s.Http5sFileProvider">
<scheme name="http5s"/>
<if-available
class-name="org.apache.hc.client5.http.classic.HttpClient"/>
</provider>
- -->
<provider
class-name="org.apache.commons.vfs2.provider.sftp.SftpFileProvider">
<scheme name="sftp"/>
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4FilesCacheTestCase.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4FilesCacheTestCase.java
index d2b62ee..c05cbf4 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4FilesCacheTestCase.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4FilesCacheTestCase.java
@@ -20,8 +20,6 @@ import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.VFS;
-import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
-import org.apache.commons.vfs2.provider.http4.Http4FileProvider;
import org.junit.Assert;
import org.junit.Test;
@@ -32,15 +30,6 @@ import junit.framework.TestCase;
*/
public class Http4FilesCacheTestCase extends TestCase {
- // TODO: VFS-360 - Remove this manual registration of http4 once http4
becomes part of standard providers.
- @Override
- protected void setUp() throws Exception {
- final DefaultFileSystemManager manager = (DefaultFileSystemManager)
VFS.getManager();
- if (!manager.hasProvider("http4")) {
- manager.addProvider("http4", new Http4FileProvider());
- }
- }
-
/**
* Tests https://issues.apache.org/jira/browse/VFS-426
*/
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
index 6f5e83a..693f2da 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
@@ -21,8 +21,6 @@ import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.VFS;
-import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
-import org.apache.commons.vfs2.provider.http4.Http4FileProvider;
import org.junit.Assert;
import org.junit.Test;
@@ -33,15 +31,6 @@ import junit.framework.TestCase;
*/
public class Http4GetContentInfoTest extends TestCase {
- // TODO: VFS-360 - Remove this manual registration of http4 once http4
becomes part of standard providers.
- @Override
- protected void setUp() throws Exception {
- final DefaultFileSystemManager manager = (DefaultFileSystemManager)
VFS.getManager();
- if (!manager.hasProvider("http4")) {
- manager.addProvider("http4", new Http4FileProvider());
- }
- }
-
/**
* Tests VFS-427 NPE on Http4FileObject.getContent().getContentInfo().
*
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4ProviderTestCase.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4ProviderTestCase.java
index c49e90c..4e6da32 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4ProviderTestCase.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4ProviderTestCase.java
@@ -127,15 +127,6 @@ public class Http4ProviderTestCase extends
AbstractProviderTestConfig {
Assert.assertTrue(file.getChildren().length > 0);
}
- // TODO: VFS-360 - Remove this manual registration of http4 once http4
becomes part of standard providers.
- @Override
- protected void setUp() throws Exception {
- final DefaultFileSystemManager manager = (DefaultFileSystemManager)
VFS.getManager();
- if (!manager.hasProvider("http4")) {
- manager.addProvider("http4", new Http4FileProvider());
- }
- }
-
/**
* Returns the base folder for tests.
*/
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4s/test/Http4sGetContentInfoTest.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4s/test/Http4sGetContentInfoTest.java
index 6a4416b..50295f1 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4s/test/Http4sGetContentInfoTest.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4s/test/Http4sGetContentInfoTest.java
@@ -25,34 +25,19 @@ import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.VFS;
-import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
-import org.apache.commons.vfs2.provider.http4.Http4FileProvider;
import org.apache.commons.vfs2.provider.http4.Http4FileSystemConfigBuilder;
-import org.apache.commons.vfs2.provider.http4s.Http4sFileProvider;
import org.junit.Assert;
import org.junit.Test;
import junit.framework.TestCase;
/**
- * Tests VFS-427 NPE on HttpFileObject.getContent().getContentInfo()
+ * Tests VFS-427 NPE on Http4FileObject.getContent().getContentInfo()
*/
public class Http4sGetContentInfoTest extends TestCase {
- // TODO: VFS-360 - Remove this manual registration of http4 once http4
becomes part of standard providers.
- @Override
- protected void setUp() throws Exception {
- final DefaultFileSystemManager manager = (DefaultFileSystemManager)
VFS.getManager();
- if (!manager.hasProvider("http4")) {
- manager.addProvider("http4", new Http4FileProvider());
- }
- if (!manager.hasProvider("http4s")) {
- manager.addProvider("http4s", new Http4sFileProvider());
- }
- }
-
/**
- * Tests VFS-427 NPE on HttpFileObject.getContent().getContentInfo().
+ * Tests VFS-427 NPE on Http4FileObject.getContent().getContentInfo().
*
* @throws FileSystemException thrown when the getContentInfo API fails.
* @throws MalformedURLException thrown when the System environment
contains an invalid URL for an HTTPS proxy.
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4FilesCacheTestCase.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5FilesCacheTestCase.java
similarity index 70%
copy from
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4FilesCacheTestCase.java
copy to
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5FilesCacheTestCase.java
index d2b62ee..f9a0a4b 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4FilesCacheTestCase.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5FilesCacheTestCase.java
@@ -14,14 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.vfs2.provider.http4.test;
+package org.apache.commons.vfs2.provider.http5.test;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.VFS;
-import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
-import org.apache.commons.vfs2.provider.http4.Http4FileProvider;
import org.junit.Assert;
import org.junit.Test;
@@ -30,25 +28,16 @@ import junit.framework.TestCase;
/**
* Tests https://issues.apache.org/jira/browse/VFS-426.
*/
-public class Http4FilesCacheTestCase extends TestCase {
-
- // TODO: VFS-360 - Remove this manual registration of http4 once http4
becomes part of standard providers.
- @Override
- protected void setUp() throws Exception {
- final DefaultFileSystemManager manager = (DefaultFileSystemManager)
VFS.getManager();
- if (!manager.hasProvider("http4")) {
- manager.addProvider("http4", new Http4FileProvider());
- }
- }
+public class Http5FilesCacheTestCase extends TestCase {
/**
* Tests https://issues.apache.org/jira/browse/VFS-426
*/
@Test
public void testQueryStringUrls() throws FileSystemException {
- final String noQueryStringUrl = "http4://commons.apache.org/vfs";
- final String queryStringUrl =
"http4://commons.apache.org/vfs?query=string";
- final String queryStringUrl2 =
"http4://commons.apache.org/vfs?query=string&more=stuff";
+ final String noQueryStringUrl = "http5://commons.apache.org/vfs";
+ final String queryStringUrl =
"http5://commons.apache.org/vfs?query=string";
+ final String queryStringUrl2 =
"http5://commons.apache.org/vfs?query=string&more=stuff";
final FileSystemManager fileSystemManager = VFS.getManager();
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5GetContentInfoTest.java
similarity index 65%
copy from
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
copy to
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5GetContentInfoTest.java
index 6f5e83a..905c301 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5GetContentInfoTest.java
@@ -14,43 +14,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.vfs2.provider.http4.test;
+package org.apache.commons.vfs2.provider.http5.test;
import org.apache.commons.vfs2.FileContent;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.VFS;
-import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
-import org.apache.commons.vfs2.provider.http4.Http4FileProvider;
import org.junit.Assert;
import org.junit.Test;
import junit.framework.TestCase;
/**
- * Tests VFS-427 NPE on Http4FileObject.getContent().getContentInfo().
+ * Tests VFS-427 NPE on Http5FileObject.getContent().getContentInfo().
*/
-public class Http4GetContentInfoTest extends TestCase {
-
- // TODO: VFS-360 - Remove this manual registration of http4 once http4
becomes part of standard providers.
- @Override
- protected void setUp() throws Exception {
- final DefaultFileSystemManager manager = (DefaultFileSystemManager)
VFS.getManager();
- if (!manager.hasProvider("http4")) {
- manager.addProvider("http4", new Http4FileProvider());
- }
- }
+public class Http5GetContentInfoTest extends TestCase {
/**
- * Tests VFS-427 NPE on Http4FileObject.getContent().getContentInfo().
+ * Tests VFS-427 NPE on Http5FileObject.getContent().getContentInfo().
*
* @throws FileSystemException thrown when the getContentInfo API fails.
*/
@Test
public void testGetContentInfo() throws FileSystemException {
final FileSystemManager fsManager = VFS.getManager();
- final FileObject fo =
fsManager.resolveFile("http4://www.apache.org/licenses/LICENSE-2.0.txt");
+ final FileObject fo =
fsManager.resolveFile("http5://www.apache.org/licenses/LICENSE-2.0.txt");
final FileContent content = fo.getContent();
Assert.assertNotNull(content);
// Used to NPE before fix:
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4ProviderTestCase.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5ProviderTestCase.java
similarity index 84%
copy from
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4ProviderTestCase.java
copy to
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5ProviderTestCase.java
index c49e90c..4ef7673 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4ProviderTestCase.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5ProviderTestCase.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.vfs2.provider.http4.test;
+package org.apache.commons.vfs2.provider.http5.test;
import java.io.File;
import java.io.IOException;
@@ -27,8 +27,8 @@ import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.VFS;
import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
-import org.apache.commons.vfs2.provider.http4.Http4FileProvider;
-import org.apache.commons.vfs2.provider.http4.Http4FileSystemConfigBuilder;
+import org.apache.commons.vfs2.provider.http5.Http5FileProvider;
+import org.apache.commons.vfs2.provider.http5.Http5FileSystemConfigBuilder;
import org.apache.commons.vfs2.test.AbstractProviderTestConfig;
import org.apache.commons.vfs2.test.ProviderTestSuite;
import org.apache.commons.vfs2.util.FreeSocketPortUtil;
@@ -38,10 +38,10 @@ import org.junit.Assert;
import junit.framework.Test;
/**
- * Test cases for the HTTP4 provider.
+ * Test cases for the HTTP5 provider.
*
*/
-public class Http4ProviderTestCase extends AbstractProviderTestConfig {
+public class Http5ProviderTestCase extends AbstractProviderTestConfig {
private static NHttpFileServer Server;
@@ -74,14 +74,14 @@ public class Http4ProviderTestCase extends
AbstractProviderTestConfig {
* @throws Exception Thrown when the suite cannot be constructed.
*/
public static Test suite() throws Exception {
- return new ProviderTestSuite(new Http4ProviderTestCase()) {
+ return new ProviderTestSuite(new Http5ProviderTestCase()) {
/**
* Adds base tests - excludes the nested test cases.
*/
@Override
protected void addBaseTests() throws Exception {
super.addBaseTests();
- addTests(Http4ProviderTestCase.class);
+ addTests(Http5ProviderTestCase.class);
}
@Override
@@ -116,10 +116,10 @@ public class Http4ProviderTestCase extends
AbstractProviderTestConfig {
*
* @throws IOException Thrown if a free local socket port cannot be found.
*/
- public Http4ProviderTestCase() throws IOException {
+ public Http5ProviderTestCase() throws IOException {
SocketPort = FreeSocketPortUtil.findFreeLocalPort();
// Use %40 for @ in a URL
- ConnectionUri = "http4://localhost:" + SocketPort;
+ ConnectionUri = "http5://localhost:" + SocketPort;
}
private void checkReadTestsFolder(final FileObject file) throws
FileSystemException {
@@ -127,15 +127,6 @@ public class Http4ProviderTestCase extends
AbstractProviderTestConfig {
Assert.assertTrue(file.getChildren().length > 0);
}
- // TODO: VFS-360 - Remove this manual registration of http4 once http4
becomes part of standard providers.
- @Override
- protected void setUp() throws Exception {
- final DefaultFileSystemManager manager = (DefaultFileSystemManager)
VFS.getManager();
- if (!manager.hasProvider("http4")) {
- manager.addProvider("http4", new Http4FileProvider());
- }
- }
-
/**
* Returns the base folder for tests.
*/
@@ -153,15 +144,15 @@ public class Http4ProviderTestCase extends
AbstractProviderTestConfig {
*/
@Override
public void prepare(final DefaultFileSystemManager manager) throws
Exception {
- if (!manager.hasProvider("http4")) {
- manager.addProvider("http4", new Http4FileProvider());
+ if (!manager.hasProvider("http5")) {
+ manager.addProvider("http5", new Http5FileProvider());
}
}
private void testResloveFolderSlash(final String uri, final boolean
followRedirect) throws FileSystemException {
VFS.getManager().getFilesCache().close();
final FileSystemOptions opts = new FileSystemOptions();
- Http4FileSystemConfigBuilder.getInstance().setFollowRedirect(opts,
followRedirect);
+ Http5FileSystemConfigBuilder.getInstance().setFollowRedirect(opts,
followRedirect);
final FileObject file = VFS.getManager().resolveFile(uri, opts);
try {
checkReadTestsFolder(file);
@@ -189,14 +180,14 @@ public class Http4ProviderTestCase extends
AbstractProviderTestConfig {
// Test no longer passing 2016/04/28
public void ignoreTestHttp405() throws FileSystemException {
final FileObject fileObject = VFS.getManager()
-
.resolveFile("http4://www.w3schools.com/webservices/tempconvert.asmx?action=WSDL");
+
.resolveFile("http5://www.w3schools.com/webservices/tempconvert.asmx?action=WSDL");
assert !fileObject.getContent().isEmpty();
}
/** Ensure VFS-453 options are present. */
public void testHttpTimeoutConfig() throws FileSystemException {
final FileSystemOptions opts = new FileSystemOptions();
- final Http4FileSystemConfigBuilder builder =
Http4FileSystemConfigBuilder.getInstance();
+ final Http5FileSystemConfigBuilder builder =
Http5FileSystemConfigBuilder.getInstance();
// ensure defaults are 0
assertEquals(0, builder.getConnectionTimeout(opts));
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4s/test/Http4sGetContentInfoTest.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5s/test/Http5sGetContentInfoTest.java
similarity index 68%
copy from
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4s/test/Http4sGetContentInfoTest.java
copy to
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5s/test/Http5sGetContentInfoTest.java
index 6a4416b..19830ed 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4s/test/Http4sGetContentInfoTest.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5s/test/Http5sGetContentInfoTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.vfs2.provider.http4s.test;
+package org.apache.commons.vfs2.provider.http5s.test;
import java.net.MalformedURLException;
import java.net.URL;
@@ -25,34 +25,19 @@ import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.VFS;
-import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
-import org.apache.commons.vfs2.provider.http4.Http4FileProvider;
-import org.apache.commons.vfs2.provider.http4.Http4FileSystemConfigBuilder;
-import org.apache.commons.vfs2.provider.http4s.Http4sFileProvider;
+import org.apache.commons.vfs2.provider.http5.Http5FileSystemConfigBuilder;
import org.junit.Assert;
import org.junit.Test;
import junit.framework.TestCase;
/**
- * Tests VFS-427 NPE on HttpFileObject.getContent().getContentInfo()
+ * Tests VFS-427 NPE on Http5FileObject.getContent().getContentInfo()
*/
-public class Http4sGetContentInfoTest extends TestCase {
-
- // TODO: VFS-360 - Remove this manual registration of http4 once http4
becomes part of standard providers.
- @Override
- protected void setUp() throws Exception {
- final DefaultFileSystemManager manager = (DefaultFileSystemManager)
VFS.getManager();
- if (!manager.hasProvider("http4")) {
- manager.addProvider("http4", new Http4FileProvider());
- }
- if (!manager.hasProvider("http4s")) {
- manager.addProvider("http4s", new Http4sFileProvider());
- }
- }
+public class Http5sGetContentInfoTest extends TestCase {
/**
- * Tests VFS-427 NPE on HttpFileObject.getContent().getContentInfo().
+ * Tests VFS-427 NPE on Http5FileObject.getContent().getContentInfo().
*
* @throws FileSystemException thrown when the getContentInfo API fails.
* @throws MalformedURLException thrown when the System environment
contains an invalid URL for an HTTPS proxy.
@@ -70,7 +55,7 @@ public class Http4sGetContentInfoTest extends TestCase {
final FileSystemOptions opts;
if (httpsProxyHost != null) {
opts = new FileSystemOptions();
- final Http4FileSystemConfigBuilder builder =
Http4FileSystemConfigBuilder.getInstance();
+ final Http5FileSystemConfigBuilder builder =
Http5FileSystemConfigBuilder.getInstance();
builder.setProxyHost(opts, httpsProxyHost);
if (httpsProxyPort >= 0) {
builder.setProxyPort(opts, httpsProxyPort);
@@ -80,7 +65,7 @@ public class Http4sGetContentInfoTest extends TestCase {
}
final FileSystemManager fsManager = VFS.getManager();
- final FileObject fo =
fsManager.resolveFile("http4://www.apache.org/licenses/LICENSE-2.0.txt", opts);
+ final FileObject fo =
fsManager.resolveFile("http5://www.apache.org/licenses/LICENSE-2.0.txt", opts);
final FileContent content = fo.getContent();
Assert.assertNotNull(content);
// Used to NPE before fix:
diff --git a/pom.xml b/pom.xml
index fc297ca..8524d1b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -468,6 +468,11 @@
<version>4.5.10</version>
</dependency>
<dependency>
+ <groupId>org.apache.httpcomponents.client5</groupId>
+ <artifactId>httpclient5</artifactId>
+ <version>5.0-beta6</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.19</version>