harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r652135 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/org/apache/harmony/luni/internal/net/www/protocol/file/ test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/ test/api/common/org/apache/harmo...
Date Tue, 29 Apr 2008 21:18:34 GMT
Author: tellison
Date: Tue Apr 29 14:18:33 2008
New Revision: 652135

URL: http://svn.apache.org/viewvc?rev=652135&view=rev
Log:
Fix for HARMONY-5779 ([classlib][luni] java.io.FileNotFoundException Issue with file://localhost)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java?rev=652135&r1=652134&r2=652135&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
Tue Apr 29 14:18:33 2008
@@ -62,10 +62,6 @@
         if (fileName == null) {
             fileName = ""; //$NON-NLS-1$
         }
-        String host = url.getHost();
-        if (host != null && host.length() > 0) {
-            fileName = "//" + host + fileName; //$NON-NLS-1$
-        }
         fileName = Util.decode(fileName, false);
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java?rev=652135&r1=652134&r2=652135&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
Tue Apr 29 14:18:33 2008
@@ -41,8 +41,8 @@
      * 
      */
     @Override
-    public URLConnection openConnection(URL url) {
-        return new FileURLConnection(url);
+    public URLConnection openConnection(URL url) throws IOException {
+        return openConnection(url, null);
     }
 
     /**
@@ -58,18 +58,28 @@
      * @throws IOException
      *             if this handler fails to establish a connection.
      * @throws IllegalArgumentException
-     *             if any argument is null or of an invalid type.
+     *             if the url argument is null.
      * @throws UnsupportedOperationException
      *             if the protocol handler doesn't support this method.
      */
     @Override
     public URLConnection openConnection(URL url, Proxy proxy)
             throws IOException {
-        if (null == url || null == proxy) {
+        if (null == url) {
             // K034b=url and proxy can not be null
             throw new IllegalArgumentException(Msg.getString("K034b")); //$NON-NLS-1$
         }
-        return new FileURLConnection(url);
+
+        String host = url.getHost();
+        if (host == null || host.length() == 0
+                || host.equalsIgnoreCase("localhost")) { //$NON-NLS-1$
+            return new FileURLConnection(url);
+        }
+
+        // If a hostname is specified try to get the resource using FTP
+        URL ftpURL = new URL("ftp", host, url.getFile()); //$NON-NLS-1$
+        return (proxy == null) ? ftpURL.openConnection() : ftpURL
+                .openConnection(proxy);
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java?rev=652135&r1=652134&r2=652135&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java
Tue Apr 29 14:18:33 2008
@@ -55,5 +55,12 @@
         
         FileURLConnection conn = new FileURLConnection(anchorUrl);
         assertNotNull(conn.getInputStream());
+        
+        // Regression for Harmony-5779
+        String localURLString = "file://localhost/" + url.getFile();
+        URL localURL = new URL(localURLString);
+        conn = new FileURLConnection(localURL);
+        assertNotNull(conn.getInputStream());
+        assertEquals("file",conn.getURL().getProtocol());
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java?rev=652135&r1=652134&r2=652135&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
Tue Apr 29 14:18:33 2008
@@ -1113,6 +1113,23 @@
             System.setSecurityManager(null);
         }
     }
+    
+    /**
+     * @tests java.net.URL#openConnection()
+     */
+    public void test_openConnection_FileProtocal() throws Exception {
+        // Regression test for Harmony-5779
+        String basedir = new File("temp.java").getAbsolutePath();
+        String fileUrlString = "file://localhost/" + basedir;
+        URLConnection conn  = new URL(fileUrlString).openConnection();
+        assertEquals("file",conn.getURL().getProtocol());
+        assertEquals(new File(basedir),new File(conn.getURL().getFile()));
+
+        String nonLocalUrlString = "file://anything/" + basedir;
+        conn  = new URL(nonLocalUrlString).openConnection();
+        assertEquals("ftp",conn.getURL().getProtocol());
+        assertEquals(new File(basedir),new File(conn.getURL().getFile()));
+    }
 
     /**
      * URLStreamHandler implementation class necessary for tests.



Mime
View raw message