users@jsr311.java.net

Re: How to handle resource uris (simple atom server)

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 27 Aug 2008 12:49:21 -0400

On Aug 27, 2008, at 4:27 AM, Jo Størset wrote:
>
> I've asked similar questions before, but I'm still not satisfied
> with the solutions I've come up with. So :)
>
> Looking at the simple atom server, the resource uris are reflected
> in a lot of places, partly as duplication and partly as unique
> pieces needed to know resource uris:
>
> - path annotations
> - java URIBuilder handling
> - hardcoded string constants
> - stored in the data store
>
> On an architectural/design level, I don't really see any consistent
> pattern to how the urls are handled (to me this seems like a bit a
> mess :).
>
> So I've, unsuccessfully, been trying to come up with a set of
> guidelines or practices, preferably with help from the framework, on
> how to handle this really important piece of a rest application.
>
> Is this clearer to anyone else? Am I trying to fix something that
> should rather be left alone for now?
>
> I would really appreciate any ideas on this, as I'm kind of stuck :)
>
I don't have a complete recipe, but a number of UriBuilder methods
will extract URI path templates from annotations so it shouldn't be
necessary to have duplicate string constants elsewhere. E.g. to build
a URI to a root resource:

@Context UriInfo uriInfo; //injected

URI u = uriInfo.getBaseUriBuilder().path(SomeResource.class).build();

I think its easier if you mainly use root resources but even if you
make use of dynamic sub-resource locators you can use the combination
of UriInfo.getBaseUriBuilder and UriInfo.getMatchedURIs to build URIs
to parent resources.

Not sure if that really answered your question ?

Marc

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.