users@jersey.java.net

Re: [Jersey] hateos + Jersey ?? how to

From: Richard Wallace <rwallace1979_at_gmail.com>
Date: Mon, 31 Aug 2009 15:50:37 -0700

2009/8/31 Felipe Gaścho <fgaucho_at_gmail.com>:
> so, I am thinking to include an href in each of my response elements..
> following the strict HATEOS principle..
>
> at least to have an hypertext reference on the root elements...
>
> How it is the most effective way of doing that ?
>

Something that I've done in the past is create a Link class that is
JAXB annotated like

public class Link {
  @XmlAttribute private final String href;
  @XmlAttribute private final String rel;
  @XmlElement private final String value;

  // ctor, builders and getters omitted
}

Then you can use it in other representations like

@XmlRootElement
class MyRepresentation {
    @XmlElement private final Link self;

    MyRepresentation(MyObject o, UriBuilder uriBuilder) {
        self = Link.href(uriBuilder.path(MyResource.class).build(o.getName())).rel("self");
    }
}

But that's only applicable if you're using JAXB. If not, then I would
imagine you could use some similar strategy as long as you can get
access to the UriBuilder, know the values you want to substitute into
the path and you know the resource class you are building the path to.

> other: should I include a full http URL like
> "http://resouce/path1/path2" or just the paths ? like "path1/path2" ?
>
> --
> Looking for a client application for this service:
> http://fgaucho.dyndns.org:8080/footprint-service/wadl
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>