1
votes

In a java web-app I write to my HttpServletResponse:

httpResponse.getWriter().write(someJsonString);
httpResponse.getWriter().flush();

The client (apache jmeter in this case) gets the response with the json in the body and status 200 as expected.

If I decide to change the response status:

httpResponse.getWriter().write(someJsonString);
httpResponse.setStatus(Response.Status.NO_CONTENT.getStatusCode());
httpResponse.getWriter().flush();

My client gets the response with the right status (204 in this case) but an empty body for some reason.

What can cause this?

1
Try setting the status first. Ut ti doesn't make sense to send some content and set a header that says there is no content.user207421
Are you manually adding the status code for all response as "No_Content" status code.?Kannan_SJD
@EJP tried that - same result.forhas
@Kannan_SJD What do you mean to "all responses"? I do add to some manually, yes.forhas

1 Answers

0
votes

When you send response as 204, it means there is no body. See w3c rfc

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

It means while sending response either container is not considering body or your client is discarding after reading status in response.

One way could be to check this response in web-browser if possible. With tools like fire-bug or similar in Chrome you could actual check response.