hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aengin...@apache.org
Subject hadoop git commit: HDDS-679. Add query parameter to the constructed query in VirtualHostStyleFilter. Contributed by Bharat Viswanadham.
Date Fri, 19 Oct 2018 19:02:35 GMT
Repository: hadoop
Updated Branches:
  refs/heads/ozone-0.3 69cf9e66e -> 6417a5119


HDDS-679. Add query parameter to the constructed query in VirtualHostStyleFilter.
Contributed by Bharat Viswanadham.

(cherry picked from commit d7b012e5600fa19b330d61a2572499f14fe9bb61)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/6417a511
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/6417a511
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/6417a511

Branch: refs/heads/ozone-0.3
Commit: 6417a511925e3a31efc4d3ca8dc57f96d23bb8ff
Parents: 69cf9e6
Author: Anu Engineer <aengineer@apache.org>
Authored: Fri Oct 19 11:40:11 2018 -0700
Committer: Anu Engineer <aengineer@apache.org>
Committed: Fri Oct 19 12:02:24 2018 -0700

----------------------------------------------------------------------
 .../hadoop/ozone/s3/VirtualHostStyleFilter.java | 13 +++--
 .../ozone/s3/TestVirtualHostStyleFilter.java    | 52 +++++++++++++++++---
 2 files changed, 53 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/6417a511/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/VirtualHostStyleFilter.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/VirtualHostStyleFilter.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/VirtualHostStyleFilter.java
index 4cf78b6..f1d52a6 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/VirtualHostStyleFilter.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/VirtualHostStyleFilter.java
@@ -22,14 +22,14 @@ import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.container.PreMatching;
 import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.ext.Provider;
 
 import java.io.IOException;
 import java.net.URI;
 import java.util.Arrays;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+
 
 import com.google.common.annotations.VisibleForTesting;
 import org.apache.hadoop.fs.InvalidRequestException;
