users@jersey.java.net

Re: [Jersey] Arbitrary path length in service URL

From: Craig McClanahan <Craig.McClanahan_at_Sun.COM>
Date: Tue, 07 Oct 2008 11:57:09 -0700

Chuck Harris wrote:
> Howdy!
>
> I am trying to write a service with Jersey that will accept a path of arbitrary length for processing; e.g., it will accept "http://server/app/resources/service/foo" and "http://server/app/resources/service/foo/bar" and even "http://server/app/resource/service/foo/bar/foo/bar/foo/bar".
>
> I can configure this if I know how many path segments to expect in the final URL, but how do I set this up to pass the whole path as one parameter (even a List or array of Strings would work; I just need to allow an arbitrary path length instead of a preset number of named parameters)?
>
> Thanks,
> Chuck Harris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
This is where the regular expression matching comes in really handy.
Try something like this:

    @GET
    @Path("/resources/service/{path:.+}")
    public Response myMethod(@PathParam("path") String path) {
        ...
     }

The "path" method parameter will absorb the entire set of elements after
/resources/service.

Craig