users@jersey.java.net

Re: [Jersey] Taking over a URL space

From: Bryon Jacob <bryon_at_jacobtx.net>
Date: Tue, 27 Jan 2009 13:28:06 -0600

Matthieu -

you can specify what matches your path variables with a regular
expression. For example, if you want to match everything underneath
"foo", you could do:

@POST
@Path("foo/{sub : .*}")
public Response post(String content) {
     // do whatever...
}

if the resource you are managing is already scoped where you want it
to be in the URL space, you could just do:

@POST
@Path("{sub : .*}")
public Response post(String content) {
     // do whatever...
}

by default, the regular expression is something like [^/]*, which
matches everything up to the next slash -- the exact regex is spelled
out by the spec, I believe...

  - Bryon

On Jan 27, 2009, at 12:49 PM, Matthieu Riou wrote:

> Hi,
>
> I'm having difficulties with a resource that handles the whole url
> space under a given url. For example everything matching /foo/bar/**
> should be delivered to that resource, no matter which subpath. The
> resource handles the rest. For now I have to do:
>
> @POST @Consumes("application/xml") @Path("{sub1}")
> public Response postSub(String content) {
> return post(content);
> }
>
> @POST @Consumes("application/xml") @Path("{sub1}/{sub2}")
> public Response postSubSub(String content) {
> return post(content);
> }
>
> ......
>
> Not really convenient and will break as soon as more subpaths are
> used than what I handle. Any other solution?
>
> Thanks,
> Matthieu
>