|
From: Bill B. <bb...@re...> - 2008-06-03 05:19:18
|
In your provider you can inject an HttpHeader field. From that you can
obtain UriInfo, from that a UriBuilder that allows you to build URIs.
@Provider
public class UserAttributeXmlSerializer {
@Context HttpHeaders headers;
...
}
Ian Butcher wrote:
> 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.
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Resteasy-developers mailing list
> Res...@li...
> https://lists.sourceforge.net/lists/listinfo/resteasy-developers
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com
|