[ 
https://issues.apache.org/jira/browse/HADOOP-11613?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15153941#comment-15153941
 ] 

Masatake Iwasaki commented on HADOOP-11613:
-------------------------------------------

While looking the related code, I felt that we should not maintain own utils to 
encode/decode URI components as far as possible.

{{URIUtil.encodePath}} is used to compose URI. I think 
[URIBuilder|https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/utils/URIBuilder.html]
 (or 
[UriBuilder|http://docs.oracle.com/javaee/7/api/javax/ws/rs/core/UriBuilder.html]
 which is already used in hadoop-azure) is the right tool for this. URIBuilder 
internally uses 
[URLEncodedUtils|https://github.com/apache/httpclient/blob/4.5.x/httpclient/src/main/java/org/apache/http/client/utils/URLEncodedUtils.java]
 which looks like up-to-date version of URIUtil. I tried to replace existing 
code like

{code}
@@ -135,13 +136,9 @@ private static String convertUriToDecodedString(URI uri) {

   private static URI convertKeyToEncodedUri(String key) {
     try {
-      String encodedKey = URIUtil.encodePath(key);
-      URI uri = new URI(encodedKey);
-      return uri;
+      return new URIBuilder().setPath(key).build();
     } catch (URISyntaxException e) {
       throw new AssertionError("Failed to encode key: " + key);
-    } catch (URIException e) {
-      throw new AssertionError("Failed to encode key: " + key);
     }
   }

@@ -150,8 +147,8 @@ public CloudBlobContainerWrapper 
getContainerReference(String name)
       throws URISyntaxException, StorageException {
     String fullUri;
     try {
-      fullUri = baseUriString + "/" + URIUtil.encodePath(name);
-    } catch (URIException e) {
+      fullUri = new URIBuilder(baseUriString + "/" + name).toString();
+    } catch (URISyntaxException e) {
       throw new RuntimeException("problem encoding fullUri", e);
     }

@@ -255,8 +252,8 @@ private String fullUriString(String relativePath, boolean 
withTrailingSlash) {
       }

       try {
-        fullUri = baseUri + URIUtil.encodePath(relativePath);
-      } catch (URIException e) {
+        fullUri = new URIBuilder(baseUri + relativePath).toString();
+      } catch (URISyntaxException e) {
         throw new RuntimeException("problem encoding fullUri", e);
       }
{code}

but some unit tests failed due to this. still digging.


> Remove httpclient dependency from hadoop-azure
> ----------------------------------------------
>
>                 Key: HADOOP-11613
>                 URL: https://issues.apache.org/jira/browse/HADOOP-11613
>             Project: Hadoop Common
>          Issue Type: Sub-task
>            Reporter: Akira AJISAKA
>            Assignee: Brahma Reddy Battula
>              Labels: BB2015-05-TBR
>         Attachments: HADOOP-11613-001.patch, HADOOP-11613-002.patch, 
> HADOOP-11613-003.patch, HADOOP-11613.004.patch, HADOOP-11613.05.patch, 
> HADOOP-11613.06.patch, HADOOP-11613.patch
>
>
> Remove httpclient dependency from MockStorageInterface.java.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to