Controller and URL Rewriting with GaelykServlet

14 views
Skip to first unread message

Nicolas Martignole

unread,
Nov 23, 2009, 5:07:38 PM11/23/09
to Gaelyk
Hi

I'd like to create a front controller for existing URLs such as
/category/java so that it loads category.groovy with a param "java"

1. Do you know if it's possible to set an URL as value for
"resource.name.replacement" ?
for instance something like category.java?c=java

2. When I declare the following configuration for my GaelykServlet
and I restart the server it works the very first time (/category/java
will load category.groovy)
but it won't work if I reload the page.

Thanks

Nicolas

<servlet>
<servlet-name>CategoryServlet</servlet-name>
<servlet-class>groovyx.gaelyk.GaelykServlet</servlet-class>
<init-param>
<param-name>verbose</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>resource.name.replace.all</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<!-- Try to turn /category/java?id=50 to /category.groovy?
c=java -->
<param-name>resource.name.regex</param-name>
<param-value>/(\w*)/*((\w*))(\?.*)?</param-value>
</init-param>
<init-param>
<param-name>resource.name.replacement</param-name>
<param-value>$1.groovy</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>CategoryServlet</servlet-name>
<url-pattern>/category/*</url-pattern>
</servlet-mapping>

Richard Vowles

unread,
Nov 24, 2009, 2:51:07 AM11/24/09
to gae...@googlegroups.com
Where did resource.name.replacement come from? I have not seen this as a parameter anywhere?


On Tue, Nov 24, 2009 at 11:07 AM, Nicolas Martignole <nmart...@gmail.com> wrote:

Hi

I'd like to create a front controller for existing URLs such as
/category/java so that it loads category.groovy with a param "java"

1. Do you know if it's possible to set an URL as value for
"resource.name.replacement" ?
for instance something like  category.java?c=java

--
---
Richard Vowles,
Grails, Groovy, Java
Consistency is the last refuge of the unimaginative - Oscar Wilde
ph: +64275467747, linkedin, skype:rvowles
get 2Gb shared disk space in the cloud - Dropbox, its incredibly useful! - http://tinyurl.com/cmcceh
podcast: http://www.illegalargument.com

Nicolas Martignole

unread,
Nov 24, 2009, 3:44:08 AM11/24/09
to gae...@googlegroups.com
Oups sorry
I was refering the initi-param for GarlykServlet, as shown in gaelyk tutorial where one puts the regexp

Nicolas

Guillaume Laforge

unread,
Nov 24, 2009, 4:38:50 AM11/24/09
to gae...@googlegroups.com
This replacement system is described in the tutorial.
--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Guillaume Laforge

unread,
Nov 24, 2009, 4:40:50 AM11/24/09
to gae...@googlegroups.com
Salut Nicolas,

On Mon, Nov 23, 2009 at 23:07, Nicolas Martignole <nmart...@gmail.com> wrote:
>
> Hi
>
> I'd like to create a front controller for existing URLs such as
> /category/java so that it loads category.groovy with a param "java"
>
> 1. Do you know if it's possible to set an URL as value for
> "resource.name.replacement" ?
> for instance something like  category.java?c=java

The replacement helps finding a resources on disk, somehow.
Think of it as a file path, if you wish.
But it's not a URL, so you can't redirect to a URL with a parameter,
unfortunately.

> 2. When I declare the following configuration for my GaelykServlet
> and I restart the server it works the very first time (/category/java
> will load category.groovy)
> but it won't work if I reload the page.

Which version of Groovy and Gaelyk do you use?

Nicolas Martignole

unread,
Nov 24, 2009, 5:00:18 AM11/24/09
to gae...@googlegroups.com
Latest Gaelyk with Groovy 1.6

Le 24 nov. 2009 à 10:40, Guillaume Laforge <glaf...@gmail.com> a
écrit :

Richard Vowles

unread,
Nov 24, 2009, 5:02:21 AM11/24/09
to gae...@googlegroups.com
Ah - right. I haven't looked into that. I forked Gaelyk (its in github/rvowles) and I have a plugin architecture available to our little group. I had to butcher the servlets a bit to make it work the way I want, but essentially you get a filter like mechanism with all the bits you actually need to make pretty much anything work.

I added a slf4j plugin which allows you to add a "log" variable to your binding easily here:


I need to test it on the project we are working on, but that is here: 


(registration system for CITCON)

Other examples of plugins that add extra functionality to the category (such as a model object, putAll on entities, etc) - the plugin that registers is here:


the extra Category functionality here (what is good about this is that it keeps you agile, adding category stuff in your own project and refactoring it out when you think you'll need it)


and the new model object that also directly injects its variables into the binding of the gtpl, which makes it really nice to use:


this means you go: model["address"] = address (for example) in your controller, and you can then just go ${address} in your gtpl.

For *your* particular project, the plugin architecture would help as you can intercept the scriptUri, pull it apart, stick the parameters into the binding and then pass the corrected scriptUri through to the next phase. Easy-peasy. You can do any kind of REST-like stuff with it as well.

But this is of course a departure from Gaelyk itself.

Richard

Nicolas Martignole

unread,
Nov 24, 2009, 5:02:48 AM11/24/09
to gae...@googlegroups.com
Hi,
Gaelyk 0.3 and Groovy 1.6.5 on Mac. I'll double check and will fill a
bug if requiered with the web.xml and the exact usecase

:-)

Thanks Guillaume

Nicolas

Le 24 nov. 2009 à 10:40, Guillaume Laforge <glaf...@gmail.com> a
écrit :

>
>> <param-value>/(\w*)/*((\w*))(\?.*)?</param-
>> value>
>> </init-param>
>> <init-param>
>> <param-name>resource.name.replacement</param-
>> name>

Guillaume Laforge

unread,
Nov 24, 2009, 5:03:52 AM11/24/09
to gae...@googlegroups.com
Latest Gaelyk certainly means 0.3.1?
And Groovy 1.6 is a bit vague, as there have been many 1.6.x versions :-)
My latest experiments were with Groovy 1.7-beta-2 and the upcoming
1.7-RC-1, and I've not had issues with this last one.
Could you please try the same thing with the upcoming RC-1 from below?
http://build.canoo.com:80/groovy/artifacts/20091123164552/dist
Reply all
Reply to author
Forward
0 new messages