From 9fb93a3a794723d6a5aa9fbc1edd2cdcd8c33507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Tue, 25 Nov 2014 11:20:19 -0800 Subject: [PATCH] fix smile exception on error + content-type --- .../main/java/io/druid/server/QueryResource.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/io/druid/server/QueryResource.java b/server/src/main/java/io/druid/server/QueryResource.java index 9a6eca65ef2..6075d628db9 100644 --- a/server/src/main/java/io/druid/server/QueryResource.java +++ b/server/src/main/java/io/druid/server/QueryResource.java @@ -126,6 +126,7 @@ public class QueryResource String queryId = null; final boolean isSmile = APPLICATION_SMILE.equals(req.getContentType()); + final String contentType = isSmile ? APPLICATION_SMILE : APPLICATION_JSON; ObjectMapper objectMapper = isSmile ? smileMapper : jsonMapper; final ObjectWriter jsonWriter = req.getParameter("pretty") == null @@ -209,7 +210,7 @@ public class QueryResource outputStream.close(); } }, - isSmile ? APPLICATION_SMILE : APPLICATION_JSON + contentType ) .header("X-Druid-Query-Id", queryId) .header("X-Druid-Response-Context", jsonMapper.writeValueAsString(responseContext)) @@ -249,10 +250,10 @@ public class QueryResource catch (Exception e2) { log.error(e2, "Unable to log query [%s]!", query); } - return Response.serverError().entity( - jsonWriter.writeValueAsString( + return Response.serverError().type(contentType).entity( + jsonWriter.writeValueAsBytes( ImmutableMap.of( - "error", e.getMessage() + "error", e.getMessage() == null ? "null exception" : e.getMessage() ) ) ).build(); @@ -285,8 +286,8 @@ public class QueryResource .addData("peer", req.getRemoteAddr()) .emit(); - return Response.serverError().entity( - jsonWriter.writeValueAsString( + return Response.serverError().type(contentType).entity( + jsonWriter.writeValueAsBytes( ImmutableMap.of( "error", e.getMessage() == null ? "null exception" : e.getMessage() )