[email protected] has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/3082

Change subject: reorg code to allow solving the gerrit update.
......................................................................

reorg code to allow solving the gerrit update.

Change-Id: I3c457d7029bd5f814e5791fc224e9100c26ea1c8
---
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
1 file changed, 26 insertions(+), 37 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/82/3082/1

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 00c461b..3b16899 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
@@ -34,7 +34,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-
 import java.util.concurrent.ConcurrentMap;
 import java.util.function.BiFunction;
 import java.util.function.Function;
@@ -518,44 +517,39 @@
         return "http://"; + host + path + handlePath(delivery);
     }
 
+
+
     private void handleRequest(IServletRequest request, IServletResponse 
response) throws IOException {
-        QueryServiceRequestParameters param = getRequestParameters(request);
-        LOGGER.info("handleRequest: {}", param);
         long elapsedStart = System.nanoTime();
-        final PrintWriter httpWriter = response.writer();
-
-        ResultDelivery delivery = parseResultDelivery(param.getMode());
-
-        final ResultProperties resultProperties = param.getMaxResultReads() == 
null ? new ResultProperties(delivery)
-                : new ResultProperties(delivery, 
Long.parseLong(param.getMaxResultReads()));
-
-        String handleUrl = getHandleUrl(param.getHost(), param.getPath(), 
delivery);
-        SessionOutput sessionOutput = createSessionOutput(param, handleUrl, 
httpWriter);
-        SessionConfig sessionConfig = sessionOutput.config();
-        HttpUtil.setContentType(response, 
HttpUtil.ContentType.APPLICATION_JSON, HttpUtil.Encoding.UTF8);
-
+        long errorCount = 1;
         Stats stats = new Stats();
-
-        // buffer the output until we are ready to set the status of the 
response message correctly
-        sessionOutput.hold();
-        sessionOutput.out().print("{\n");
-        printRequestId(sessionOutput.out());
-        printClientContextID(sessionOutput.out(), param);
-        if (!param.isParseOnly()) {
-            printSignature(sessionOutput.out(), param);
-        }
-        printType(sessionOutput.out(), sessionConfig);
-        long errorCount = 1; // so far we just return 1 error
-        List<ExecutionWarning> warnings = Collections.emptyList(); // we don't 
have any warnings yet
-
         RequestExecutionState execution = new RequestExecutionState();
+        List<ExecutionWarning> warnings = Collections.emptyList();
+        PrintWriter httpWriter = response.writer();
+        SessionOutput sessionOutput = createSessionOutput(param, handleUrl, 
httpWriter);
+        QueryServiceRequestParameters param = new 
QueryServiceRequestParameters();
         try {
+            // buffer the output until we are ready to set the status of the 
response message correctly
+            sessionOutput.hold();
+            sessionOutput.out().print("{\n");
+            HttpUtil.setContentType(response, 
HttpUtil.ContentType.APPLICATION_JSON, HttpUtil.Encoding.UTF8);
+            setRequestParam(request, param);
+            LOGGER.info("handleRequest: {}", param);
+            ResultDelivery delivery = parseResultDelivery(param.getMode());
+            setSessionConfig(sessionOutput, param, delivery);
+            final ResultProperties resultProperties = 
param.getMaxResultReads() == null ? new ResultProperties(delivery)
+                    : new ResultProperties(delivery, 
Long.parseLong(param.getMaxResultReads()));
+            printAdditionalResultFields(sessionOutput.out());
+            printRequestId(sessionOutput.out());
+            printClientContextID(sessionOutput.out(), param);
+            if (!param.isParseOnly()) {
+                printSignature(sessionOutput.out(), param);
+            }
+            printType(sessionOutput.out(), sessionOutput.config());
             if (param.getStatement() == null || 
param.getStatement().isEmpty()) {
                 throw new 
RuntimeDataException(ErrorCode.NO_STATEMENT_PROVIDED);
             }
-
             String statementsText = param.getStatement() + ";";
-
             Map<String, String> optionalParams = null;
             if (optionalParamProvider != null) {
                 optionalParams = optionalParamProvider.apply(request);
@@ -579,9 +573,8 @@
                 }
                 response.setHeader("Access-Control-Allow-Headers", "Origin, 
X-Requested-With, Content-Type, Accept");
                 response.setStatus(execution.getHttpStatus());
-
-                executeStatement(statementsText, sessionOutput, 
resultProperties, stats, param, execution,
-                        optionalParams, statementParams);
+                executeStatement(statementsText, sessionOutput, 
resultProperties, stats, param, execution, optionalParams,
+                        statementParams);
                 if (ResultDelivery.IMMEDIATE == delivery || 
ResultDelivery.DEFERRED == delivery) {
                     ResultUtil.printStatus(sessionOutput, 
execution.getResultStatus());
                 }
@@ -589,9 +582,7 @@
             if (!warnings.isEmpty()) {
                 printWarnings(sessionOutput.out(), warnings);
             }
-
             errorCount = 0;
-
         } catch (Exception | TokenMgrError | 
org.apache.asterix.aqlplus.parser.TokenMgrError e) {
             handleExecuteStatementException(e, execution, param);
             response.setStatus(execution.getHttpStatus());
@@ -602,10 +593,8 @@
             sessionOutput.release();
             execution.finish();
         }
-
         printMetrics(sessionOutput.out(), System.nanoTime() - elapsedStart, 
execution.duration(), stats.getCount(),
                     stats.getSize(), stats.getProcessedObjects(), errorCount, 
warnings.size());
-
         sessionOutput.out().print("}\n");
         sessionOutput.out().flush();
         if (sessionOutput.out().checkError()) {

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/3082
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c457d7029bd5f814e5791fc224e9100c26ea1c8
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: [email protected]

Reply via email to