commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1845662 - in /commons/proper/vfs/trunk: commons-vfs2-examples/ commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/ commons-vfs2-examples/src/main/resources/ commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/ commons-...
Date Sat, 03 Nov 2018 14:38:05 GMT
Author: ggregory
Date: Sat Nov  3 14:38:04 2018
New Revision: 1845662

URL: http://svn.apache.org/viewvc?rev=1845662&view=rev
Log:
[VFS-360] Migrate to HttpComponent HttpClient. This patch is from Woonsan Ko (woonsan on GitHub)
Switching http(N)/s providers easily for default http/s schemes. Closes #40. Improvements:
Set HttpClient v3 based providers to both schemes http/s and http3/s. So, we can use it through
http3/s as well.
Set default http/s scheme in HttpClient v3 provider.
Improved Shell to easily switch providers.xml configuration through system property. e.g,
mvn -Pshell -Dhttp3 -Dhttp4 -Dproviders=providers-http4-default.xml, with an example setting
http4/s as default http/s in commons-vfs2-examples/.
See commons-vfs2-examples/README.md for detail.
Add pwfs command to print the current working file system, next to pwd, which is useful when
verifying which http(N) provider is being really used for http/s scheme for example.

Added:
    commons/proper/vfs/trunk/commons-vfs2-examples/src/main/resources/
    commons/proper/vfs/trunk/commons-vfs2-examples/src/main/resources/providers-http4-default.xml
Modified:
    commons/proper/vfs/trunk/commons-vfs2-examples/README.md
    commons/proper/vfs/trunk/commons-vfs2-examples/pom.xml
    commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
    commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/providers.xml
    commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileProvider.java

Modified: commons/proper/vfs/trunk/commons-vfs2-examples/README.md
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-examples/README.md?rev=1845662&r1=1845661&r2=1845662&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2-examples/README.md (original)
+++ commons/proper/vfs/trunk/commons-vfs2-examples/README.md Sat Nov  3 14:38:04 2018
@@ -21,15 +21,67 @@
 
     mvn clean install
 
-## Test `http` and `https` providers
+## Test `http3` and `http3s` providers
 
-    mvn -Pshell -Dhttp
+    mvn -Pshell -Dhttp3
 
 ## Test `http4` and `http4s` providers
 
     mvn -Pshell -Dhttp4
 
-## Test `http`, `https`, `http4` and `http4s` providers together
+## Test `http3`, `http3s`, `http4` and `http4s` providers together
 
-    mvn -Pshell -Dhttp -Dhttp4
+    mvn -Pshell -Dhttp3 -Dhttp4
 
