servletsurl-rewritingservlet-filtersurl-mappingtuckey-urlrewrite-filter

How to add .do extension to incoming requests using URLRewriting filter


I've just installed the URL-rewriting filter from http://tuckey.org/.

I have added a rule to add .do for requests coming on a specific path /beta.

  <rule>
        <from>(.*)/beta/(.*)\?(.*)</from>
        <to>$1/beta/$2.do\?$3</to>
    </rule>

    <rule>
        <from>(.*)/beta/(.*)</from>
        <to>$1/beta/$2.do</to>
    </rule>

The rules configuration goes to state OK, so it has successfully loaded.

Unfortunately, now I see an exception stacktrace in the log that is over 5000 lines long and seems to be stuck in a loop.

017-03-08 13:50:15.827 [0.0-8080-1] ERROR JSPException              [0966E] Exception trapped when showing Error Page! Filter execution threw an exception
javax.servlet.ServletException: Filter execution threw an exception
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:259) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) ~[urlrewritefilter-4.0.3.jar:4.0.3]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)]
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292) ~[tmp7900369758995902766jbossweb.jar:4.2.3.GA (build: 

And on it goes...


Solution

  • Seems your rules recursively cycling because the destination url match a regex in the <from> clause. Try to rewrite regex to match only from expression, not to resulting url. I.e.

    <rule>
        <from>(.*)/beta/(.*)</from>
        <to>$1/beta2/$2.do</to>
    </rule>
    

    For more detailed info see this guide URL Rewriting for Beginners.