cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dan Diephouse" <...@envoisolutions.com>
Subject Re: JAXB and xs:any question
Date Fri, 29 Dec 2006 18:53:07 GMT
Hi Steve,

First an explanation: One of the highly annoying limitations of JAXB
is that when you create a JAXBContext - which holds all metadata about
what types of classes you want to serialize - you must supply all the
classes for that context up front. When we build up a service, we
initialize the JAXBContext by finding all the classes referenced from
service interface that we can find. This means your GuineaPig class
won't be found since you presumably created it yourself.

I created an issue for this case in JIRA which you can track:

http://issues.apache.org/jira/browse/CXF-340

In the mean time if you're willing to get more low level I believe you
can set the context yourself.

Lets say you're doing Endpoint.publish():

EndpointImpl ep = (EndpointImpl) Endpoint.publish(implementor, address);
Service s = ep.getServer().getEndpoint().getService();

s.getDataBinding().setContext(JAXBContext.newInstance("package1", "package2"));

Hope that helps.

 Regards,
 Dan

On 12/28/06, Olson, Steve <SOlson@ameren.com> wrote:
> I am using CXF and JAX-WS (JDK 6) to talk to a .Net web service that has
> a normal WSDL, and one of the elements in one of the objects defined in
> the wsdl is an xs:any type. All the other objects and operations this
> .Net web service uses are working fine, so my question is specific to
> xs:any handling.
>
>
>
> The intent for this particular xs:any is for clients to pass in any XML
> fragment desired, undefined to the WSDL. After running wsdl2java to get
> the client stub, I'm using code like this to set the xs:any - this first
> snippet arrives just fine at the .Net web service:
>
>
>
>       QName qnm = new QName("test");
>
>       QName qnm1 = new QName(","Pig");
>
>       JAXBElement<String> jaxb1 = new JAXBElement<String>(qnm1,
> String.class, "piglet");
>
>       JAXBElement<JAXBElement> jaxb = new JAXBElement<JAXBElement>(qnm,
> JAXBElement.class, jaxb1);
>
>       xml.setAny(jaxb);
>
>
>
> With this wimpy test snippet, this XML shows up at .Net, which is fine:
>
>             <test><Pig>piglet</Pig></test>
>
>
>
> Next I tried to get little fancier, and have JAXB put a little more
> complex object that has a couple attributes out with this code:
>
>
>
>       QName qnm = new QName("test");
>
>       QName qnm1 = new QName("Pig");
>
>       JAXBElement<GuineaPig> jaxb1 = new JAXBElement<GuineaPig>(qnm1,
> GuineaPig.class, pig);
>
>       JAXBElement<JAXBElement> jaxb = new JAXBElement<JAXBElement>(qnm,
> JAXBElement.class, jaxb1);
>
>       xml.setAny(jaxb);
>
>
>
> where GuineaPig is a simple POJO and looks like this (I left out the
> get/set methods):
>
>
>
> @XmlAccessorType(XmlAccessType.FIELD)
>
> @XmlRootElement
>
> public class GuineaPig {
>
>       @XmlAttribute
>
>       private String color;
>
>       @XmlAttribute
>
>       private String name;
>
> }
>
>
>
> I was hoping this code would generate this XML and pass it up in the
> any:
>
>             <test><Pig color="red" name="xxx"/></Test>
>
>
>
> But instead the web service client throws javax.xml.bind.JAXBException:
> com.ameren.esb.eventserviceclient.GuineaPig is not known to this
> context.
>
>
>
> Is this a correct way to put XML into an xs:any type?  If it is, what am
> I missing to make JAXB happy with this GuineaPig class?  Any help anyone
> is willing to offer would be appreciated.
>
>
>
> BTW - I have been comparing Sun's JAX-WS, XFire, and Axis2 functionality
> for building clients of .Net web services of various types that we use
> internally, and so far CXF is handling the most different WSDLs with the
> least hassle of any of these.  I congratulate the CXF team - this is
> pretty good for a milestone build compared to release builds of all the
> others!
>
>
>
> Steve Olson
>
>
>
>
>
> *******************************
> The information contained in this message may be privileged and/or confidential and protected
from disclosure. If the reader of this message is not the intended recipient, or an employee
or agent responsible for delivering this message to the intended recipient, you are hereby
notified that any dissemination, distribution or copying of this communication is strictly
prohibited. Note that any views or opinions presented in this message are solely those of
the author and do not necessarily represent those of Ameren. All emails are subject to monitoring
and archival. Finally, the recipient should check this message and any attachments for the
presence of viruses. Ameren accepts no liability for any damage caused by any virus transmitted
by this email. If you have received this in error, please notify the sender immediately by
replying to the message and deleting the material from any computer. Ameren Corporation
> *******************************
>
>
>


-- 
Dan Diephouse
Envoi Solutions
http://envoisolutions.com | http://netzooid.com/blog

Mime
View raw message