Rewrite Query String in UrlRewriteFilter 3.0

193 views
Skip to first unread message

Skitch

unread,
Jun 20, 2011, 10:01:09 AM6/20/11
to UrlRewrite
I'm having an issue where I'm trying to remap a query string in
version 3.0. Based on the solution provided at
http://blog.gomilko.com/2007/07/16/playing-with-urlrewrite-filter

The issue is that the rule doesn't seem to fire and everything seems
to break.

Now if I include, "use-query-string" in the urlrewrite dom, the rule
does execute, but it goes into an endless loop firing the rule over
and over again. Any ideas?

Basically my rule is :

<rule>
<from>^(.+)$</from>
<run class="com.service.util.RequestToAttributeSetter">
<init-param>
<param-name>parameterName</param-name>
<param-value>queryString</param-value>
</init-param>
</run>
</rule>

<rule>
<from>^/service/(.+)?(.*)$</from>
<to>^/service/$1?%{attribute:queryString}</to>
</rule>

Ondřej Světlík

unread,
Jun 21, 2011, 2:42:37 AM6/21/11
to urlre...@googlegroups.com
Dne 20.6.2011 16:01, Skitch napsal(a):

Hi there,

take a look into your web.xml, what dispatchers are configured in
filter-mapping:

<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>

If you have also FORWARD dispatcher configured, remove it. Unless you
really know what you are doing :-). I'm using 3.0.4 because 3.2 is not
in maven repository and this is what caused endless loops and other
strange behaviour in my projects.

Also, I don't know what your RequestToAttributeSetter does, but if it
only sets the request-uri to queryString attribute, you can do it
without a class:

<rule>
<from>.*</from>
<set name="contextPath">%{context-path}</set>
<set name="requestPath">%{request-uri}</set>
</rule>

This works for me.

Regards,

Ondrej

Skitch

unread,
Jun 21, 2011, 10:43:36 AM6/21/11
to UrlRewrite
Ok I figured out some issues and now consider myself a Urlrewrite guru
XD.

My main goal was to translate an existing Python API to our Java
Search API and using urlrewrite to allow users to format the url's as
normal. Since the search query parameter syntax is quite different I
needed to modify the queries pretty heavily.

Some things I did:
1 - Upgraded to 3.2
2 - Patched UrlRewriteWrappedResponse and URlRewriteWrappedRequest
with 4.0 code, (so overridden params are treated as HashMap<String,
String[]>, rather than <String, String>)
- I don't necessarily enjoy patching, but this was needed and
I see the dev's were in the right direction, but maybe haven't gotten
to it.
- 4.0 code still only accepts a single String param as the
value of the hash and then wraps it in a String[]{}
- Also it keeps the original params completely separate from
the overridden params, but I see this as a loss in functionality
because if I want to edit the key of a param, I cannot delete the
original. Probably going to add that functionality myself.

3 - Implemented a QueryParameterSetter instead that accepts a String[]
paramater of ignore fields. This will take all parameters from the
existing URL and modify them to work with the Search query syntax.
Reply all
Reply to author
Forward
0 new messages