In Struts 6.2 I am using urlrewrite 4.0.3 with below config. ( explained at How to map a friendly URL to the action in Struts 2 answer)
<urlrewrite>
<rule match-type="regex">
<from>/callback/hamoon-handler.ib/sign/(\w+)</from>
<to>/callback/hamoon-handler.ib?sign=$1</to>
</rule>
</urlrewrite>
This will not work. To test I used curl to make some tests.
Below curl works ( which shows the struts action is mapped corretly):
curl "https://localhost/callback/hamoon-handler.ib?sign/v1" --header "Content-Type: application/json" --data "{ \"test\": \"1\"}"
but below ( which goes throw urlrewrite does not) and I get the error The requested resource [/callback/hamoon-handler.ib] is not available
:
curl "https://localhost/callback/hamoon-handler.ib/sign/v1" --header "Content-Type: application/json" --data "{ \"test\": \"1\"}"
I see this in the log ( which shows that the rewriting is done correctly) :
utils.ServerNameMatcher DEBUG: looking for hostname match on current server name localhost
UrlRewriteFilter DEBUG: checking for status path on /callback/hamoon-handler.ib/sign/v1
UrlRewriter DEBUG: processing request for /callback/hamoon-handler.ib/sign/v1
RuleBase DEBUG: Rule 0 run called with /callback/hamoon-handler.ib/sign/v1
RuleBase DEBUG: matched "from"
substitution.MatcherReplacer DEBUG: found 1
substitution.MatcherReplacer DEBUG: replaced sb is /callback/hamoon-handler.ib?sign=v1
RuleExecutionOutput DEBUG: needs to be redirected to /callback/hamoon-handler.ib?sign=v1
UrlRewriter TRACE: got a rewritten url
RewrittenUrl TRACE: doRewrite called
RewrittenUrl TRACE: redirected to /callback/hamoon-handler.ib?sign=v1
To make a test I have change <to>
to <to type="redirect">
. and add -L
to curl
to follow redirects, by this change the action is found. (But I can not use this as my caller does not support redirect)
The UrlRewriteFilter
is defined before StrutsPrepareAndExecuteFilter
The web.xml
is:
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>TRACE</param-value>
</init-param>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</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>
</filter-mapping>
Is there any way I can fix it.