You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by ab...@apache.org on 2015/08/27 03:01:45 UTC

sqoop git commit: SQOOP-2507: Sqoop2: Do not use default Tomcat handlers for unsupported HTTP methods

Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 37fec0abd -> d11e83393


SQOOP-2507: Sqoop2: Do not use default Tomcat handlers for unsupported HTTP methods

(Jarek Jarcec Cecho via Abraham Elmahrek)


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

Branch: refs/heads/sqoop2
Commit: d11e83393161ebdd12f5383e349615d957e03763
Parents: 37fec0a
Author: Abraham Elmahrek <ab...@apache.org>
Authored: Wed Aug 26 18:00:19 2015 -0700
Committer: Abraham Elmahrek <ab...@apache.org>
Committed: Wed Aug 26 18:00:42 2015 -0700

----------------------------------------------------------------------
 .../sqoop/handler/VersionRequestHandler.java       |  5 -----
 .../apache/sqoop/server/SqoopProtocolServlet.java  | 17 +++++------------
 .../integration/server/InvalidRESTCallsTest.java   | 15 ++++++++++++++-
 3 files changed, 19 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/d11e8339/server/src/main/java/org/apache/sqoop/handler/VersionRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/handler/VersionRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/VersionRequestHandler.java
index 588218b..30819bc 100644
--- a/server/src/main/java/org/apache/sqoop/handler/VersionRequestHandler.java
+++ b/server/src/main/java/org/apache/sqoop/handler/VersionRequestHandler.java
@@ -55,11 +55,6 @@ public class VersionRequestHandler implements RequestHandler {
 
   @Override
   public JsonBean handleEvent(RequestContext ctx) {
-    // version only support GET requests
-    if (ctx.getMethod() != Method.GET) {
-      throw new SqoopException(ServerError.SERVER_0002, "Unsupported HTTP method for version:"
-          + ctx.getMethod());
-    }
     AuditLoggerManager.getInstance()
         .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
         "show", "version", "");

http://git-wip-us.apache.org/repos/asf/sqoop/blob/d11e8339/server/src/main/java/org/apache/sqoop/server/SqoopProtocolServlet.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/server/SqoopProtocolServlet.java b/server/src/main/java/org/apache/sqoop/server/SqoopProtocolServlet.java
index 92bdc9c..fb4a99f 100644
--- a/server/src/main/java/org/apache/sqoop/server/SqoopProtocolServlet.java
+++ b/server/src/main/java/org/apache/sqoop/server/SqoopProtocolServlet.java
@@ -32,6 +32,7 @@ import org.apache.sqoop.common.SqoopProtocolConstants;
 import org.apache.sqoop.common.SqoopResponseCode;
 import org.apache.sqoop.error.code.CoreError;
 import org.apache.sqoop.json.JsonBean;
+import org.apache.sqoop.server.common.ServerError;
 
 @SuppressWarnings("serial")
 public class SqoopProtocolServlet extends HttpServlet {
@@ -160,26 +161,18 @@ public class SqoopProtocolServlet extends HttpServlet {
   }
 
   protected JsonBean handleGetRequest(RequestContext ctx) throws Exception {
-    super.doGet(ctx.getRequest(), ctx.getResponse());
-
-    return null;
+    throw new SqoopException(ServerError.SERVER_0002, ctx.getMethod() + " for " + ctx.getPath());
   }
 
   protected JsonBean handlePostRequest(RequestContext ctx) throws Exception {
-    super.doPost(ctx.getRequest(), ctx.getResponse());
-
-    return null;
+    throw new SqoopException(ServerError.SERVER_0002, ctx.getMethod() + " for " + ctx.getPath());
   }
 
   protected JsonBean handlePutRequest(RequestContext ctx) throws Exception {
-    super.doPut(ctx.getRequest(), ctx.getResponse());
-
-    return null;
+    throw new SqoopException(ServerError.SERVER_0002, ctx.getMethod() + " for " + ctx.getPath());
   }
 
   protected JsonBean handleDeleteRequest(RequestContext ctx) throws Exception {
-    super.doDelete(ctx.getRequest(), ctx.getResponse());
-
-    return null;
+    throw new SqoopException(ServerError.SERVER_0002, ctx.getMethod() + " for " + ctx.getPath());
   }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/d11e8339/test/src/test/java/org/apache/sqoop/integration/server/InvalidRESTCallsTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/server/InvalidRESTCallsTest.java b/test/src/test/java/org/apache/sqoop/integration/server/InvalidRESTCallsTest.java
index 0490cf0..da3a6ea 100644
--- a/test/src/test/java/org/apache/sqoop/integration/server/InvalidRESTCallsTest.java
+++ b/test/src/test/java/org/apache/sqoop/integration/server/InvalidRESTCallsTest.java
@@ -39,6 +39,8 @@ import java.net.URL;
 import java.nio.charset.Charset;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
 
 @Infrastructure(dependencies = {HadoopInfrastructureProvider.class, SqoopInfrastructureProvider.class})
 public class InvalidRESTCallsTest extends SqoopTestCase {
@@ -69,6 +71,16 @@ public class InvalidRESTCallsTest extends SqoopTestCase {
     public void assertResponseCode(int expected) throws Exception {
       assertEquals(connection.getResponseCode(), expected);
     }
+
+    // Assert given exception from server
+    public void assertServerException(String errorClass, String errorCode) throws Exception {
+      // On exception, the error trace can't be null
+      assertNotNull(error);
+
+      // We're not parsing entire JSON, but rather just looking for sub-strings that are of particular interest
+      assertTrue(error.contains("error-code-class\":\"" + errorClass));
+      assertTrue(error.contains("error-code\":\"" + errorCode));
+    }
   }
 
   // Small internal class describing our test case
@@ -101,7 +113,8 @@ public class InvalidRESTCallsTest extends SqoopTestCase {
     new TestDescription("Invalid post request", "version", "POST", "Random text", new Validator() {
       @Override
       void validate() throws Exception {
-        assertResponseCode(405);
+        assertResponseCode(500);
+        assertServerException("org.apache.sqoop.server.common.ServerError", "SERVER_0002");
       }}),
   };