Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
2 replies Latest Post - ‏2012-05-16T07:13:13Z by X75J_Li_Yanli
SystemAdmin
SystemAdmin
2233 Posts
ACCEPTED ANSWER

Pinned topic IllegalStateException in my local URL rewrite filtering

‏2011-10-31T08:26:47Z |
Hello all,

I am developing a system on WAS CE 2.1.1.5 (not the latest one for a contract reason). I am using our own very simple URL rewrite filtering component (for copyright reason). It has only simple forwarding function and successfully runs on WAS 7.0 and Tomcat. But its filtering on WAS CE sometimes fails with the following exception:

java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:312)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at com.ibm.accessibility.filters.UrlRewriter.process(UrlRewriter.java:67)
at com.ibm.accessibility.filters.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.geronimo.tomcat.valve.DefaultSubjectValve.invoke(DefaultSubjectValve.java:56)
at org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:406)
at org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:47)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
at org.apache.geronimo.tomcat.valve.ThreadCleanerValve.invoke(ThreadCleanerValve.java:40)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:736)

I set only one filter in the web.xml of my system as follows. I also attach our URL rewrite filter codes:

web.xml
...
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>filters.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
...

The trace log says that the isCommitted flag has already been true when the filter is invoked as follows:

2011-10-31 17:15:44,590 TRACE http-0.0.0.0-8080-1:StandardWrapper Returning non-STM instance
2011-10-31 17:15:44,591 DEBUG http-0.0.0.0-8080-1:UrlRewriteFilter Response has been already committed!!!

The second log is written just after UrlRewriteFilter.doFilter is invoked. I think there is another hidden filter which handles the response but I can't find it even in the detailed trace log using log4j.

Could anyone let me know what happens and what is wrong?

Thanks a lot in advance...
Updated on 2012-05-16T07:13:13Z at 2012-05-16T07:13:13Z by X75J_Li_Yanli
  • Forrest_Xia
    Forrest_Xia
    82 Posts
    ACCEPTED ANSWER

    Re: IllegalStateException in my local URL rewrite filtering

    ‏2011-12-09T02:18:31Z  in response to SystemAdmin
    Hi,
    Can you provide a runnable sample with this issue? so that we can investigate it easily.

    Forrest
  • X75J_Li_Yanli
    X75J_Li_Yanli
    45 Posts
    ACCEPTED ANSWER

    Re: IllegalStateException in my local URL rewrite filtering

    ‏2012-05-16T07:13:13Z  in response to SystemAdmin
    Hello,

    1. According to your sample attachment:Custom-UrlRewriteFilter.zip, I created a dynamic web project like yours which including a servlet named UrlRewriter, two java files named UrlRewriteFilter and UrlRewriteRule.

    2 .I also created two web pages named index.html and test.jsp, if access index.html it will print "Say Hello!" on web page, if access test.jsp, it will print "Say Hello JSP!"

    3. I also add the urlwrite.xml which is the same role of file urlrewriterules.xml that you mentioned in class UrlRewriter:
    InputStream is = context.getResourceAsStream("/WEB-INF/urlrewriterules.xml");

    4. For the urlwrithe.xml, the content is simple and like this:
    <?xml version="1.0" encoding="utf-8"?>
    <urlrewrite>
    <rule>
    <name>Test Rule1</name>
    <note>A test rule to show a simple redirect.</note>
    <from>/index.html</from>
    <to type="redirect">/test.jsp</to>
    </rule>
    </urlrewrite>

    5.Export the project as a WAR, and deployed on wasce 2.1.1.5, and access the url:
    http://localhost:8080/UrlRewriteFilterTest2115/index.html
    Then you can see the result is :
    Say Hello JSP!
    And can't reproduce this problem as you described.

    6. The project I created is attached and please support your urlrewriterules.xml file which will be helpful to reproduce this problem.

    Thanks!