Repository: ignite
Updated Branches:
  refs/heads/ignite-6012 [created] a0fe6ea46


IGNITE-6012 Refactored GridJettyRestHandler.processRequest(): replace 
mapper.writeValueAsString with writeValue(outputStream, v).


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

Branch: refs/heads/ignite-6012
Commit: a0fe6ea46c54f4c256435644c6954cc4658b7b17
Parents: 8d6e842
Author: Alexey Kuznetsov <akuznet...@apache.org>
Authored: Wed Aug 9 21:00:51 2017 +0700
Committer: Alexey Kuznetsov <akuznet...@apache.org>
Committed: Wed Aug 9 21:00:51 2017 +0700

----------------------------------------------------------------------
 .../http/jetty/GridJettyRestHandler.java        | 35 +++++++++-----------
 1 file changed, 16 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a0fe6ea4/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..b1c5577 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
@@ -17,7 +17,8 @@
 
 package org.apache.ignite.internal.processors.rest.protocols.http.jetty;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import java.io.BufferedInputStream;
 import java.io.ByteArrayOutputStream;
@@ -34,6 +35,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;
@@ -362,35 +364,30 @@ public class GridJettyRestHandler extends AbstractHandler 
{
                 throw (Error)e;
         }
 
-        String json;
-
         try {
-            json = jsonMapper.writeValueAsString(cmdRes);
-        }
-        catch (JsonProcessingException e1) {
-            U.error(log, "Failed to convert response to JSON: " + cmdRes, e1);
-
-            GridRestResponse resFailed = new GridRestResponse(STATUS_FAILED, 
e1.getMessage());
+            ServletOutputStream os = res.getOutputStream();
 
             try {
-                json = jsonMapper.writeValueAsString(resFailed);
+                jsonMapper.writeValue(os, cmdRes);
             }
-            catch (JsonProcessingException e2) {
-                json = "{\"successStatus\": \"1\", \"error:\" \"" + 
e2.getMessage() + "\"}}";
-            }
-        }
+            catch (JsonGenerationException | JsonMappingException e1) {
+                U.error(log, "Failed to convert response to JSON: " + cmdRes, 
e1);
 
-        try {
-            if (log.isDebugEnabled())
-                log.debug("Parsed command response into JSON object: " + json);
+                GridRestResponse resFailed = new 
GridRestResponse(STATUS_FAILED, e1.getMessage());
 
-            res.getWriter().write(json);
+                try {
+                    jsonMapper.writeValue(os, resFailed);
+                }
+                catch (JsonGenerationException | JsonMappingException e2) {
+                    jsonMapper.writeValue(os, "{\"successStatus\": \"1\", 
\"error:\" \"" + e2.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);
         }
     }
 

Reply via email to