Jack van Ooststroom created MYFACES-3695:
--------------------------------------------
Summary: 'Cannot set header. Response already committed.' on
WebSphere Application Server 7 and 8
Key: MYFACES-3695
URL: https://issues.apache.org/jira/browse/MYFACES-3695
Project: MyFaces Core
Issue Type: Bug
Components: JSR-314
Affects Versions: 2.1.10
Environment: WebSphere Application Server 7 or 8
Reporter: Jack van Ooststroom
When trying to handle a resource using the default implementation of
ResourceHandler, namely ResourceHandlerImpl, a warning message is logged when
running on WebSphere Application Server 7 or 8:
W com.ibm.ws.webcontainer.srt.SRTServletResponse setIntHeader SRVE8094W:
WARNING: Cannot set header. Response already committed.
Looking at the code of ResourceHandlerImpl.handleResourceRequest(FacesContext
context) I found the following snippet:
try
{
InputStream in = resource.getInputStream();
OutputStream out = httpServletResponse.getOutputStream();
//byte[] buffer = new byte[_BUFFER_SIZE];
byte[] buffer = new byte[this.getResourceBufferSize()];
try
{
int count = pipeBytes(in, out, buffer);
//set the content lenght
httpServletResponse.setContentLength(count);
}
finally
{
try
{
in.close();
}
finally
{
out.close();
}
}
}
If the resource is small enough and the buffer limit is not reached everything
should be fine (default size seems 2048), however if the resource is bigger the
buffer gets flushed WebSphere Application Server will use chunked encoding and
the httpServletResponse.setContentLength(count) gets executed after the fact
resulting in the mentioned message. Setting the
org.apache.myfaces.RESOURCE_BUFFER_SIZE context parameter is a possible
workaround, but it would be better to avoid this as resource sizes can be
unpredictable.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira