Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-3695

'Cannot set header. Response already committed.' on WebSphere Application Server 7 and 8

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.10
    • Fix Version/s: 2.0.17, 2.1.11
    • Component/s: JSR-314
    • Labels:
      None
    • Environment:
      WebSphere Application Server 7 or 8

      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

      { 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.

        Attachments

          Activity

            People

            • Assignee:
              lu4242 Leonardo Uribe
              Reporter:
              jack_van_ooststroom Jack van Ooststroom
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: