users@jersey.java.net

[Jersey] Re: Handling a special URI.

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Fri, 3 Dec 2010 10:27:58 +0100

Hi Rahul,

It may be tricky as Jan and Kevin suggest but it may be possible. Lets
see if i understand your requirements :-)

You could have a root resource such as:

   @Path("{anything}"/CUSTOM/{id}")

I explicitly used "CUSTOM" because i do not know what your rules are
to distinguish a key word from a "normal" word. If the rules can be
declared as a regular expression then you can replace "CUSTOM" with a
path parameter that declares the regular expression.

I presume you must have some rules otherwise you would not be able to
write filter.

The precedence rules of matching are as follows:

number of literal characters in each member as the primary key
(descending order), the number of capturing groups as a secondary key
(descending order) and the number of capturing groups with non-default
regular expressions (i.e. not ‘([/]+?)’) as the tertiary key
(descending order).

which basically means:

   @Path("{anything}"/CUSTOM/{id}")

takes precedence over:

   @Path("{anything}")

in terms of matching.

Hth,
Paul.


On Dec 2, 2010, at 9:30 PM, Rahul Babbar wrote:

> Hello All,
>
> I have a few Jersey resources which handle different URIs.
>
> Lets say i have two resources, handling /foo and /bar.
>
> I have a requirement in which any URI of the form /<anything>/{Id}/
> {SOME KEYWORD}/{name} should not go to the resource handling foo or
> bar even though anything is foo or bar.
>
> Eg, lets say, the URI is of the form /foo or /foo/1 or /bar or /bar/
> 1 , it will go to the corresponding resource handling the URI.
>
> However if the URI is of form /foo/CUSTOM/1 or /bar/CUSTOM/1, i
> need it to go to a different resource directly.
>
> Sorry but i know this requirement is a bit weird, but is there a way
> to accomplish it?
>
> Thank you
>
> Rahul