users@jersey.java.net

Re: [Jersey] Fighting with Regex

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Tue, 23 Dec 2008 10:05:31 -0500

On Dec 23, 2008, at 9:28 AM, Daniel Manzke wrote:
>
> I have some little fights with the regex and jersey. I followed the
> example and used "@Path("/filesystem/{folder:.+}"). In the hope that
> I would get all folders.
>
> /filesystem/folder1 - works
> /filesystem/folder1/folder2 - doesn't work
>
> With the help of wireshark I get a "Method not allowed" returned.
> Any ideas? Is Regex supported or experimental?
>
Its supported. My guess is that the second path is matching another
resource that doesn't support the method you are using. All matching
resources are sorted according to the following keys (most to least
significant):

(i) Number of literal chars in the template (descending order)
(ii) Number of template vars (descending order)
(iii) Number of template vars with non-default regex (descending order)

So, if you have @Path("/filesystem/{folder:.+}") and @Path("/
filesystem/{folder1}/{folder2}") then the latter will be matched since
it has more literal characters (the extra literal '/').

You can find the full matching algorithm in section 3.7 of the JAX-RS
spec:

https://jsr311.dev.java.net/nonav/releases/1.0/spec/
spec3.html#x3-340003.7

Marc.

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.