You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2012/07/16 22:18:58 UTC

svn commit: r1362235 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/provider/http/ core/src/test/java/org/apache/commons/vfs2/provider/http/test/ core/src/test/java/org/apache/commons/vfs2/provider/https/ core/src/test/java/...

Author: ggregory
Date: Mon Jul 16 20:18:57 2012
New Revision: 1362235

URL: http://svn.apache.org/viewvc?rev=1362235&view=rev
Log:
[VFS-427][HTTP] NPE on HttpFileObject.getContent().getContentInfo().

Added:
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/GetContentInfoFunctionalTest.java   (with props)
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/https/
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/https/test/
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/https/test/GetContentInfoFunctionalTest.java   (with props)
Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java?rev=1362235&r1=1362234&r2=1362235&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java Mon Jul 16 20:18:57 2012
@@ -16,8 +16,11 @@
  */
 package org.apache.commons.vfs2.provider.http;
 
+import java.io.IOException;
+
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HeaderElement;
+import org.apache.commons.httpclient.methods.HeadMethod;
 import org.apache.commons.vfs2.FileContent;
 import org.apache.commons.vfs2.FileContentInfo;
 import org.apache.commons.vfs2.FileContentInfoFactory;
@@ -26,7 +29,7 @@ import org.apache.commons.vfs2.impl.Defa
 import org.apache.commons.vfs2.util.FileObjectUtils;
 
 /**
- * Creates the FileContentInfo.
+ * Creates FileContentInfo instances for HTTP.
  */
 public class HttpFileContentInfoFactory implements FileContentInfoFactory
 {
@@ -38,7 +41,15 @@ public class HttpFileContentInfoFactory 
         String contentType = null;
         String contentEncoding = null;
 
-        Header header = httpFile.getHeadMethod().getResponseHeader("content-type");
+        HeadMethod headMethod;
+        try
+        {
+            headMethod = httpFile.getHeadMethod();
+        } catch (IOException e)
+        {
+            throw new FileSystemException(e);
+        }
+        Header header = headMethod.getResponseHeader("content-type");
         if (header != null)
         {
             HeaderElement[] element = header.getElements();
@@ -48,7 +59,7 @@ public class HttpFileContentInfoFactory 
             }
         }
 
-        contentEncoding = httpFile.getHeadMethod().getResponseCharSet();
+        contentEncoding = headMethod.getResponseCharSet();
 
         return new DefaultFileContentInfo(contentType, contentEncoding);
     }

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=1362235&r1=1362234&r2=1362235&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 16 20:18:57 2012
@@ -74,11 +74,7 @@ public class HttpFileObject extends Abst
     protected FileType doGetType() throws Exception
     {
         // Use the HEAD method to probe the file.
-        method = new HeadMethod();
-        setupMethod(method);
-        final HttpClient client = fileSystem.getClient();
-        final int status = client.executeMethod(method);
-        method.releaseConnection();
+        final int status = this.getHeadMethod().getStatusCode();
         if (status == HttpURLConnection.HTTP_OK)
         {
             return FileType.FILE;
@@ -216,8 +212,16 @@ public class HttpFileObject extends Abst
         return new HttpFileContentInfoFactory();
     }
 
-    HeadMethod getHeadMethod()
+    HeadMethod getHeadMethod() throws IOException
     {
+        if (method != null) {
+            return method;
+        }
+        method = new HeadMethod();
+        setupMethod(method);
+        final HttpClient client = fileSystem.getClient();
+        client.executeMethod(method);
+        method.releaseConnection();
         return method;
     }
 

Added: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/GetContentInfoFunctionalTest.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/GetContentInfoFunctionalTest.java?rev=1362235&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/GetContentInfoFunctionalTest.java (added)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/GetContentInfoFunctionalTest.java Mon Jul 16 20:18:57 2012
@@ -0,0 +1,35 @@
+package org.apache.commons.vfs2.provider.http.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.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests VFS-427 NPE on HttpFileObject.getContent().getContentInfo()
+ * 
+ * @since 2.1
+ */
+public class GetContentInfoFunctionalTest
+{
+
+    /**
+     * Tests VFS-427 NPE on HttpFileObject.getContent().getContentInfo().
+     * 
+     * @throws FileSystemException
+     *             thrown when the getContentInfo API fails.
+     */
+    @Test
+    public void testGoogle() throws FileSystemException
+    {
+        final FileSystemManager fsManager = VFS.getManager();
+        final FileObject fo = fsManager.resolveFile("http://www.google.com/images/logos/ps_logo2.png");
+        final FileContent content = fo.getContent();
+        Assert.assertNotNull(content);
+        // Used to NPE before fix:
+        content.getContentInfo();
+    }
+}

Propchange: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/GetContentInfoFunctionalTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/GetContentInfoFunctionalTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/https/test/GetContentInfoFunctionalTest.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/https/test/GetContentInfoFunctionalTest.java?rev=1362235&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/https/test/GetContentInfoFunctionalTest.java (added)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/https/test/GetContentInfoFunctionalTest.java Mon Jul 16 20:18:57 2012
@@ -0,0 +1,35 @@
+package org.apache.commons.vfs2.provider.https.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.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests VFS-427 NPE on HttpFileObject.getContent().getContentInfo()
+ * 
+ * @since 2.1
+ */
+public class GetContentInfoFunctionalTest
+{
+
+    /**
+     * Tests VFS-427 NPE on HttpFileObject.getContent().getContentInfo().
+     * 
+     * @throws FileSystemException
+     *             thrown when the getContentInfo API fails.
+     */
+    @Test
+    public void testGoogle() throws FileSystemException
+    {
+        final FileSystemManager fsManager = VFS.getManager();
+        final FileObject fo = fsManager.resolveFile("https://www.google.com/images/logos/ps_logo2.png");
+        final FileContent content = fo.getContent();
+        Assert.assertNotNull(content);
+        // Used to NPE before fix:
+        content.getContentInfo();
+    }
+}

Propchange: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/https/test/GetContentInfoFunctionalTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/https/test/GetContentInfoFunctionalTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1362235&r1=1362234&r2=1362235&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Mon Jul 16 20:18:57 2012
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.1" date="TBD" description="New features and bug fix release.">
+      <action issue="VFS-427" dev="ggregory" type="add" due-to="awelynant">
+        [HTTP] NPE on HttpFileObject.getContent().getContentInfo().
+      </action>
       <action issue="VFS-405" dev="ggregory" type="add" due-to="dwaszak">
         Get/set the file permissions.
       </action>
@@ -108,7 +111,7 @@
         [RAM] Reading a RAM FileSystem file fails because it never returns EOF -1.
       </action>
       <action issue="VFS-404" dev="ggregory" type="update">
-        [FTP][FTPS] Update Apache Commons Net to 3.1 from 3.0.1
+        [FTP][FTPS] Update Apache Commons Net to 3.1 from 3.0.1.
       </action>
       <action issue="VFS-402" dev="ggregory" type="update">
         [WebDAV] Update Apache Jackrabbit 1.5.2 to 1.6.5.