commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1364484 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/provider/http/ core/src/main/java/org/apache/commons/vfs2/provider/webdav/ core/src/test/java/org/apache/commons/vfs2/provider/http/test/ src/changes/
Date Mon, 23 Jul 2012 03:27:33 GMT
Author: ggregory
Date: Mon Jul 23 03:27:32 2012
New Revision: 1364484

URL: http://svn.apache.org/viewvc?rev=1364484&view=rev
Log:
[VFS-432][HTTP][WebDAV] Allow HTTP follow redirect.

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileSystemConfigBuilder.java
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java?rev=1364484&r1=1364483&r2=1364484&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java
Mon Jul 23 03:27:32 2012
@@ -31,6 +31,7 @@ import org.apache.commons.httpclient.uti
 import org.apache.commons.vfs2.FileContentInfoFactory;
 import org.apache.commons.vfs2.FileNotFoundException;
 import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileSystemOptions;
 import org.apache.commons.vfs2.FileType;
 import org.apache.commons.vfs2.RandomAccessContent;
 import org.apache.commons.vfs2.provider.AbstractFileName;
@@ -47,12 +48,20 @@ import org.apache.commons.vfs2.util.Rand
 public class HttpFileObject extends AbstractFileObject<HttpFileSystem>
 {
     private final String urlCharset;
+    private final boolean followRedirect;
     private HeadMethod method;
 
     protected HttpFileObject(final AbstractFileName name, final HttpFileSystem fileSystem)
     {
+        this(name, fileSystem, HttpFileSystemConfigBuilder.getInstance());
+    }
+
+    protected HttpFileObject(final AbstractFileName name, final HttpFileSystem fileSystem,
final HttpFileSystemConfigBuilder builder)
+    {
         super(name, fileSystem);
-        urlCharset = HttpFileSystemConfigBuilder.getInstance().getUrlCharset(getFileSystem().getFileSystemOptions());
+        final FileSystemOptions fileSystemOptions = fileSystem.getFileSystemOptions();
+        urlCharset = builder.getUrlCharset(fileSystemOptions);
+        followRedirect = builder.getFollowRedirect(fileSystemOptions);
     }
 
     /**
@@ -162,14 +171,15 @@ public class HttpFileObject extends Abst
     }
 
     /**
-     * Prepares a Method object.
+     * Prepares a HttpMethod object.
+     * 
      * @since 2.0 (was package)
      */
     protected void setupMethod(final HttpMethod method) throws FileSystemException, URIException
     {
         String pathEncoded = ((URLFileName) getName()).getPathQueryEncoded(urlCharset);
         method.setPath(pathEncoded);
-        method.setFollowRedirects(true);
+        method.setFollowRedirects(this.getFollowRedirect());
         method.setRequestHeader("User-Agent", "Jakarta-Commons-VFS");
     }
 
@@ -210,6 +220,11 @@ public class HttpFileObject extends Abst
         return new HttpFileContentInfoFactory();
     }
 
