Java Reference
In-Depth Information
In the PersonResource the links are set with a private method, shown in the next list-
ing.
Listing 9.7. Setting prev , self , and next link headers for each person
So-called “self” links are generated for each person. Next and previous links are generated
for those elements between the first and last. The links themselves are simply generated by
string manipulation.
Adding the links to the resource is done with the links method:
Response findById(@PathParam("id") long id) {
Person p = dao.findById(id)
Response. ok (p)
.links(getLinks(id))
.build()
}
It turns out that converting the Link headers into something useful isn't simple with the
RESTClient . In this case the JAX-RS Client class works better. The Client class
has a method called getLink , which takes a string argument, in which the string is the
relation type. That method returns an instance of the javax.ws.rs .core.Link class,
which corresponds to specification RFC 5988, Web Linking, of the IETF.
Search WWH ::




Custom Search