Browse Source

HDFS-15110. HttpFS: post requests are not supported for path "/". Contributed by hemanthboyina.

Takanobu Asanuma 5 years ago
parent
commit
9da294a140

+ 24 - 0
hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java

@@ -525,6 +525,30 @@ public class HttpFSServer {
     return response;
     return response;
   }
   }
 
 
+  /**
+   * Special binding for '/' as it is not handled by the wildcard binding.
+   * @param is the inputstream for the request payload.
+   * @param uriInfo the of the request.
+   * @param op the HttpFS operation of the request.
+   * @param params the HttpFS parameters of the request.
+   *
+   * @return the request response.
+   *
+   * @throws IOException thrown if an IO error occurred. Thrown exceptions are
+   *           handled by {@link HttpFSExceptionProvider}.
+   * @throws FileSystemAccessException thrown if a FileSystemAccess related
+   *           error occurred. Thrown exceptions are handled by
+   *           {@link HttpFSExceptionProvider}.
+   */
+  @POST
+  @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8 })
+  public Response postRoot(InputStream is, @Context UriInfo uriInfo,
+      @QueryParam(OperationParam.NAME) OperationParam op,
+      @Context Parameters params, @Context HttpServletRequest request)
+      throws IOException, FileSystemAccessException {
+    return post(is, uriInfo, "/", op, params, request);
+  }
+
   /**
   /**
    * Binding to handle POST requests.
    * Binding to handle POST requests.
    *
    *

+ 10 - 0
hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServer.java

@@ -1790,5 +1790,15 @@ public class TestHttpFSServer extends HFSTestCase {
         putCmdWithReturn(dir1, "SETECPOLICY", "ecpolicy=" + ecPolicyName);
         putCmdWithReturn(dir1, "SETECPOLICY", "ecpolicy=" + ecPolicyName);
     // Should return HTTP_OK
     // Should return HTTP_OK
     Assert.assertEquals(HttpURLConnection.HTTP_OK, conn3.getResponseCode());
     Assert.assertEquals(HttpURLConnection.HTTP_OK, conn3.getResponseCode());
+
+    // test post operation with path as "/"
+    final String dir2 = "/";
+    URL url1 = new URL(TestJettyHelper.getJettyURL(),
+        MessageFormat.format("/webhdfs/v1{0}?user.name={1}&op={2}&{3}", dir2,
+            user, "UNSETECPOLICY", ""));
+    HttpURLConnection conn4 = (HttpURLConnection) url1.openConnection();
+    conn4.setRequestMethod("POST");
+    conn4.connect();
+    Assert.assertEquals(HttpURLConnection.HTTP_OK, conn4.getResponseCode());
   }
   }
 }
 }