ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [06/25] ignite git commit: IGNITE-6012 Refactored GridJettyRestHandler.processRequest(): replace mapper.writeValueAsString with writeValue(stream, v).
Date Wed, 16 Aug 2017 15:41:29 GMT
IGNITE-6012 Refactored GridJettyRestHandler.processRequest(): replace mapper.writeValueAsString
with writeValue(stream, v).


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

Branch: refs/heads/ignite-5901
Commit: 3a390c8afa157a54bdcde62a30159baebea87fb4
Parents: ebb8765
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Fri Aug 11 11:07:26 2017 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Fri Aug 11 11:07:26 2017 +0700

----------------------------------------------------------------------
 .../http/jetty/GridJettyRestHandler.java        | 31 +++++++-------------
 1 file changed, 10 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3a390c8a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
index c864a10..327c13a 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
@@ -34,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
 import javax.servlet.ServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -356,41 +357,29 @@ public class GridJettyRestHandler extends AbstractHandler {
 
             U.error(log, "Failed to process HTTP request [action=" + act + ", req=" + req
+ ']', e);
 
-            cmdRes = new GridRestResponse(STATUS_FAILED, e.getMessage());
-
             if (e instanceof Error)
                 throw (Error)e;
-        }
-
-        String json;
 
-        try {
-            json = jsonMapper.writeValueAsString(cmdRes);
+            cmdRes = new GridRestResponse(STATUS_FAILED, e.getMessage());
         }
-        catch (JsonProcessingException e1) {
-            U.error(log, "Failed to convert response to JSON: " + cmdRes, e1);
 
-            GridRestResponse resFailed = new GridRestResponse(STATUS_FAILED, e1.getMessage());
+        try {
+            ServletOutputStream os = res.getOutputStream();
 
             try {
-                json = jsonMapper.writeValueAsString(resFailed);
+                jsonMapper.writeValue(os, cmdRes);
             }
-            catch (JsonProcessingException e2) {
-                json = "{\"successStatus\": \"1\", \"error:\" \"" + e2.getMessage() + "\"}}";
-            }
-        }
-
-        try {
-            if (log.isDebugEnabled())
-                log.debug("Parsed command response into JSON object: " + json);
+            catch (JsonProcessingException e) {
+                U.error(log, "Failed to convert response to JSON: " + cmdRes, e);
 
-            res.getWriter().write(json);
+                jsonMapper.writeValue(os, F.asMap("successStatus", STATUS_FAILED, "error",
e.getMessage()));
+            }
 
             if (log.isDebugEnabled())
                 log.debug("Processed HTTP request [action=" + act + ", jsonRes=" + cmdRes
+ ", req=" + req + ']');
         }
         catch (IOException e) {
-            U.error(log, "Failed to send HTTP response: " + json, e);
+            U.error(log, "Failed to send HTTP response: " + cmdRes, e);
         }
     }
 


Mime
View raw message