users@jersey.java.net

Re: [Jersey] consuming xml

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 16 Mar 2009 11:19:23 +0100

On Mar 16, 2009, at 10:55 AM, Youssef ALAHYANE wrote:

> Hi Paul,
> Thanx for your last reply it helps me a lot to progress in my
> project. The final question i'd like to answer is the following:
> I have a ressource method that uses PUT httpMethod by consuming xml
> Mime, the problem for me is that i don't know how to consume the
> received xml in other words how can I retrieve and parse the
> consumed XML to create the corresponding java object.
>
>
> @Path("/test/{sessionCode}")
> @Produces("application/xml")
> @Consumes("application/xml")
> public String setHistory(@PathParam("sessionCode") String
> sessionCode)
> {
> I don't know how to get and retrieve consumed xml
>

You need another method parameter in the above that is the request
entity to update the resource with, for example if you want to consume
the XML the client sent as a JAXB bean, called say SessionCode, you
could do:

     @Path("/test/{sessionCode}")
     @Produces("application/xml")
     @Consumes("application/xml")
     public String setHistory(@PathParam("sessionCode") String
sessionCode, SessionCode code) {
         ...
     }

In general you can use the same Java types for method parameters as
you can for the response, when producing.

For more details on JAXB usage see the following sample:

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

Paul.