Hi Lief,
Leif Gensert wrote:
> I'm writing an REST-Web-Service which returns Plain Old XML. I'd like
> to add a resource URI to all my resource. It should look like this:
>
> http://www.xfront.com/REST-Web-Services.html
>
> <?xml version="1.0"?>
> <p:Parts xmlns:p="http://www.parts-depot.com"
> xmlns:xlink="http://www.w3.org/1999/xlink">
> <Part id="00345" xlink:href="http://www.parts-depot.com/parts/00345"/>
> <Part id="00346" xlink:href="http://www.parts-depot.com/parts/00346"/>
> <Part id="00347" xlink:href="http://www.parts-depot.com/parts/00347"/>
> <Part id="00348" xlink:href="http://www.parts-depot.com/parts/00348"/>
> </p:Parts>
>
> What I'm currently doing is, add the base-url to every resource object
> manually as an attribute and let jaxb do the rest.
>
> Isn't there a nicer way in JSR-311 oder jersey to achieve this feature?
>
IIUC you could create a message body writer for your JAXB types that
adds the base URI. You can inject UriInfo:
@Context UriInfo ui
on a message body writer to get the base URI.
An more complicated alternative sneaky way is to provide your own
JAXBContext implementation and use the ContextResolver<JAXBContext> to
return your JAXBContext implementation for your own types. The
marshaller returned from your JAXBContext implementation can add the
base URI to the JAXB bean before marshalling.
I think in general we should probably have some form of JAXB helper
classes for reading/writing to make it easier for you to do this type of
thing.
Paul.
> Leif
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109