Return an error if a non query statement is passed to the REST API endpoint.

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_result_distribution@1157 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryAPIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryAPIServlet.java
index 92bfb3f..4e9659e 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryAPIServlet.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryAPIServlet.java
@@ -24,9 +24,14 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.json.JSONArray;
+
+import twitter4j.internal.org.json.JSONObject;
+
 import edu.uci.ics.asterix.api.common.APIFramework.DisplayFormat;
 import edu.uci.ics.asterix.api.common.SessionConfig;
 import edu.uci.ics.asterix.aql.base.Statement;
+import edu.uci.ics.asterix.aql.base.Statement.Kind;
 import edu.uci.ics.asterix.aql.parser.AQLParser;
 import edu.uci.ics.asterix.aql.parser.ParseException;
 import edu.uci.ics.asterix.aql.translator.AqlTranslator;
@@ -39,6 +44,8 @@
 
     private static final String HYRACKS_CONNECTION_ATTR = "edu.uci.ics.asterix.HYRACKS_CONNECTION";
 
+    private static final Kind QUERY_STMT = Kind.QUERY;
+
     @Override
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
         String query = request.getParameter("query");
@@ -64,6 +71,15 @@
             }
             AQLParser parser = new AQLParser(new StringReader(query));
             List<Statement> aqlStatements = parser.Statement();
+            for (Statement st : aqlStatements) {
+                if (st.getKind() != QUERY_STMT) {
+                    JSONObject errorResp = new JSONObject();
+                    JSONArray errorArray = new JSONArray();
+                    errorArray.put("1");
+                    errorArray.put("Invalid stament: Non-query statement to the query API." + st.getKind());
+                    errorResp.put("error-code", errorArray);
+                }
+            }
             SessionConfig sessionConfig = new SessionConfig(port, true, false, false, false, false, false, true, false);
 
             MetadataManager.INSTANCE.init();