users@jersey.java.net

Re: [Jersey] Re: Client-side question

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 04 Nov 2009 10:26:37 +0100

On Nov 4, 2009, at 1:05 AM, Steve Cohen wrote:

>> On Nov 3, 2009, Paul Sandoz wrote:
>>> On Nov 2, 2009, at 11:47 PM, Steve Cohen wrote:
>>>
>>> > I need to write client side code to access a Vendor's Web
>>> Service > which is supposed to be accessible by JAX-RS. I am
>>> given an XSD > schema and a document telling me what URI
>>> parameters I need to set > to extract the data from the service.
>>> >
>>> > Is there a way to generate Jersey-compatible data classes from
>>> the > XSD or do I have to write them by hand?
>>> >
>>>
>>> You can use JAXB xjc [1] to compile the XSD into Java classes that
>>> can be used with JAXB to marshall and unmarshall from and to XML
>>> respectively.
>>>
>>> And then you can use those generated Java classes with Jersey.
>>> See JAXB sample:
>>>
>>> http://download.java.net/maven/2/com/sun/jersey/samples/jaxb/1.1.2-ea/jaxb-1.1.2-ea-project.zip
>>>
>>> Paul.
>>>
>>> [1] https://jaxb.dev.java.net/nonav/2.1.12/docs/
>>> https://jaxb.dev.java.net/nonav/2.1.12/docs/xjc.html
>>> https://jaxb.dev.java.net/jaxb-maven2-plugin/
>>>
>>>
> Is it possible to use XmlBeans for the Java classes?

Yes, but you have to implement yourself as Jersey does not currently
ship with support for XmlBeans.

The plug-in mechanism requires that you implement a MessageBodyWriter
to convert an XmlBean instance to an XML document, and a
MessageBodyReader to convert an XML document to an instance of an
XmlBean.

For a very simple example utilizing MessageBodyWriter and
MessageBodyReader see:

   http://download.java.net/maven/2/com/sun/jersey/samples/entity-provider/1.1.2-ea/entity-provider-1.1.2-ea-project.zip

Paul.