users@jersey.java.net

Re: [Jersey] Dynamic _at_Path

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 06 Aug 2009 18:02:24 +0200

On Aug 6, 2009, at 5:55 PM, Martin Probst wrote:

> Hi,
>
> I had a similar problem of allowing basically user defined paths in my
> application. The simple solution for me was to use sublocators. So you
> have a class:
>
> class Resource {
> ArrayList<String> segments = ...;
>
> // will be called when there are still trailing path segments
> @Path("{path}")
> public Resource foo(@PathParam("path") String path) {
> segments.add(path);
> return this;
> }
>

Why don't you utilize

@Path("{path: .+}")

?

Paul.

> // will be called when no more path segments are there
> @GET public Bla foo() { ... }
> }
>
> Of course you might need to take care not to modify the segments
> ArrayList and return a new object, depending on your application and
> whether you use singletons.
>
> The drawback of the approach is that sub-locators kind of mess up your
> WADL, but that is of course expected when you have dynamic paths that
> are generated on the fly.
>
> I don't know about static file serving - I actually never figured that
> out but probably should. I guess you can just make sure that all your
> dynamic paths always have a fixed, different prefix to disambiguate
> between them and actual static resources.
>
> Martin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>