users@jersey.java.net

Re: [Jersey] Sending xml to Jersey

From: Lars Tackmann <lars_at_randompage.org>
Date: Fri, 6 Feb 2009 23:38:18 +0100

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
-- 
Yours sincerely
Lars Tackmann