+    protected boolean getFollowRedirect()
+    {
+        return followRedirect;
+    }
+
     HeadMethod getHeadMethod() throws IOException
     {
         if (method != null) {

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java?rev=1364484&r1=1364483&r2=1364484&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystemConfigBuilder.java
Mon Jul 23 03:27:32 2012
@@ -34,7 +34,11 @@ public class HttpFileSystemConfigBuilder
 
     private static final int DEFAULT_MAX_CONNECTIONS = 50;
 
-    private static final String OPTION_NAME_PREEMPTIVE_AUTHENTICATION = "preemptiveAuth";
+    private static final boolean DEFAULT_FOLLOW_REDIRECT = true;
+
+    private static final String KEY_PREEMPTIVE_AUTHENTICATION = "preemptiveAuth";
+
+    protected static final String KEY_FOLLOW_REDIRECT = "followRedirect";
 
     /** @since 2.0 */
     protected HttpFileSystemConfigBuilder(String prefix)
@@ -162,6 +166,21 @@ public class HttpFileSystemConfigBuilder
     }
 
     /**
+     * Sets whether to follow redirects for the connection.
+     * 
+     * @param opts
+     *            The FileSystem options.
+     * @param redirect
+     *            {@code true} to follow redirects, {@code false} not to.
+     * @see #setFollowRedirect
+     * @since 2.1
+     */
+    public void setFollowRedirect(FileSystemOptions opts, boolean redirect)
+    {
+        setParam(opts, KEY_FOLLOW_REDIRECT, redirect);
+    }
+
+    /**
      * The cookies to add to the request.
      * @param opts The FileSystem options.
      * @return the Cookie array.
@@ -172,6 +191,20 @@ public class HttpFileSystemConfigBuilder
     }
 
     /**
+     * Gets whether to follow redirects for the connection.
+     * 
+     * @param opts
+     *            The FileSystem options.
+     * @return {@code true} to follow redirects, {@code false} not to.
+     * @see #setFollowRedirect
+     * @since 2.1
+     */
+    public boolean getFollowRedirect(FileSystemOptions opts)
+    {
+        return getBoolean(opts, KEY_FOLLOW_REDIRECT, DEFAULT_FOLLOW_REDIRECT);
+    }
+
+    /**
      * The maximum number of connections allowed.
      * @param opts The FileSystem options.
      * @param maxTotalConnections The maximum number of connections.
@@ -224,7 +257,7 @@ public class HttpFileSystemConfigBuilder
      */
     public boolean isPreemptiveAuth(FileSystemOptions opts)
     {
-        return getBoolean(opts, OPTION_NAME_PREEMPTIVE_AUTHENTICATION, Boolean.FALSE).booleanValue();
+        return getBoolean(opts, KEY_PREEMPTIVE_AUTHENTICATION, Boolean.FALSE).booleanValue();
     }
 
     /**
@@ -238,7 +271,7 @@ public class HttpFileSystemConfigBuilder
      */
     public void setPreemptiveAuth(FileSystemOptions opts, boolean preemptiveAuth)
     {
-        setParam(opts, OPTION_NAME_PREEMPTIVE_AUTHENTICATION, Boolean.valueOf(preemptiveAuth));
+        setParam(opts, KEY_PREEMPTIVE_AUTHENTICATION, Boolean.valueOf(preemptiveAuth));
     }
 
     @Override

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java?rev=1364484&r1=1364483&r2=1364484&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java
Mon Jul 23 03:27:32 2012
@@ -39,6 +39,7 @@ import org.apache.commons.vfs2.FileNotFo
 import org.apache.commons.vfs2.FileNotFoundException;
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileSystemOptions;
 import org.apache.commons.vfs2.FileType;
 import org.apache.commons.vfs2.NameScope;
 import org.apache.commons.vfs2.provider.AbstractFileName;
@@ -91,10 +92,11 @@ public class WebdavFileObject extends Ht
 
     protected WebdavFileObject(final AbstractFileName name, final WebdavFileSystem fileSystem)
     {
-        super(name, fileSystem);
+        super(name, fileSystem, WebdavFileSystemConfigBuilder.getInstance());
         this.fileSystem = fileSystem;
         builder = (WebdavFileSystemConfigBuilder) WebdavFileSystemConfigBuilder.getInstance();
-        this.urlCharset = builder.getUrlCharset(getFileSystem().getFileSystemOptions());
+        final FileSystemOptions fileSystemOptions = fileSystem.getFileSystemOptions();
+        this.urlCharset = builder.getUrlCharset(fileSystemOptions);
     }
 
     protected void configureMethod(HttpMethodBase httpMethod)
@@ -394,8 +396,7 @@ public class WebdavFileObject extends Ht
     {
         String pathEncoded = ((URLFileName) getName()).getPathQueryEncoded(urlCharset);
         method.setPath(pathEncoded);
-        // All the WebDav methods are EntityEnclosingMethods and are not allowed to redirect.
-        method.setFollowRedirects(false);
+        method.setFollowRedirects(this.getFollowRedirect());
         method.setRequestHeader("User-Agent", "Jakarta-Commons-VFS");
         method.addRequestHeader("Cache-control", "no-cache");
         method.addRequestHeader("Cache-store", "no-store");

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileSystemConfigBuilder.java?rev=1364484&r1=1364483&r2=1364484&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileSystemConfigBuilder.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileSystemConfigBuilder.java
Mon Jul 23 03:27:32 2012
@@ -28,6 +28,8 @@ import org.apache.commons.vfs2.provider.
 public final class WebdavFileSystemConfigBuilder extends HttpFileSystemConfigBuilder
 {
     private static final WebdavFileSystemConfigBuilder BUILDER = new WebdavFileSystemConfigBuilder();
+    
+    private static final boolean DEFAULT_FOLLOW_REDIRECT = false;
 
     private WebdavFileSystemConfigBuilder()
     {
@@ -65,6 +67,20 @@ public final class WebdavFileSystemConfi
     }
 
     /**
+     * Gets whether to follow redirects for the connection.
+     * 
+     * @param opts
+     *            The FileSystem options.
+     * @return {@code true} to follow redirects, {@code false} not to.
+     * @see #setFollowRedirect
+     * @since 2.1
+     */
+    public boolean getFollowRedirect(FileSystemOptions opts)
+    {
+        return getBoolean(opts, KEY_FOLLOW_REDIRECT, DEFAULT_FOLLOW_REDIRECT);
+    }
+
+    /**
      * Whether to use versioning.
      * @param opts The FileSystem options.
      * @param versioning true if versioning should be enabled.

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java?rev=1364484&r1=1364483&r2=1364484&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java
Mon Jul 23 03:27:32 2012
@@ -22,13 +22,15 @@ import java.io.IOException;
 import junit.framework.Assert;
 import junit.framework.Test;
 
-import org.apache.commons.vfs2.FileContent;
+import org.apache.commons.vfs2.FileNotFolderException;
 import org.apache.commons.vfs2.FileObject;
 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.http.HttpFileProvider;
+import org.apache.commons.vfs2.provider.http.HttpFileSystemConfigBuilder;
 import org.apache.commons.vfs2.test.AbstractProviderTestConfig;
 import org.apache.commons.vfs2.test.ProviderTestSuite;
 import org.apache.commons.vfs2.util.FreeSocketPortUtil;
@@ -81,6 +83,16 @@ public class HttpProviderTestCase extend
     {
         return new ProviderTestSuite(new HttpProviderTestCase())
         {
+            /**
+             * Adds base tests - excludes the nested test cases.
+             */
+            @Override
+            protected void addBaseTests() throws Exception
+            {
+                super.addBaseTests();
+                addTests(HttpProviderTestCase.class);
+            }
+
             @Override
             protected void setUp() throws Exception
             {
@@ -126,6 +138,12 @@ public class HttpProviderTestCase extend
         ConnectionUri = "http://localhost:" + SocketPort;
     }
 
+    private void checkReadTestsFolder(final FileObject file) throws FileSystemException
+    {
+        Assert.assertNotNull(file.getChildren());
+        Assert.assertTrue(file.getChildren().length > 0);
+    }
+
     /**
      * Returns the base folder for tests.
      */
@@ -149,17 +167,38 @@ public class HttpProviderTestCase extend
         manager.addProvider("http", new HttpFileProvider());
     }
 
-    public void testGetContent() throws FileSystemException
+    private void testResloveFolderSlash(String uri, boolean followRedirect) throws FileSystemException
+    {
+        VFS.getManager().getFilesCache().close();
+        final FileSystemOptions opts = new FileSystemOptions();
+        HttpFileSystemConfigBuilder.getInstance().setFollowRedirect(opts, followRedirect);
+        final FileObject file = VFS.getManager().resolveFile(uri, opts);
+        try
+        {
+            checkReadTestsFolder(file);
+        } catch (FileNotFolderException e)
+        {
+            // Expected: VFS HTTP does not support listing children yet.
+        }
+    }
+
+    public void testResloveFolderSlashNoRedirectOff() throws FileSystemException
+    {
+        testResloveFolderSlash(ConnectionUri + "/read-tests", false);
+    }
+
+    public void testResloveFolderSlashNoRedirectOn() throws FileSystemException
+    {
+        testResloveFolderSlash(ConnectionUri + "/read-tests", true);
+    }
+
+    public void testResloveFolderSlashYesRedirectOff() throws FileSystemException
     {
-        final FileObject file = VFS.getManager().resolveFile(ConnectionUri + "/read-tests/file1.txt");
-        Assert.assertNotNull(file.getContent());
+        testResloveFolderSlash(ConnectionUri + "/read-tests/", false);
     }
 
-    public void testGetContentInfo() throws FileSystemException
+    public void testResloveFolderSlashYesRedirectOn() throws FileSystemException
     {
-        final FileObject file = VFS.getManager().resolveFile(ConnectionUri + "/read-tests/file1.txt");
-        final FileContent content = file.getContent();
-        Assert.assertNotNull(content);
-        Assert.assertNotNull(content.getContentInfo());
+        testResloveFolderSlash(ConnectionUri + "/read-tests/", true);
     }
 }

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1364484&r1=1364483&r2=1364484&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Mon Jul 23 03:27:32 2012
@@ -23,10 +23,13 @@
 
   <body>
     <release version="2.1" date="TBD" description="New features and bug fix release.">
-      <action issue="VFS-431" dev="ggregory" type="add" due-to="awelynant">
+      <action issue="VFS-432" dev="ggregory" type="add" due-to="ggregory">
+        [HTTP][WebDAV] Allow HTTP follow redirect.
+      </action>
+      <action issue="VFS-431" dev="ggregory" type="add" due-to="ggregory">
         FileSystemOption does not implement toString().
       </action>
-      <action issue="VFS-429" dev="ggregory" type="add" due-to="awelynant">
+      <action issue="VFS-429" dev="ggregory" type="add" due-to="ggregory">
         Remove extra FileSystem ivar in AbstractFileObject subclasses with generics.
       </action>
       <action issue="VFS-427" dev="ggregory" type="add" due-to="awelynant">



Mime
View raw message