UrlRewrite not working for Grails?

78 views
Skip to first unread message

J

unread,
Jul 16, 2008, 8:54:12 AM7/16/08
to UrlRewrite
I'm trying to get the Grails webframework working with Tuckey's Url
Rewrite Filter, but somehow Grails doesn't seem to accept a simple
rule.

Versions:
-UrlRewriteFilter 2.6 and 3.1.0
-Grails 1.0.3
-Webserver: tested both Jetty 6.1.4 and Tomcat 6.0.14

Settings:
-I configured UrlReWriteFilter as first filter in web.xml.
-urlrewrite.xml has the rule: <rule><from>/mytest</from><to>/products/
index</to></rule>, and a similar outbound rule.

Results:
Browsing to http://localhost:8080/webapp/products/index will directly
show the Grails page bypassing urlrewrite because no inbound rules are
configured for that URL. When browsing to http://localhost:8080/webapp/mytest,
the rule is found by UrlRewrite, but somehow a 404 error pops up. The
404 error shows: "The requested resource (/webapp/products/index) is
not available". Which is strange because that url does work when
directly browsing to it.

I also testing it further with ROOT (empty) context, so the context
should not be the problem. (Also I didn't have any problem when using
simple servlets instead of Grails.)

The outbound rule does work without problems.





Any idea's what's going wrong?

Lucas F. A. Teixeira

unread,
Jul 16, 2008, 8:55:45 AM7/16/08
to urlre...@googlegroups.com
The Grails default mechanism for urlrewrite doest not fit to you?

[]s,

Lucas
--
Lucas F. A. Teixeira .·.
luca...@gmail.com

J

unread,
Jul 16, 2008, 9:26:17 AM7/16/08
to UrlRewrite
I like it that Grails has urlmappings (compared to other
webframeworks), but it is not as advanced/flexible as Tuckeys
UrlRewriteFilter. For example, Grails doesn't support regex in
urlmapping method names, only wildcards and tokens are supported
there. It does support regex in urlmapping constraints, but not in the
method names.

But the case in my first post should work, right? Grails should have
no knowledge that URLs are being rewritten by UrlRewriteFilter.



On 16 jul, 14:55, "Lucas F. A. Teixeira" <lucas...@gmail.com> wrote:
> The Grails default mechanism for urlrewrite doest not fit to you?
> []s,
>
> Lucas
>
>
>
>
>
> On Wed, Jul 16, 2008 at 9:54 AM, J <lowb...@gmail.com> wrote:
>
> > I'm trying to get the Grails webframework working with Tuckey's Url
> > Rewrite Filter, but somehow Grails doesn't seem to accept a simple
> > rule.
>
> > Versions:
> > -UrlRewriteFilter 2.6 and 3.1.0
> > -Grails 1.0.3
> > -Webserver: tested both Jetty 6.1.4 and Tomcat 6.0.14
>
> > Settings:
> > -I configured UrlReWriteFilter as first filter in web.xml.
> > -urlrewrite.xml has the rule: <rule><from>/mytest</from><to>/products/
> > index</to></rule>, and a similar outbound rule.
>
> > Results:
> > Browsing tohttp://localhost:8080/webapp/products/indexwill directly
> > show the Grails page bypassing urlrewrite because no inbound rules are
> > configured for that URL. When browsing to
> >http://localhost:8080/webapp/mytest,
> > the rule is found by UrlRewrite, but somehow a 404 error pops up. The
> > 404 error shows: "The requested resource (/webapp/products/index) is
> > not available". Which is strange because that url does work when
> > directly browsing to it.
>
> > I also testing it further with ROOT (empty) context, so the context
> > should not be the problem. (Also I didn't have any problem when using
> > simple servlets instead of Grails.)
>
> > The outbound rule does work without problems.
>
> > Any idea's what's going wrong?
>
> --
> Lucas F. A. Teixeira .·.
> lucas...@gmail.com- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

J

unread,
Jul 16, 2008, 11:10:23 AM7/16/08
to UrlRewrite
Here the complete debug log.


