[NO ISSUE][FAIL] Use Formatted Exception For No Statement Provided

- user model changes: no
- storage format changes: no
- interface changes: no

Change-Id: Ibe86b4e6703a3e0e228d96d37e371cc2295ccc12
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2869
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceRequestParameters.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceRequestParameters.java
index d0c59b5..16a2105 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceRequestParameters.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceRequestParameters.java
@@ -201,7 +201,7 @@
             ObjectNode on = OBJECT_MAPPER.createObjectNode();
             on.put("host", host);
             on.put("path", path);
-            on.put("statement", JSONUtil.escape(new StringBuilder(), statement).toString());
+            on.put("statement", statement != null ? JSONUtil.escape(new StringBuilder(), statement).toString() : null);
             on.put("pretty", pretty);
             on.put("mode", mode);
             on.put("clientContextID", clientContextID);
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
index 54b5baa..c05ce6f 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
@@ -43,7 +43,8 @@
 import org.apache.asterix.common.config.GlobalConfig;
 import org.apache.asterix.common.context.IStorageComponentProvider;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.lang.aql.parser.TokenMgrError;
 import org.apache.asterix.lang.common.base.IParser;
@@ -416,7 +417,10 @@
         if (HttpUtil.ContentType.APPLICATION_JSON.equals(contentType)) {
             try {
                 JsonNode jsonRequest = OBJECT_MAPPER.readTree(HttpUtil.getRequestBody(request));
-                param.setStatement(jsonRequest.get(Parameter.STATEMENT.str()).asText());
+                final String statementParam = Parameter.STATEMENT.str();
+                if (jsonRequest.has(statementParam)) {
+                    param.setStatement(jsonRequest.get(statementParam).asText());
+                }
                 param.setFormat(toLower(getOptText(jsonRequest, Parameter.FORMAT.str())));
                 param.setPretty(getOptBoolean(jsonRequest, Parameter.PRETTY.str(), false));
                 param.setMode(toLower(getOptText(jsonRequest, Parameter.MODE.str())));
@@ -532,7 +536,7 @@
         List<ExecutionWarning> warnings = Collections.emptyList(); // we don't have any warnings yet
         try {
             if (param.getStatement() == null || param.getStatement().isEmpty()) {
-                throw new AsterixException("Empty request, no statement provided");
+                throw new RuntimeDataException(ErrorCode.NO_STATEMENT_PROVIDED);
             }
             String statementsText = param.getStatement() + ";";
             Map<String, String> optionalParams = null;
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
index 8af1ec7..3fbce28 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
@@ -79,6 +79,7 @@
     public static final int TYPE_MISMATCH_GENERIC = 37;
     public static final int DIFFERENT_LIST_TYPE_ARGS = 38;
     public static final int INTEGER_VALUE_EXPECTED = 39;
+    public static final int NO_STATEMENT_PROVIDED = 40;
 
     public static final int UNSUPPORTED_JRE = 100;
 
diff --git a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
index 63e0cda..f0dfd1a 100644
--- a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
+++ b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
@@ -73,6 +73,7 @@
 36 = Cannot compare non-primitive values
 38 = Input contains different list types
 39 = Expected integer value, got %1$s
+40 = No statement provided
 
 100 = Unsupported JRE: %1$s