users@jersey.java.net

Re: [Jersey] Sending xml to Jersey

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 10 Feb 2009 10:45:05 +0100

On Feb 6, 2009, at 11:38 PM, Lars Tackmann wrote:

> On Fri, Feb 6, 2009 at 11:04 PM, Amir Pourteymour <pourteymour_at_gmail.com
> > wrote:
>> Hi,
>>
>> I would like to generate xml from an object (by using JAXB), and
>> send it to
>> my Servlet. On the Servlet side, I want to transform once again to
>> a JAXB
>> object, and do some procedure, and return the result as an XML to the
>> client.
>>
>> Should I use WebClient to send these kinds of request in both ends?
>>
>> thanks for your helpful comments in advance,\
>
> Not sure I fully understand your question, since Jersey already have
> transparent support for JAXB. i.e. on the server
>
> __
> @POST
> @Consumes( { MediaType.APPLICATION_XML })
> @Produces( { MediaType.APPLICATION_XML })
> public Response doSomething(JAXBObject myObject) {
> // do stuff and return response
> }
> --
>
> and then something like this on the client:
>
> --
> JAXBObject myObject = ...; // create JAXB bean
> Client c = Client.create();
> final String url = "http://localhost:9999/xml;
> WebResource resource = c.resource(url);
> Builder builder = resource.accept(MediaType.APPLICATION_XML);
> builder.entity(myObject);
> String response = builder.get(String.class);
> --
>
> Hope this helps
>

See also this sample:

   http://download.java.net/maven/2/com/sun/jersey/samples/jaxb/1.0.1/jaxb-1.0.1-project.zip

That shows how to use JAXB on the client and server-side.

Paul.