Просмотр исходного кода

HDFS-4943. WebHdfsFileSystem does not work when original file path has encoded chars. Contributed by Jerry He and Robert Parker.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1504296 13f79535-47bb-0310-9956-ffa450edef68
Kihwal Lee 12 лет назад
Родитель
Сommit
dcfef9fa11

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -19,6 +19,9 @@ Release 0.23.10 - UNRELEASED
 
     HDFS-4998. TestUnderReplicatedBlocks fails intermittently (kihwal)
 
+    HDFS-4943. WebHdfsFileSystem does not work when original file path has
+    encoded chars. (Jerry He and Robert Parker via kihwal)
+
 Release 0.23.9 - 2013-07-08
 
   INCOMPATIBLE CHANGES

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java

@@ -324,7 +324,7 @@ public class WebHdfsFileSystem extends FileSystem
       final Param<?,?>... parameters) throws IOException {
     //initialize URI path and query
     final String path = PATH_PREFIX
-        + (fspath == null? "/": makeQualified(fspath).toUri().getPath());
+        + (fspath == null? "/": makeQualified(fspath).toUri().getRawPath());
     final String query = op.toQueryString()
         + Param.toSortedString("&", getAuthParameters(op))
         + Param.toSortedString("&", parameters);

+ 18 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsUrl.java

@@ -20,6 +20,7 @@ package org.apache.hadoop.hdfs.web;
 
 import java.io.IOException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Arrays;
 
@@ -55,6 +56,23 @@ public class TestWebHdfsUrl {
     UserGroupInformation.setConfiguration(new Configuration());
   }
   
+
+  @Test(timeout=60000)
+  public void testEncodedPathUrl() throws IOException, URISyntaxException{
+    Configuration conf = new Configuration();
+
+    final WebHdfsFileSystem webhdfs = (WebHdfsFileSystem) FileSystem.get(
+       uri, conf);
+
+    // Construct a file path that contains percentage-encoded string    
+    String pathName = "/hdtest010%2C60020%2C1371000602151.1371058984668";
+    Path fsPath = new Path(pathName);
+    URL encodedPathUrl = webhdfs.toUrl(PutOpParam.Op.CREATE, fsPath);
+    // We should get back the original file path after cycling back and decoding
+    Assert.assertEquals(WebHdfsFileSystem.PATH_PREFIX + pathName,
+        encodedPathUrl.toURI().getPath());
+  }
+
   @Test(timeout=4000)
   public void testSimpleAuthParamsInUrl() throws IOException {
     Configuration conf = new Configuration();