+## Example Test Scenario
+
+    mvn -Pshell -Dhttp3 -Dhttp4
+    ...
+    cd http3://repo1.maven.org/maven2/org/apache/commons/commons-vfs2/
+    ...
+    cat maven-metadata.xml
+    ...
+    cd http3s://repo1.maven.org/maven2/org/apache/commons/commons-vfs2/
+    ...
+    cat maven-metadata.xml
+    ...
+    cd http4://repo1.maven.org/maven2/org/apache/commons/commons-vfs2/
+    ...
+    cat maven-metadata.xml
+    ...
+    cd http4s://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
+    ...
+    cd https://repo1.maven.org/maven2/org/apache/commons/commons-vfs2/
+    ...
+    cat maven-metadata.xml
+    ...
+    pwd
+    > Current folder is https://repo1.maven.org/maven2/org/apache/commons/commons-vfs2
+    pwfs
+    > FileSystem of current folder is org.apache.commons.vfs2.provider.http.HttpFileSystem@668be11a
(root: https://repo1.maven.org/)
+    ...
+    quit
+    
+
+
+## Test with custom providers configuration
+
+Set `-Dproviders=<custom_providers.xml_resource_name>`.
+
+    mvn -Pshell -Dhttp3 -Dhttp4 -Dproviders=providers-http4-default.xml
+    ...
+    Custom providers configuration used: file:/tmp/commons-vfs/commons-vfs2-examples/target/classes/providers-http4-default.xml
+    VFS Shell null
+    cd http://repo1.maven.org/maven2/org/apache/commons/commons-vfs2/
+    > Current folder is http://repo1.maven.org/maven2/org/apache/commons/commons-vfs2
+    pwd
+    > Current folder is http://repo1.maven.org/maven2/org/apache/commons/commons-vfs2
+    pwfs
+    > FileSystem of current folder is org.apache.commons.vfs2.provider.http4.Http4FileSystem@6e012f9b
(root: http://repo1.maven.org/)
+    ...

Modified: commons/proper/vfs/trunk/commons-vfs2-examples/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-examples/pom.xml?rev=1845662&r1=1845661&r2=1845662&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2-examples/pom.xml (original)
+++ commons/proper/vfs/trunk/commons-vfs2-examples/pom.xml Sat Nov  3 14:38:04 2018
@@ -64,6 +64,9 @@
   <build>
     <resources>
       <resource>
+        <directory>src/main/resources</directory>
+      </resource>
+      <resource>
         <directory>${vfs.parent.dir}</directory>
         <targetPath>META-INF</targetPath>
         <includes>
@@ -102,11 +105,11 @@
     </profile>
 
     <profile>
-      <id>with-http</id>
+      <id>with-http3</id>
       <activation>
         <activeByDefault>true</activeByDefault>
         <property>
-          <name>http</name>
+          <name>http3</name>
         </property>
       </activation>
       <dependencies>

Modified: commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java?rev=1845662&r1=1845661&r2=1845662&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
Sat Nov  3 14:38:04 2018
@@ -20,6 +20,7 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.net.URL;
 import java.nio.charset.Charset;
 import java.text.DateFormat;
 import java.util.ArrayList;
@@ -39,6 +40,7 @@ import org.apache.commons.vfs2.FileUtil;
 import org.apache.commons.vfs2.Selectors;
 import org.apache.commons.vfs2.VFS;
 import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
+import org.apache.commons.vfs2.impl.StandardFileSystemManager;
 import org.apache.commons.vfs2.operations.FileOperationProvider;
 import org.apache.commons.vfs2.provider.FileProvider;
 
@@ -54,7 +56,17 @@ public final class Shell {
     private final BufferedReader reader;
 
     private Shell() throws IOException {
-        mgr = VFS.getManager();
+        final String providers = System.getProperty("providers");
+        final URL providersUrl = (providers != null) ? Shell.class.getResource("/" + providers)
: null;
+
+        if (providersUrl != null) {
+            mgr = new StandardFileSystemManager();
+            System.out.println("Custom providers configuration used: " + providersUrl);
+            ((StandardFileSystemManager) mgr).setConfiguration(providersUrl);
+            ((StandardFileSystemManager) mgr).init();
+        } else {
+            mgr = VFS.getManager();
+        }
 
         // TODO: VFS-360 - Remove this manual registration of http4 once http4 becomes part
of standard providers.
         boolean httpClient4Available = false;
@@ -126,6 +138,8 @@ public final class Shell {
             ls(cmd);
         } else if (cmdName.equalsIgnoreCase("pwd")) {
             pwd();
+        } else if (cmdName.equalsIgnoreCase("pwfs")) {
+            pwfs();
         } else if (cmdName.equalsIgnoreCase("rm")) {
             rm(cmd);
         } else if (cmdName.equalsIgnoreCase("touch")) {
@@ -191,6 +205,7 @@ public final class Shell {
         System.out.println("info [scheme]      Displays information about providers.");
         System.out.println("ls [-R] [path]     Lists contents of a file or folder.");
         System.out.println("pwd                Displays current folder.");
+        System.out.println("pwfs               Displays current file system.");
         System.out.println("rm <path>          Deletes a file or folder.");
         System.out.println("touch <path>       Sets the last-modified time of a file.");
         System.out.println("exit, quit         Exits this program.");
@@ -249,6 +264,14 @@ public final class Shell {
     }
 
     /**
+     * Does a 'pwfs' command.
+     */
+    private void pwfs() {
+        System.out.println("FileSystem of current folder is " + cwd.getFileSystem() + " (root:
"
+                + cwd.getFileSystem().getRootURI() + ")");
+    }
+
+    /**
      * Does a 'cd' command. If the taget directory does not exist, a message is printed to
<code>System.err</code>.
      */
     private void cd(final String[] cmd) throws Exception {

Added: commons/proper/vfs/trunk/commons-vfs2-examples/src/main/resources/providers-http4-default.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-examples/src/main/resources/providers-http4-default.xml?rev=1845662&view=auto
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2-examples/src/main/resources/providers-http4-default.xml
(added)
+++ commons/proper/vfs/trunk/commons-vfs2-examples/src/main/resources/providers-http4-default.xml
Sat Nov  3 14:38:04 2018
@@ -0,0 +1,131 @@
+<!--
+    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.
+-->
+<providers>
+    <default-provider class-name="org.apache.commons.vfs2.provider.url.UrlFileProvider">
+    </default-provider>
+    <provider class-name="org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider">
+        <scheme name="file"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.zip.ZipFileProvider">
+        <scheme name="zip"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.tar.TarFileProvider">
+        <scheme name="tar"/>
+        <if-available class-name="org.apache.commons.compress.archivers.tar.TarArchiveOutputStream"/>
+    </provider>
+
+    <provider class-name="org.apache.commons.vfs2.provider.bzip2.Bzip2FileProvider">
+        <scheme name="bz2"/>
+        <if-available class-name="org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.gzip.GzipFileProvider">
+        <scheme name="gz"/>
+    </provider>
+
+    <provider class-name="org.apache.commons.vfs2.provider.jar.JarFileProvider">
+        <scheme name="jar"/>
+        <scheme name="sar"/>
+        <scheme name="ear"/>
+        <scheme name="par"/>
+        <scheme name="ejb3"/>
+        <scheme name="war"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.temp.TemporaryFileProvider">
+        <scheme name="tmp"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.ftp.FtpFileProvider">
+        <scheme name="ftp"/>
+        <if-available class-name="org.apache.commons.net.ftp.FTPFile"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.ftps.FtpsFileProvider">
+        <scheme name="ftps"/>
+        <if-available class-name="org.apache.commons.net.ftp.FTPFile"/>
+    </provider>
+
+    <!-- The default http/https providers based on HttpClient v3 -->
+    <provider class-name="org.apache.commons.vfs2.provider.http.HttpFileProvider">
+        <scheme name="http3"/>
+        <if-available class-name="org.apache.commons.httpclient.HttpClient"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.https.HttpsFileProvider">
+        <scheme name="http3s"/>
+        <if-available class-name="org.apache.commons.httpclient.HttpClient"/>
+    </provider>
+
+    <!-- http4/http4s providers based on HttpClient v4 -->
+    <provider class-name="org.apache.commons.vfs2.provider.http4.Http4FileProvider">
+        <scheme name="http"/>
+        <scheme name="http4"/>
+        <if-available class-name="org.apache.http.client.HttpClient"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.http4s.Http4sFileProvider">
+        <scheme name="https"/>
+        <scheme name="http4s"/>
+        <if-available class-name="org.apache.http.client.HttpClient"/>
+    </provider>
+
+    <provider class-name="org.apache.commons.vfs2.provider.sftp.SftpFileProvider">
+        <scheme name="sftp"/>
+        <if-available class-name="javax.crypto.Cipher"/>
+        <if-available class-name="com.jcraft.jsch.JSch"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.res.ResourceFileProvider">
+        <scheme name="res"/>
+    </provider>
+        <provider class-name="org.apache.commons.vfs2.provider.webdav.WebdavFileProvider">
+        <scheme name="webdav"/>
+        <if-available class-name="org.apache.commons.httpclient.HttpClient"/>
+        <if-available class-name="org.apache.jackrabbit.webdav.client.methods.DavMethod"/>
+    </provider>
+
+    <provider class-name="org.apache.commons.vfs2.provider.tar.TarFileProvider">
+        <scheme name="tgz"/>
+        <if-available scheme="gz"/>
+        <if-available scheme="tar"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.tar.TarFileProvider">
+        <scheme name="tbz2"/>
+        <if-available scheme="bz2"/>
+        <if-available scheme="tar"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.ram.RamFileProvider">
+        <scheme name="ram"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.hdfs.HdfsFileProvider">
+        <scheme name="hdfs"/>
+        <if-available class-name="org.apache.hadoop.fs.FileSystem"/>
+    </provider>
+
+    <extension-map extension="zip" scheme="zip"/>
+    <extension-map extension="tar" scheme="tar"/>
+    <mime-type-map mime-type="application/zip" scheme="zip"/>
+    <mime-type-map mime-type="application/x-tar" scheme="tar"/>
+    <mime-type-map mime-type="application/x-gzip" scheme="gz"/>
+    <!--
+    <mime-type-map mime-type="application/x-tgz" scheme="tgz"/>
+    -->
+    <extension-map extension="jar" scheme="jar"/>
+    <extension-map extension="bz2" scheme="bz2"/>
+    <extension-map extension="gz" scheme="gz"/>
+    <!--
+    <extension-map extension="tgz" scheme="tgz"/>
+    <extension-map extension="tbz2" scheme="tbz2"/>
+    -->
+    <extension-map extension="tgz" scheme="tar"/>
+    <extension-map extension="tbz2" scheme="tar"/>
+
+</providers>

Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/providers.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/providers.xml?rev=1845662&r1=1845661&r2=1845662&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/providers.xml
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/providers.xml
Sat Nov  3 14:38:04 2018
@@ -55,14 +55,31 @@
         <scheme name="ftps"/>
         <if-available class-name="org.apache.commons.net.ftp.FTPFile"/>
     </provider>
+
+    <!-- The default http/https providers based on HttpClient v3 -->
     <provider class-name="org.apache.commons.vfs2.provider.http.HttpFileProvider">
         <scheme name="http"/>
+        <scheme name="http3"/>
         <if-available class-name="org.apache.commons.httpclient.HttpClient"/>
     </provider>
     <provider class-name="org.apache.commons.vfs2.provider.https.HttpsFileProvider">
         <scheme name="https"/>
+        <scheme name="http3s"/>
         <if-available class-name="org.apache.commons.httpclient.HttpClient"/>
     </provider>
+
+    <!-- http4/http4s providers based on HttpClient v4 -->
+    <!--
+    <provider class-name="org.apache.commons.vfs2.provider.http4.Http4FileProvider">
+        <scheme name="http4"/>
+        <if-available class-name="org.apache.http.client.HttpClient"/>
+    </provider>
+    <provider class-name="org.apache.commons.vfs2.provider.http4s.Http4sFileProvider">
+        <scheme name="http4s"/>
+        <if-available class-name="org.apache.http.client.HttpClient"/>
+    </provider>
+    -->
+
     <provider class-name="org.apache.commons.vfs2.provider.sftp.SftpFileProvider">
         <scheme name="sftp"/>
         <if-available class-name="javax.crypto.Cipher"/>

Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileProvider.java?rev=1845662&r1=1845661&r2=1845662&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileProvider.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileProvider.java
Sat Nov  3 14:38:04 2018
@@ -67,7 +67,11 @@ public class HttpFileProvider extends Ab
         try {
             authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES);
 
-            httpClient = HttpClientFactory.createConnection(rootName.getScheme(), rootName.getHostName(),
+            final String fileScheme = rootName.getScheme();
+            final char lastChar = fileScheme.charAt(fileScheme.length() - 1);
+            final String internalScheme = (lastChar == 's' || lastChar == 'S') ? "https"
: "http";
+
+            httpClient = HttpClientFactory.createConnection(internalScheme, rootName.getHostName(),
                     rootName.getPort(),
                     UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
                             UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName()))),



Mime
View raw message