users@jersey.java.net

Re: [Jersey] Dynamic _at_Path

From: Martin Probst <mail_at_martin-probst.com>
Date: Thu, 6 Aug 2009 17:55:09 +0200

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;
  }

  // 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