@@ -95,11 +95,16 @@ public class VirtualHostStyleFilter implements ContainerRequestFilter
{
 
       URI baseURI = requestContext.getUriInfo().getBaseUri();
       String currentPath = requestContext.getUriInfo().getPath();
-          String newPath = bucketName;
+      String newPath = bucketName;
       if (currentPath != null) {
         newPath += String.format("%s", currentPath);
       }
-      URI requestAddr = UriBuilder.fromUri(baseURI).path(newPath).build();
+      MultivaluedMap<String, String> queryParams = requestContext.getUriInfo()
+          .getQueryParameters();
+      UriBuilder requestAddrBuilder = UriBuilder.fromUri(baseURI).path(newPath);
+      queryParams.forEach((k, v) -> requestAddrBuilder.queryParam(k,
+          v.toArray()));
+      URI requestAddr = requestAddrBuilder.build();
       requestContext.setRequestUri(baseURI, requestAddr);
     }
   }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/6417a511/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestVirtualHostStyleFilter.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestVirtualHostStyleFilter.java
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestVirtualHostStyleFilter.java
index 5548c77..3fe6e1a 100644
--- a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestVirtualHostStyleFilter.java
+++ b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/TestVirtualHostStyleFilter.java
@@ -31,6 +31,7 @@ import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.SecurityContext;
 import java.net.URI;
 
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 /**
@@ -55,16 +56,27 @@ public class TestVirtualHostStyleFilter {
    * @throws Exception
    */
   public ContainerRequest createContainerRequest(String host, String path,
+                                                 String queryParams,
                                                  boolean virtualHostStyle)
       throws Exception {
     URI baseUri = new URI("http://" + s3HttpAddr);
     URI virtualHostStyleUri;
-    if (path == null) {
+    if (path == null && queryParams == null) {
       virtualHostStyleUri = new URI("http://" + s3HttpAddr);
-    } else {
+    } else if (path != null && queryParams == null) {
       virtualHostStyleUri = new URI("http://" + s3HttpAddr + path);
+    } else if (path !=null && queryParams != null)  {
+      virtualHostStyleUri = new URI("http://" + s3HttpAddr + path +
+          queryParams);
+    } else {
+      virtualHostStyleUri = new URI("http://" + s3HttpAddr  + queryParams);
+    }
+    URI pathStyleUri;
+    if (queryParams == null) {
+      pathStyleUri = new URI("http://" + s3HttpAddr + path);
+    } else {
+      pathStyleUri = new URI("http://" + s3HttpAddr + path + queryParams);
     }
-    URI pathStyleUri = new URI("http://" + s3HttpAddr + path);
     String httpMethod = "DELETE";
     SecurityContext securityContext = Mockito.mock(SecurityContext.class);
     PropertiesDelegate propertiesDelegate = Mockito.mock(PropertiesDelegate
@@ -89,7 +101,7 @@ public class TestVirtualHostStyleFilter {
     virtualHostStyleFilter.setConfiguration(conf);
 
     ContainerRequest containerRequest = createContainerRequest("mybucket" +
-            ".localhost:9878", "/myfile", true);
+            ".localhost:9878", "/myfile", null, true);
     virtualHostStyleFilter.filter(containerRequest);
     URI expected = new URI("http://" + s3HttpAddr +
         "/mybucket/myfile");
@@ -104,7 +116,7 @@ public class TestVirtualHostStyleFilter {
     virtualHostStyleFilter.setConfiguration(conf);
 
     ContainerRequest containerRequest = createContainerRequest(s3HttpAddr,
-        "/mybucket/myfile", false);
+        "/mybucket/myfile", null, false);
     virtualHostStyleFilter.filter(containerRequest);
     URI expected = new URI("http://" + s3HttpAddr +
         "/mybucket/myfile");
@@ -120,7 +132,7 @@ public class TestVirtualHostStyleFilter {
     virtualHostStyleFilter.setConfiguration(conf);
 
     ContainerRequest containerRequest = createContainerRequest("mybucket" +
-        ".localhost:9878", null, true);
+        ".localhost:9878", null, null, true);
     virtualHostStyleFilter.filter(containerRequest);
     URI expected = new URI("http://" + s3HttpAddr + "/mybucket");
     Assert.assertEquals(expected, containerRequest.getRequestUri());
@@ -128,6 +140,30 @@ public class TestVirtualHostStyleFilter {
   }
 
   @Test
+  public void testVirtualHostStyleWithQueryParams() throws Exception {
+
+    VirtualHostStyleFilter virtualHostStyleFilter =
+        new VirtualHostStyleFilter();
+    virtualHostStyleFilter.setConfiguration(conf);
+
+    ContainerRequest containerRequest = createContainerRequest("mybucket" +
+        ".localhost:9878", null, "?prefix=bh", true);
+    virtualHostStyleFilter.filter(containerRequest);
+    URI expected = new URI("http://" + s3HttpAddr + "/mybucket?prefix=bh");
+    assertTrue(expected.toString().contains(containerRequest.getRequestUri()
+        .toString()));
+
+    containerRequest = createContainerRequest("mybucket" +
+        ".localhost:9878", null, "?prefix=bh&type=dir", true);
+    virtualHostStyleFilter.filter(containerRequest);
+    expected = new URI("http://" + s3HttpAddr +
+        "/mybucket?prefix=bh&type=dir");
+    assertTrue(expected.toString().contains(containerRequest.getRequestUri()
+        .toString()));
+
+  }
+
+  @Test
   public void testVirtualHostStyleWithNoMatchingDomain() throws Exception {
 
     VirtualHostStyleFilter virtualHostStyleFilter =
@@ -135,7 +171,7 @@ public class TestVirtualHostStyleFilter {
     virtualHostStyleFilter.setConfiguration(conf);
 
     ContainerRequest containerRequest = createContainerRequest("mybucket" +
-        ".localhost:9999", null, true);
+        ".localhost:9999", null, null, true);
     try {
       virtualHostStyleFilter.filter(containerRequest);
     } catch (InvalidRequestException ex) {
@@ -153,7 +189,7 @@ public class TestVirtualHostStyleFilter {
     virtualHostStyleFilter.setConfiguration(conf);
 
     ContainerRequest containerRequest = createContainerRequest("mybucket" +
-        "localhost:9878", null, true);
+        "localhost:9878", null, null, true);
     try {
       virtualHostStyleFilter.filter(containerRequest);
       fail("testIncorrectVirtualHostStyle failed");


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message