users@jersey.java.net

Re: [Jersey] Putting the RESTful "connectedness" around my existing Domain objects

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 04 Dec 2008 07:38:08 +0100

Hi Brett,

I will reply in more detail tomorrow as i am traveling today. In
general i think your approach is heading roughly in the right direction.

Paul.

On Dec 4, 2008, at 5:54 AM, Brett Dargan wrote:

> One of the great things about jersey is that it gives us a simple
> way to take our existing JAXB annotated objects and expose them as
> resources.
> So at my company we are progressing with creating more RESTful Web
> Services, I would like a standard way to facilitate adding the
> "connectedness" aspect of existing JAXB annotated objects.
>
> Obviously right now, we don't have domain objects that are linked in
> that way.
>
> Has anyone come across this problem?
>
>
>
> Maybe we could create some Annotation, add to our existing JAXB
> annotated objects that use the same URITemplate style specified in
> the jsr311.
>
> Then by using a ContainerResponseFilter, traverse the entity object
> and add links to those objects prior to unmarshalling.
>
> I've got some running code that does this, nothing worth posting yet.
>
> But there are a few issues, I'm not sure if I should continue down
> this path, or if someone has a better idea.
>
> So something like this:
>
> @XmlRootElement
>
> class Book {
>
> private String id;
>
> @ResourceLink("/authors/{author}")
>
> private String author;
>
>
> @ResourceLinkContainer
>
> private List<ResourceLinkItem> resourceLinks = new
> ArrayList<ResourceLinkItem>();
>
> ...
>
> Then in the ContainerResponseFilter
> grab the entity out of the contentResponse, scan it for
> ResourceLinks, add ResourceLinkItems with hrefs that have been
> evaluated, from some context.
>
>
> Since we support multiple representations, the ResourceLinkItem,
> would need to handle links like standard html as well as xlink.
>
> The other potential niceness, is being able to preserve the suffix
> in links from the requested resource.
>
> Eg. Requested specific representations, such as /books/1231.xml
> should be able to return an xml representation with the same suffix,
> like /authors/bob.xml.
>
> Or /books/1231.es.html should contain a link to /authors/bob.es.html
>
> Using a filter, would enable me to easily slightly tailor the links
> to other resources, without affecting the original domain object.
>
> Sure it raises questions like what is a suffix, but there are
> conventions we could follow around that.
>
> cheers,
>
> Brett.
>
>
>