Discussion:
The wsdl generated from cxf contains elements with minOccurs=0 instead of a choice
Stefano Fontanel
2014-04-14 15:21:09 UTC
Permalink
Hi,
I'm using cxf 2.7.10 with java 6.

I have defined a wsdl with a top-down approach. In one of the xml schema
that I import in the wsdl I have defined a complex type that includes a
choice.

When I look at the wsdl that cxf generates at runtime I see that the choice
disappeared and a nillable=true have appeared.

<xsd:complexType name="MyResponse">
<xsd:choice>
<xsd:element ref="mdtx:myElement"/>
<xsd:element name="error" type="mdsvc:Error" maxOccurs="unbounded"/>
</xsd:choice>
</xsd:complexType>

<xs:complexType name="MyResponse">
<xs:sequence>
<xs:element minOccurs="0" ref="ns2:myElement"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="error"
nillable="true" type="ns3:Error"/>
</xs:sequence>
</xs:complexType>

Please, could you explain me why it happens and how can I change some
configuration to avoid it?
Thank you very much.
Stefano.
sfont
2014-04-16 11:55:55 UTC
Permalink
Hi,
we have solved introducing the wsdlLocation attribute in the jaws:endpoint
configuration. We verified also that after that change if we enable the
schema validation cxf validates the soap request and response against our
original schema/wsdl :)

Searching the web we found that the wsdl that cxf publish by default
(without the wsdlLocation configuration) is generated from the jaxws/jaxb
annotations of the classes generated from the wsdl2java tool..Is it correct?

Thank you very much.
Stefano






--
View this message in context: http://cxf.547215.n5.nabble.com/The-wsdl-generated-from-cxf-contains-elements-with-minOccurs-0-instead-of-a-choice-tp5742815p5742901.html
Sent from the cxf-user mailing list archive at Nabble.com.
Daniel Kulp
2014-04-16 14:39:36 UTC
Permalink
Post by sfont
Hi,
we have solved introducing the wsdlLocation attribute in the jaws:endpoint
configuration. We verified also that after that change if we enable the
schema validation cxf validates the soap request and response against our
original schema/wsdl :)
Searching the web we found that the wsdl that cxf publish by default
(without the wsdlLocation configuration) is generated from the jaxws/jaxb
annotations of the classes generated from the wsdl2java tool..Is it correct?
Yep. That’s correct. Not everything in schema is recorded in the JAXB generated classes. Things like facets and such are lost. Additionally, there are several schema constructs that map to the same JAXB structure so when you do the reverse, it may not be exactly the same.

In general, if you have a wsdl/schema, it’s likely best to use it via the wsdlLocation.
--
Daniel Kulp
dkulp-1oDqGaOF3Lkdnm+***@public.gmane.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Frizz
2014-04-28 09:03:25 UTC
Permalink
Hi,

I have a similar "problem", so I would also be interested to know more
technical details. Especially about this choice/sequence thing.

I have a WSDL file with the following content:

...

<xsd:complexType name="Scenario" mixed="true">

<xsd:sequence>

<xsd:element name="Description" type="xsd:anyURI" minOccurs="0"/>

<xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded"
processContents="lax"/>

</xsd:sequence>

<xsd:anyAttribute namespace="##other" processContents="lax"/>

</xsd:complexType>

...




And this is what JAX-WS/JAXB/CXF generates:



...

<xsd:complexType mixed="true" name="Scenario">

<xsd:sequence>

<xsd:choice maxOccurs="unbounded" minOccurs="0">

<xsd:element name="Description" type="xsd:string"/>

<xsd:any namespace="##other" processContents="lax"/>

<xsd:choice>

</xsd:sequence>

<xsd:anyAttribute namespace="##other" processContents="skip"/>

</xsd:complexType>

...

Loading...