myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonardo Uribe (JIRA)" <...@myfaces.apache.org>
Subject [jira] [Commented] (MYFACES-3695) 'Cannot set header. Response already committed.' on WebSphere Application Server 7 and 8
Date Thu, 14 Feb 2013 19:15:13 GMT

    [ https://issues.apache.org/jira/browse/MYFACES-3695?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13578583#comment-13578583
] 

Leonardo Uribe commented on MYFACES-3695:
-----------------------------------------

This issue has been widely discussed in MYFACES-3104, but I can see here a new element. 

JSF 2.0 spec says this about handling resources:

"...
-  Pass the result of Resource.getContentType() to HttpServletResponse.setContentType.

- Call Resource.getResponseHeaders(). For each entry in this Map, call HttpServletResponse.setHeader(),
passing the key as the first argument and the value as the second argument.

- Call Resource.getInputStream() and serve up the bytes of the resource to the response.

- Call HttpServletResponse.setContentLength() passing the byte count of the resource. ..."

So by the spec, setContentLength() is called after the bytes are served, because otherwise
there is no way to know how many bytes are served to the response. 

Maybe we could use a JSF2_STRICT config param for that. ....
                
> '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

Mime
View raw message