Browse Source

HDFS-4944. WebHDFS cannot create a file path containing characters that must be URI-encoded, such as space. Contributed by Chris Nauroth.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1@1498059 13f79535-47bb-0310-9956-ffa450edef68
Chris Nauroth 12 years ago
parent
commit
6125ee19e7

+ 3 - 0
CHANGES.txt

@@ -65,6 +65,9 @@ Release 1.3.0 - unreleased
     HADOOP-7140. IPC Reader threads do not stop when server stops
     (Todd Lipcon, backported by ivanmi)
 
+    HDFS-4944. WebHDFS cannot create a file path containing characters that must
+    be URI-encoded, such as space. (cnauroth)
+
 Release 1.2.1 - Unreleased 
 
   INCOMPATIBLE CHANGES

+ 2 - 1
src/hdfs/org/apache/hadoop/hdfs/server/datanode/web/resources/DatanodeWebHdfsMethods.java

@@ -193,7 +193,8 @@ public class DatanodeWebHdfsMethods {
         IOUtils.cleanup(LOG, dfsclient);
       }
       final String nnAddr = NameNode.getInfoServer(conf);
-      final URI uri = new URI(WebHdfsFileSystem.SCHEME + "://" + nnAddr + fullpath);
+      final URI uri = new URI(WebHdfsFileSystem.SCHEME, nnAddr, fullpath, null,
+        null);
       return Response.created(uri).type(MediaType.APPLICATION_OCTET_STREAM).build();
     }
     default:

+ 29 - 0
src/test/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java

@@ -380,5 +380,34 @@ public class TestWebHdfsFileSystemContract extends FileSystemContractBaseTest {
       }
       conn.disconnect();
     }
+
+    {//test create with path containing spaces
+      HttpOpParam.Op op = PutOpParam.Op.CREATE;
+      Path path = new Path("/test/path%20with%20spaces");
+      URL url = webhdfs.toUrl(op, path);
+      HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+      conn.setRequestMethod(op.getType().toString());
+      conn.setDoOutput(false);
+      conn.setInstanceFollowRedirects(false);
+      final String redirect;
+      try {
+        conn.connect();
+        assertEquals(HttpServletResponse.SC_TEMPORARY_REDIRECT,
+          conn.getResponseCode());
+        redirect = conn.getHeaderField("Location");
+      } finally {
+        conn.disconnect();
+      }
+
+      conn = (HttpURLConnection)new URL(redirect).openConnection();
+      conn.setRequestMethod(op.getType().toString());
+      conn.setDoOutput(op.getDoOutput());
+      try {
+        conn.connect();
+        assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode());
+      } finally {
+        conn.disconnect();
+      }
+    }
   }
 }