====== BOOT STRAP ====================
[1390] mapping.DefaultUrlMappingsHolder Reverse mapping:
[DefaultUrlMappingsHolder.UrlMappingKey@1087359 controller = [null],
action = [null], params = set[[empty]]] ->
org.codehaus.groovy.grails.web.mapping.ResponseCodeUrlMapping@1ccf342
[1390] mapping.DefaultUrlMappingsHolder Reverse mapping:
[DefaultUrlMappingsHolder.UrlMappingKey@7691c0 controller = [null],
action = [null], params = set['controller']] -> /(*)/(*)?/(*)?
[1390] mapping.DefaultUrlMappingsHolder Reverse mapping:
[DefaultUrlMappingsHolder.UrlMappingKey@5b02a6 controller = [null],
action = [null], params = set['action', 'controller']] -> /(*)/(*)?/
(*)?
[1392] mapping.DefaultUrlMappingsHolder Reverse mapping:
[DefaultUrlMappingsHolder.UrlMappingKey@10aefdb controller = [null],
action = [null], params = set['id', 'action', 'controller']] -> /(*)/
(*)?/(*)?
[2855] mapping.DefaultUrlMappingsHolder Reverse mapping:
[DefaultUrlMappingsHolder.UrlMappingKey@154145 controller = [null],
action = [null], params = set[[empty]]] ->
org.codehaus.groovy.grails.web.mapping.ResponseCodeUrlMapping@17035c6
[2855] mapping.DefaultUrlMappingsHolder Reverse mapping:
[DefaultUrlMappingsHolder.UrlMappingKey@1da997a controller = [null],
action = [null], params = set['controller']] -> /(*)/(*)?/(*)?
[2855] mapping.DefaultUrlMappingsHolder Reverse mapping:
[DefaultUrlMappingsHolder.UrlMappingKey@921a90 controller = [null],
action = [null], params = set['action', 'controller']] -> /(*)/(*)?/
(*)?
[2856] mapping.DefaultUrlMappingsHolder Reverse mapping:
[DefaultUrlMappingsHolder.UrlMappingKey@de648 controller = [null],
action = [null], params = set['id', 'action', 'controller']] -> /(*)/
(*)?/(*)?
2008-07-16 17:00:18.624:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.utils.Log DEBUG: logLevel set to
DEBUG
2008-07-16 17:00:18.624:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: confPath set
to /WEB-INF/urlrewrite.xml
2008-07-16 17:00:18.638:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.Conf DEBUG: XML builder factory is:
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
2008-07-16 17:00:18.641:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.Conf DEBUG: XML Parser:
org.apache.xerces.jaxp.DocumentBuilderImpl
2008-07-16 17:00:18.641:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.Conf DEBUG: about to parse conf
2008-07-16 17:00:18.642:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.ConfHandler DEBUG: Resolving to DTD /
org/tuckey/web/filters/urlrewrite/dtds/urlrewrite3.1.dtd
2008-07-16 17:00:18.658:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.Conf DEBUG: now initialising conf
2008-07-16 17:00:18.664:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: loaded rule Rule 0 (/
mytest, /products/index 1)
2008-07-16 17:00:18.664:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.NormalRule DEBUG: loaded rule Rule 0
(/mytest, /products/index 1)
2008-07-16 17:00:18.664:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: inited with
1 rules
2008-07-16 17:00:18.664:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: conf is ok
2008-07-16 17:00:18.666:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter INFO: loaded (conf
ok)
2008-07-16 17:00:18.735:/webapp:INFO: Initializing Spring
FrameworkServlet 'grails'
2008-07-16 17:00:18.904::INFO: Started
SelectChann...@0.0.0.0:8080
Server running. Browse to http://localhost:8080/webapp

=========== Direct Grails URL request (/webapp/products/index)
=====================
2008-07-16 17:00:31.578:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.utils.ServerNameMatcher DEBUG:
looking for hostname match on current server name localhost
2008-07-16 17:00:31.580:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: checking for
status path on /webapp/products/index
2008-07-16 17:00:31.580:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: processing
request for /webapp/products/index
2008-07-16 17:00:31.580:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: context removed
from url
2008-07-16 17:00:31.584:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 0 run called
with /products/index
[16217] mapping.DefaultUrlMappingsHolder Attempting to match URI [/
products/index] with pattern [500]
[16218] mapping.DefaultUrlMappingsHolder Attempting to match URI [/
products/index] with pattern [/(*)/(*)?/(*)?]
[16237] mapping.DefaultUrlMappingsHolder Matched URI [/products/index]
with pattern [/(*)/(*)?/(*)?], adding to posibilities

=========== Rewritten URL request (/webapp/mytest) ==================
2008-07-16 17:00:41.417:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.utils.ServerNameMatcher DEBUG:
looking for hostname match on current server name localhost
2008-07-16 17:00:41.417:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: checking for
status path on /webapp/mytest
2008-07-16 17:00:41.417:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: processing
request for /webapp/mytest
2008-07-16 17:00:41.417:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: context removed
from url
2008-07-16 17:00:41.418:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 0 run called
with /mytest
2008-07-16 17:00:41.418:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: matched "from"
2008-07-16 17:00:41.422:/webapp:INFO:
org.tuckey.web.filters.urlrewrite.RuleExecutionOutput DEBUG: needs to
be forwarded to /products/index



As you can see, a direct Grails URL request works as expected:
Urlrewrite will filter it first and won't find a rule for it, and then
Grails urlmapping will find a rule and shows the page.
In the second request -the rewritten URL request- Urlrewrite will find
a rule and forwards it to /webapp/products/index, BUT Grails
urlmapping doesn't seem to be called now???
And a 404 page will show: "NOT_FOUND RequestURI=/webapp/products/
index".


Any ideas why Grails urlmapping doesn't work when an URL is forwarded
by Urlrewrite? Grails should be unaware of any action performed by
Urlrewrite, right?

J

unread,
Jul 16, 2008, 1:32:13 PM7/16/08
to UrlRewrite
http://www.nabble.com/UrlRewriteFilter-not-working-for-Grails--td18486957.html
The problem is Grails. It doesn't support forward dispatchers.
Reply all
Reply to author
Forward
0 new messages