asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject asterixdb git commit: set HTTP status code before writing the result
Date Thu, 01 Sep 2016 22:30:48 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master 4ba0bf3c5 -> a9ac670b8


set HTTP status code before writing the result

Change-Id: I46adb4aeaaa1ada6669b7535bb6d0879a26bc319
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1134
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>


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

Branch: refs/heads/master
Commit: a9ac670b8d48fe6f2f2a6996513f9248e8d69603
Parents: 4ba0bf3
Author: Till Westmann <tillw@apache.org>
Authored: Thu Sep 1 10:20:10 2016 -0700
Committer: Till Westmann <tillw@apache.org>
Committed: Thu Sep 1 15:30:10 2016 -0700

----------------------------------------------------------------------
 .../api/http/servlet/QueryServiceServlet.java   |  4 +--
 .../apache/asterix/test/aql/TestExecutor.java   | 26 +++++++++++---------
 2 files changed, 17 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/a9ac670b/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 b4097d1..3b69dd1 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
@@ -342,7 +342,7 @@ public class QueryServiceServlet extends HttpServlet {
         printField(pw, ErrorField.CODE.str(), "1");
         final String msg = rootCause.getMessage();
         printField(pw, ErrorField.MSG.str(),
-                JSONUtil.escape(rootCause.getClass().getName() + ": " + msg != null ? msg
: ""), addStack);
+                JSONUtil.escape(rootCause.getClass().getName() + ": " + (msg != null ? msg
: "")), addStack);
         if (addStack) {
             StringWriter sw = new StringWriter();
             PrintWriter stackWriter = new PrintWriter(sw);
@@ -453,10 +453,10 @@ public class QueryServiceServlet extends HttpServlet {
 
         GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, result);
 
+        response.setStatus(respCode);
         response.getWriter().print(result);
         if (response.getWriter().checkError()) {
             LOGGER.warning("Error flushing output writer");
         }
-        response.setStatus(respCode);
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/a9ac670b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java
b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java
index 3e16802..52237d8 100644
--- a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java
+++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java
@@ -250,21 +250,25 @@ public class TestExecutor {
         }
     }
 
+    protected HttpResponse executeAndCheckHttpRequest(HttpUriRequest method) throws Exception
{
+        return checkResponse(executeHttpRequest(method));
+    }
+
     protected HttpResponse executeHttpRequest(HttpUriRequest method) throws Exception {
         HttpClient client = HttpClients.custom()
                 .setRetryHandler(StandardHttpRequestRetryHandler.INSTANCE)
                 .build();
-        HttpResponse httpResponse;
-
         try {
-            httpResponse = client.execute(method);
+            return client.execute(method);
         } catch (Exception e) {
             GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), e);
             e.printStackTrace();
             throw e;
         }
-        int statusCode = httpResponse.getStatusLine().getStatusCode();
-        if (statusCode != HttpStatus.SC_OK) {
+    }
+
+    protected HttpResponse checkResponse(HttpResponse httpResponse) throws Exception {
+        if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
             // QQQ For now, we are indeed assuming we get back JSON errors.
             // In future this may be changed depending on the requested
             // output format sent to the servlet.
@@ -294,7 +298,7 @@ public class TestExecutor {
         HttpUriRequest method = constructHttpMethod(str, url, "query", false, params);
         // Set accepted output response type
         method.setHeader("Accept", fmt.mimeType());
-        HttpResponse response = executeHttpRequest(method);
+        HttpResponse response = executeAndCheckHttpRequest(method);
         return response.getEntity().getContent();
     }
 
@@ -368,7 +372,7 @@ public class TestExecutor {
     public InputStream executeClusterStateQuery(OutputFormat fmt, String url) throws Exception
{
         HttpUriRequest request = RequestBuilder.get(url).setHeader("Accept", fmt.mimeType()).build();
 
-        HttpResponse response = executeHttpRequest(request);
+        HttpResponse response = executeAndCheckHttpRequest(request);
         return response.getEntity().getContent();
     }
 
@@ -381,7 +385,7 @@ public class TestExecutor {
                 .build();
 
         // Execute the method.
-        executeHttpRequest(request);
+        executeAndCheckHttpRequest(request);
     }
 
     // Executes AQL in either async or async-defer mode.
@@ -393,7 +397,7 @@ public class TestExecutor {
                 .setHeader("Accept", fmt.mimeType())
                 .build();
 
-        HttpResponse response = executeHttpRequest(request);
+        HttpResponse response = executeAndCheckHttpRequest(request);
         InputStream resultStream = response.getEntity().getContent();
 
         String theHandle = IOUtils.toString(resultStream, "UTF-8");
@@ -412,7 +416,7 @@ public class TestExecutor {
                 .setHeader("Accept", fmt.mimeType())
                 .build();
 
-        HttpResponse response = executeHttpRequest(request);
+        HttpResponse response = executeAndCheckHttpRequest(request);
         return response.getEntity().getContent();
     }
 
@@ -429,7 +433,7 @@ public class TestExecutor {
                 .build();
 
         // Execute the method.
-        executeHttpRequest(request);
+        executeAndCheckHttpRequest(request);
     }
 
     // Method that reads a DDL/Update/Query File


Mime
View raw message