Repository: asterixdb
Updated Branches:
  refs/heads/master b99349d5c -> 4ad756062


ASTERIXDB-1714: Eliminate dependency on org.json

Change-Id: I3ada73e15c781a77b5b3019f246e1a1fc23a2377
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1318
Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mb...@apache.org>


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

Branch: refs/heads/master
Commit: 4ad756062d7afde7c03801705dad4ca9854ccf87
Parents: b99349d
Author: Till Westmann <ti...@apache.org>
Authored: Wed Nov 2 10:48:46 2016 -0700
Committer: Michael Blow <mb...@apache.org>
Committed: Wed Nov 9 17:50:37 2016 -0800

----------------------------------------------------------------------
 asterixdb/asterix-app/pom.xml                   | 10 +++++++
 .../api/http/servlet/QueryServiceServlet.java   | 28 ++++++++++++++------
 2 files changed, 30 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4ad75606/asterixdb/asterix-app/pom.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/pom.xml b/asterixdb/asterix-app/pom.xml
index 0ae7ea3..79c0c6a 100644
--- a/asterixdb/asterix-app/pom.xml
+++ b/asterixdb/asterix-app/pom.xml
@@ -196,6 +196,16 @@
       <scope>compile</scope>
     </dependency>
     <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-core</artifactId>
+      <version>2.8.4</version>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-databind</artifactId>
+      <version>2.8.4</version>
+    </dependency>
+    <dependency>
       <groupId>org.apache.hyracks</groupId>
       <artifactId>hyracks-control-cc</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4ad75606/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
index 1b6d718..941c7f7 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/QueryServiceServlet.java
@@ -36,6 +36,10 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.asterix.app.result.ResultReader;
 import org.apache.asterix.app.result.ResultUtil;
 import org.apache.asterix.app.translator.QueryTranslator;
@@ -59,8 +63,6 @@ import 
org.apache.hyracks.algebricks.core.algebra.prettyprint.AlgebricksAppendab
 import org.apache.hyracks.api.client.IHyracksClientConnection;
 import org.apache.hyracks.api.dataset.IHyracksDataset;
 import org.apache.hyracks.client.dataset.HyracksDataset;
-import org.json.JSONException;
-import org.json.JSONObject;
 
 public class QueryServiceServlet extends HttpServlet {
     private static final long serialVersionUID = 1L;
@@ -417,6 +419,16 @@ public class QueryServiceServlet extends HttpServlet {
         }
     }
 
+    private String getOptText(JsonNode node, String fieldName) {
+        final JsonNode value = node.get(fieldName);
+        return value != null ? value.asText() : null;
+    }
+
+    private boolean getOptBoolean(JsonNode node, String fieldName, boolean 
defaultValue) {
+        final JsonNode value = node.get(fieldName);
+        return value != null ? value.asBoolean() : defaultValue;
+    }
+
     private RequestParameters getRequestParameters(HttpServletRequest request) 
throws IOException {
         final String contentTypeParam = request.getContentType();
         int sep = contentTypeParam.indexOf(';');
@@ -424,12 +436,12 @@ public class QueryServiceServlet extends HttpServlet {
         RequestParameters param = new RequestParameters();
         if (MediaType.JSON.str().equals(contentType)) {
             try {
-                JSONObject jsonRequest = new 
JSONObject(getRequestBody(request));
-                param.statement = 
jsonRequest.getString(Parameter.STATEMENT.str());
-                param.format = 
toLower(jsonRequest.optString(Parameter.FORMAT.str()));
-                param.pretty = jsonRequest.optBoolean(Parameter.PRETTY.str());
-                param.clientContextID = 
jsonRequest.optString(Parameter.CLIENT_ID.str());
-            } catch (JSONException e) {
+                JsonNode jsonRequest = new 
ObjectMapper().readTree(getRequestBody(request));
+                param.statement = 
jsonRequest.get(Parameter.STATEMENT.str()).asText();
+                param.format = toLower(getOptText(jsonRequest, 
Parameter.FORMAT.str()));
+                param.pretty = getOptBoolean(jsonRequest, 
Parameter.PRETTY.str(), false);
+                param.clientContextID = getOptText(jsonRequest, 
Parameter.CLIENT_ID.str());
+            } catch (JsonParseException | JsonMappingException e) {
                 // if the JSON parsing fails, the statement is empty and we 
get an empty statement error
                 GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), 
e);
             }

Reply via email to