Skip to content

Commit

Permalink
Added support for byte array response
Browse files Browse the repository at this point in the history
  • Loading branch information
regunathb committed Apr 24, 2017
1 parent d636c11 commit 114f5be
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,17 @@ private void buildResponse(PoseidonRequest request, PoseidonResponse poseidonRes
httpResponse.setStatus(statusCode);
Object responseObj = poseidonResponse.getResponse();
if (responseObj != null) {
String responseStr = "";
if (responseObj instanceof String) {
responseStr = (String) responseObj;
httpResponse.getWriter().println((String)responseObj);
} else if (responseObj instanceof byte[]) {
byte[] rawBytes = (byte[])responseObj;
// we override default response meta-data as the data is raw bytes
httpResponse.setContentType(MediaType.OCTET_STREAM.toString());
httpResponse.setContentLength(rawBytes.length);
httpResponse.getOutputStream().write(rawBytes);
} else {
responseStr = configuration.getObjectMapper().writeValueAsString(responseObj);
httpResponse.getWriter().println(configuration.getObjectMapper().writeValueAsString(responseObj));
}
httpResponse.getWriter().println(responseStr);
}
}

Expand Down

0 comments on commit 114f5be

Please sign in to comment.