I believe this may have been due to an update of the version of JAXB between
the two versions. CXF really doesn't do anything at this level.
HOWEVER, can I see the annotations on the FOO object as well? Does it have
an @XmlRootElement on it? How about an @XmlType annotation? Does the
@XmlType have a name attribute?
Dan
On Thursday, January 26, 2012 12:16:13 PM rouble wrote:
> CXF Gurus,
>
> I use JavaToWS to generate the WSDL on my development box. After migrating
> to 2.4.3 (from 2.4.1) I noticed that the WSDL being generated is slightly
> different (uses references). And any clients generated using wsdl2java, on
> that WSDL do not work. This issue is easily reproducible.
>
> The data object in question is, lets say, a Widget, and the SOAP API call
> is getWidget(). Here is what Widget looks like:
> <code>
> @XmlRootElement(name = "Widget")
> @XmlAccessorType(XmlAccessType.PROPERTY)
> @XmlType(name = "Widget")
> public class Widget {
> private FOO foo;
> private Bar bar;
>
> public FOO getFOO() {
> return foo;
> }
> public void setFOO(FOO foo) {
> this.foo = foo;
> }
> public Bar getBar() {
> return bar;
> }
> public void setBar(Bar bar) {
> this.bar = bar;
> }
> }
> </code>
>
> The WSDL generated by JavaToWS looks like this:
> <wsdl>
> <xs:complexType name="Widget">
> <xs:sequence>
> <xs:element minOccurs="0" name="bar" type="tns:Bar"/>
> <xs:element minOccurs="0" ref="tns:FOO"/>
> </xs:sequence>
> </xs:complexType>
> </wsdl>
>
> Notice how bar is explicitly listed inline, but FOO is referred to via a
> reference. In CXF 2.4.1, both of these elements would be explicitly listed
> inline.
>
> And the generated code using wsdl2java looks like this:
> <code>
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "Widget", propOrder = { "bar", "foo" })
> public class Widget {
> protected Bar bar;
> @XmlElement(name = "FOO", namespace = "http://example.com/")
> protected FOO foo;
> <SNIP>
> }
> </code>
>
> Notice, that FOO is explicitly marked to be in a namespace in the generated
> code, and bar is in no explicit namespace.
>
> Now, when we call the getWidget() on the web service, we get back:
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
> <soap:Body>
> <ns2:getWidgetResponse xmlns:ns2="http://example.com/">
> <return>
> <bar>
> <intBar>7</intBar>
> </bar>
> <FOO>
> <fooInt>99</fooInt>
> </FOO>
> </return>
> </ns2:getWidgetResponse>
> </soap:Body>
> </soap:Envelope>
>
> And CXF throws the exception:
> org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
> WARNING: Interceptor for {
> http://example.com/}FooWebService#{http://example.com/}getWidget has thrown
> exception, unwinding now
> org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element
> (uri:"", local:"FOO"). Expected elements are
> <{http://example.com/}FOO>,<{}bar>
>
>
> The CXF client is expecting FOO to be in the namespace http://example.com,
> but JAXB does not namespace elements. Hence the exception. bar is
> unmarshalled just fine. Now this worked fine in when we used JavaToWS in
> 2.4.1 and is broke now. Any thoughts? Do I need to file a bug?
>
> tia,
> rouble
--
Daniel Kulp
[email protected] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com