Doahh
Doahh

Reputation: 590

Tuckey UrlRewriteFilter and Struts2 gives 404 on first request

About 30 of my rewritten links work fine but I have a couple that don't work the first time they are called but they do work the second time!

This is the web.xml snippets:

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    <init-param>
        <param-name>actionPackages</param-name>
        <param-value>uk.co.prodia.prosoc.struts2.action</param-value>
    </init-param>
</filter>
<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

and here is the urlrewrite.xml that gives a 404 the first time it is called:

<rule>
    <from>^/forgotten-password$</from>
    <to>/unsecured/forgotten-password!input.action</to>
</rule>

and the struts2 config for that action:

<package name="unsecured" extends="struts-default" namespace="/unsecured">
    <action name="forgotten-password" class="actionForgottenPassword">
        <result name="input">/WEB-INF/view/unsecured/forgotten-password.jsp</result>
        <result name="passwordNotFound">/WEB-INF/view/unsecured/forgotten-password.jsp</result>
    </action>
</package>

However if I make the urlrewrite.xml pass through the unsecured package which contains the forgotten-password action then it works:

<rule>
    <from>^/unsecured/forgotten-password$</from><!--works through /unsecured -->
    <to>/unsecured/forgotten-password!input.action</to>
</rule>

It seems that missing of the Struts2 package name from the urlrewrite causes the 404 the first time the URI is used.

Does this make any sense to anyone or shall I just stay in crazy town?

Upvotes: 0

Views: 907

Answers (1)

Doahh
Doahh

Reputation: 590

The problem seems to be caused by the jsessionid in the URL on the first page load of the context. I am a bit useless with regexp but this seems to work:

<rule>
    <from>^/forgotten-password(;jsessionid=.*)?$</from>
    <to>/unsecured/forgotten-password!input.action</to>
</rule>

I added the (;jsessionid=.*)? to the end of each of the rules and it seems to work.

Upvotes: 1

Related Questions