IllegalStateException in filter(Cannot forward. Response alreadycommitted) - Websphere

This is a discussion on IllegalStateException in filter(Cannot forward. Response alreadycommitted) - Websphere ; I am converting some web apps from WAS 5.1 to 6.1 and have encountered a problem. We use a servlet filter to imbed a web page header and footer into our web pages. The code (below - ignore the comments ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: IllegalStateException in filter(Cannot forward. Response alreadycommitted)

  1. IllegalStateException in filter(Cannot forward. Response alreadycommitted)

    I am converting some web apps from WAS 5.1 to 6.1 and have encountered a problem.



    We use a servlet filter to imbed a web page header and footer into our web pages. The code (below - ignore the comments and debugging code ;>) works fine in WAS 5.1, but in WAS 6.1 it appears that the sequence of events has changed and it no longer works. The problem appears to be related to going to a default or welcome page in a WebSphere app.



    Example:



    In WAS 5.1: After keying in http://servername/login (which is forwarded to index.jsp) within the login app, this filter sees/obtains the text for the index.jsp page and wraps text around it.


    In WAS 6.1: After keying in http://servername/login (which is forwarded to index.jsp) within the login app, this filter DOESN'T (never) see the text for the index.jsp page. It looks like WAS 6.1 is doing the forward to index.jsp after the filters are invoked. If we go directly to the page (http://servername/login/index.jsp) the filter works.



    We have a lot of links in our applications where we don't code a default page and we'd prefer not to hard code links to default pages if possible. Also we don't want users having to be concerned about the individual pages they go to in an app.



    What's different about WAS 6.1? Is this change in behavior intentional? Do we now have to code links directly to all of our pages? We'd like to do this migration as unobtrusively as possible.


    Here's the code and the error (excuse the commented out and debugging code):



    CODE:



    String contentType = response.getContentType();

    //String contentType = wrapper.getContentType();

    LOGGER.debug("doFilter - Content Type: " + contentType);

    if (contentType != null && contentType.toLowerCase().startsWith("text")) {

    String outStr = null;

    LOGGER.debug("doFilter - Wrapper Content Type: "

    + contentType);

    if (contentType.toLowerCase().startsWith("text/html")) {

    CharArrayWriter caw = new CharArrayWriter();



    // Add header

    caw.write((String) header.get(language));

    // Add body

    caw.write(wrapper.toString());

    // Add footer

    caw.write((String) footer.get(language));

    // Write to browser

    outStr = caw.toString();

    } else {

    outStr = wrapper.toString();

    }

    // response.setContentLength(outStr.length());

    LOGGER.debug("doFilter - ContentLength: " + outStr.length());

    PrintWriter out = response.getWriter();

    boolean isComm = response.isCommitted();

    out.write(outStr);

    isComm = response.isCommitted();

    out.close();

    isComm = response.isCommitted();

    }

    ERROR:



    11/26/07 9:23:22:669 PST 0000002c WebApp E Servlet Error-http://Cannot forward. Response already committed.: java.lang.IllegalStateException: Cannot forward. Response already committed.

    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispat cher.forward(WebAppRequestDispatcher.java:157)

    at com.ibm.ws.webcontainer.extension.DefaultExtension Processor.handleRequest(DefaultExtensionProcessor. java:555)

    at com.ibm.ws.wswebcontainer.extension.DefaultExtensi onProcessor.handleRequest(DefaultExtensionProcesso r.java:113)


  2. Re: IllegalStateException in filter(Cannot forward. Responsealready commit

    Just wasted 1/2 a day with exactly the same issue - and you are right it is forwarding to the "welcome list" regardless of what the filter does. I have removed my welcome file list. This is definitely a bug.



    Regards

    Stan

  3. Re: IllegalStateException in filter(Cannot forward. Responsealready commit

    Hi,


    I get the same error since was 6.1. I first had HTTP 404 page cannot be found, so I regenerated the web server plugin and now I get:

    [Servlet Error]-[Cannot forward. Response already committed.]: java.lang.IllegalStateException: Cannot forward. Response already committed.
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispat cher.forward(WebAppRequestDispatcher.java:157)
    at com.ibm.ws.webcontainer.extension.DefaultExtension Processor.handleRequest(DefaultExtensionProcessor. java:581)
    at com.ibm.ws.wswebcontainer.extension.DefaultExtensi onProcessor.handleRequest(DefaultExtensionProcesso r.java:113)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleReques t(WebApp.java:3391)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequ est(WebGroup.java:267)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest (WebContainer.java:811)
    at com.ibm.ws.wswebcontainer.WebContainer.handleReque st(WebContainer.java:1455)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.read y(WCChannelLink.java:115)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.handleDiscrimination(HttpInboundLink.java:458)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.handleNewInformation(HttpInboundLink.java:387)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.ready(HttpInboundLink.java:267)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialRe adCallback.sendToDiscriminators(NewConnectionIniti alReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialRe adCallback.complete(NewConnectionInitialReadCallba ck.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListe ner.futureCompleted(AioReadCompletionListener.java :165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallbac k(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletion Actions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture .java:136)
    at com.ibm.io.async.ResultHandler.complete(ResultHand ler.java:195)
    at com.ibm.io.async.ResultHandler.runEventProcessingL oop(ResultHandler.java:743)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler .java:873)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.j ava:1473)

  4. Re: IllegalStateException in filter(Cannot forward. Responsealready commit

    Could you show the "filter-mapping" portion of your web.xml please?

  5. Re: IllegalStateException in filter(Cannot forward. Response alreadycommitted)

    If the response is an error, such as 404 then it's already committed is committed early via the SendError() function. You should override this in your wrapper and do nothing.

    Have a look at this article
    http://codediaries.blogspot.com/2009...va-filter.html

  6. Re: IllegalStateException in filter(Cannot forward. Response alreadycommitted)

    The response for errors such as 404, are committed early throught the SendError() function. You should override this in your wrapper and do nothing.

+ Reply to Thread