In Mule 2.1.0 the following code was added to this method:
org.mule.transport.servlet.AbstractReceiverServlet.writeResponse(HttpServletResponse servletResponse, MuleMessage message)
if (message.getPayload() instanceof InputStream)
{
httpResponse.setBody((OutputHandler) message.getPayload(OutputHandler.class));
}
else
{
httpResponse.setBody(message.getPayloadAsString());
}
This seems like it was intended to replace the previous way of setting the body, which was this line of code:
httpResponse.setBody(message);
The problem though is that both of these are in the current Mule 2.1.0 AbstractReceiverServlet, causing setBody to be called twice. The second setBody is happening a few lines after the first on line 150.
This sets the content length and the output buffer content twice (once before setting the HTTP status, and once after) and causes problems with HTTP requests made with the 'Connection: Keep-Alive' header or requests made without a Connection header (which defaults to Keep-Alive). In this case the output stream isn't received by the client until the HTTP connection finally times out after a minute or so.
I looked in the code a bit, but couldn't pinpoint the exact cause of the problem that creates the symptom I describe, but it nonetheless seems like there's no reason why setBody should be getting called twice. I over-rode the 'writeResponse' method in a servlet of mine (thanks for having it be protected
) and removed the second setBody call, and the problem I was seeing went away. Hence I think this call should be removed.
Thanks Bill for reporting this!