From 05fd0a706aedfb83222a48e4cd110b1897c4b3c5 Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Tue, 2 Jul 2013 14:58:35 +0000 Subject: [PATCH] HDFS-4943. WebHdfsFileSystem does not work when original file path has encoded chars. Contributed by Jerry He git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1498962 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hadoop/hdfs/web/WebHdfsFileSystem.java | 2 +- .../hadoop/hdfs/web/TestWebHdfsUrl.java | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 36fabb1fcd..cbad9848dd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -640,6 +640,9 @@ Release 2.1.0-beta - 2013-07-02 HDFS-4888. Refactor and fix FSNamesystem.getTurnOffTip. (Ravi Prakash via kihwal) + HDFS-4943. WebHdfsFileSystem does not work when original file path has + encoded chars. (Jerry He via szetszwo) + BREAKDOWN OF HDFS-347 SUBTASKS AND RELATED JIRAS HDFS-4353. Encapsulate connections to peers in Peer and PeerServer classes. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java index c1bdadb706..9dbb01b394 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java @@ -389,7 +389,7 @@ URL toUrl(final HttpOpParam.Op op, final Path fspath, 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); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsUrl.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsUrl.java index b084a630a4..2bcab6ef6f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsUrl.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsUrl.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.Arrays; @@ -54,6 +55,22 @@ public void resetUGI() { 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=60000) public void testSimpleAuthParamsInUrl() throws IOException { Configuration conf = new Configuration(); @@ -380,4 +397,4 @@ public int getDefaultPort() { return super.getDefaultPort(); } } -} \ No newline at end of file +}