Details
Description
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
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.