|
From: Ian B. <ibu...@re...> - 2008-06-02 23:27:30
|
One of the features of RESTful web services described in the ORA book
"RESTful Web Services" is that of hypermedia connections in resource
representations. I can't find a way (although I'm very new to it) in
JAX-RS or resteasy to put a link to another resource in my
representation. Is there a way to get the URL of another resource
inside of resteasy?
Example:
I have a system that is a glorified keystore. A user is referenced by
GUID, the key part of the keystore has a name. The value can be
either a simple scalar type (int, long, string, etc) or an array of
them.
My resources would look something like:
@Path("/attributes/{key}/{definition}")
public class KeyResource{}
@Path("/attributes/{userguid}/{key}")
public class UserKeyResource{}
@Provider
@ProduceMime("text/xml")
public class UserAttributeXmlSerializer implements MessageBodyReader,
MessageBodyWriter {
public void writeTo(Object o, Class aClass, Type type, Annotation[]
annotations, MediaType mediaType,
MultivaluedMap multivaluedMap, OutputStream outputStream)
throws IOException, WebApplicationException {
// build representation of the 'values' part of the UserKey
resource
...
// now I want to add a link to the key resource. This allows
the client to find out what scalar type or array this value represents
// there is where I'd really like to be able to get the actual
URL for a given 'key' resource
...
}
}
So the representation that I want to send to the client looks like this:
<keyvalue>
<values>
<value>123</value>
</values>
<key>http://somehost/somecontext/atributes/somekey</key>
</keyvalue>
Any ideas or answers greatly appreciated.
Thanks,
Ian. |