The Object that is passed in must be something that JAXB knows about.   That 
would include one of the classes that was generated from the wsdl2java call 
or a DOM.

Dan


On Tuesday, March 13, 2012 09:00:19 AM phil.n wrote:
> Hi,
> 
> Apologies if this has been asked before.
> I am using cxf to create a client for a webservice that is described via
> wsdl. The generation seems to work ok, except for a couple of operations
> where the incoming request is empty:
> 
> <xs:element name="opRequest" />
> 
> <wsdl11:message name="opRequest">
>         <wsdl11:part name="Parameters" element="tns:opRequest"/>
> </wsdl11:message>
> 
> The following java is generated from this:
> @WebMethod(action = "http://test.com/read";)
> public void read(
>   @WebParam(partName = "Parameters", name = "opRequest", targetNamespace =
> "http://test.com";)
>    java.lang.Object parameters,
>    ....
> 
> Subsequently in my client code, if I try to create an object and pass it
> through, I get a ClassCastException:
> 
> Object read_req = new Object();
> port.read(read_req ... );
> 
> If I pass a null, then the error goes away, but I run into an issue with
> the service provider as the SOAP that comes out has an empty SOAP:body,
> when they're epecting an <opRequest>.
> 
> Any ideas?
> Phil
> 
> Stack Trace below:
> 
> org.apache.cxf.interceptor.Fault: Marshalling Error: java.lang.Object
> cannot be
> cast to org.w3c.dom.Element
>         at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.ja
> va:263)
>         at
> org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:169)
>         at
> org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writePar
> ts(AbstractOutDatabindingInterceptor.java:119)
>         at
> org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutIn
> terceptor.java:68)
>         at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercept
> orChain.java:263)
>         at
> org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:533) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319) at
> org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
>         at
> org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:13
> 4)
>         at $Proxy44.readAllPersonIds(Unknown Source)
>         at
> com.psydev.lis.person.clients.PersonClient.readAllIds(PersonClient.ja
> va:319)
>         at
> com.psydev.lis.person.clients.PersonClientCLI.processOperation(Person
> ClientCLI.java:240)
>         at
> com.psydev.lis.person.clients.PersonClientCLI.run(PersonClientCLI.jav
> a:350)
>         at
> com.psydev.lis.person.clients.PersonClientCLI.main(PersonClientCLI.ja
> va:368)
> Caused by: java.lang.ClassCastException: java.lang.Object cannot be cast
> to org.
> w3c.dom.Element
>         at
> com.sun.xml.bind.v2.runtime.AnyTypeBeanInfo.serializeURIs(AnyTypeBean
> Info.java:149)
>         at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerialize
> r.java:677)
>         at
> com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serial
> izeBody(SingleElementNodeProperty.java:152)
>         at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(Eleme
> ntBeanInfoImpl.java:157)
>         at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(Eleme
> ntBeanInfoImpl.java:189)
>         at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(Element
> BeanInfoImpl.java:316)
>         at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(Element
> BeanInfoImpl.java:323)
>         at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(Element
> BeanInfoImpl.java:72)
>         at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.j
> ava:494)
>         at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:
> 315)
>         at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.jav
> a:172)
>         at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder
> .java:550)
>         at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.ja
> va:236)
>         ... 15 more
> 
> 
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/wsdl-first-generation-class-cast-exceptio
> n-with-generated-code-tp5561429p5561429.html Sent from the cxf-user
> mailing list archive at Nabble.com.
-- 
Daniel Kulp
dk...@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

Reply via email to