How to resolve collision in ObjectFactory on wsdl2java?

I use CXF and wsdl2java to automatically create webservice classes.

Problem: somehow the web service I want to connect to has duplicate names for some elements:

Two declarations cause a collision in the ObjectFactory class

xsd looks like this:

 <xs:schema targetNamespace="http://thenamespace"> <xs:complexType name="ViolatingName"> ... </xs:complexType> <xs:element name="ViolatingName" nillable="true" type="tns:ViolatingName"/> </xs:schema> 

Xsd itself is imported inside wsdl, which is used to auto-generate jaxb classes as follows:

 <wsdl:types> <xsd:schema targetNamespace="http://imports"> <xsd:import schemaLocation="https://path.to.xsd" namespace="http://thenamespace" /> 

I am trying to cover this with jaxb-bindings.xml :

 <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1"> <jaxb:bindings schemalocation="https://path.to.xsd" node="//xs:schema"> <jaxb:bindings node=".//xs:element[@name='ViolatingName']"> <jaxb:property name="ViolatingNameBinding" /> </jaxb:bindings> </jaxb:bindings> </jaxb:bindings> 

Result:

[ERROR] XPath evaluation of "//xs:schema" results in empty target node (org.apache.cxf:cxf-codegen-plugin:3.0.1:wsdl2java:generate-sources:generate-sources)

Why is the wrong node here? Xsd has an xs:schema tag, so why doesn't it succeed?

Interesting fact: when I use any xpath tool, download the XSD to my local machine, check the path, then //xs:schema/xs:element[@name='ViolatingName'] evaluates the corresponding tag.

+7
java xml web-services jaxb cxf
source share
3 answers

It turned out that I should apply rename / suffix for all xs:complexType elements, such as:

 <jaxb:bindings schemaLocation="https://path.to.xsd" node="/xs:schema"> <jaxb:schemaBindings> <jaxb:nameXmlTransform> <jaxb:typeName suffix="Type" /> </jaxb:nameXmlTransform> </jaxb:schemaBindings> </jaxb:bindings> 
+6
source share

Try jaxb:factoryMethod instead of jaxb:property .

 <jaxb:bindings node=".//xs:element[@name='ViolatingName']"> <jaxb:factoryMethod name="ViolatingName1" /> </jaxb:bindings> 

jaxb:factoryMethod binding example jaxb:factoryMethod .

Update:

It may also help.

+2
source share

Property Binding Declarations

A binding declaration allows you to customize the binding of an XML schema element to a Java representation as a property. The configuration area can be either at the definition level or at the component level, depending on where the binding declaration is indicated.

The syntax for the settings is:

 <property [ name = "propertyName"] [ collectionType = "propertyCollectionType" ] [ fixedAttributeAsConstantProperty = "true" | "false" | "1" | "0" ] [ generateIsSetMethod = "true" | "false" | "1" | "0" ] [ enableFailFastCheck ="true" | "false" | "1" | "0" ] [ <baseType> ... </baseType> ] [ <javadoc> ... </javadoc> ] </property> <baseType> <javaType> ... </javaType> </baseType> 
  • name defines the value of the propertyName property; it must be a Java legal identifier.
  • collectionType defines the value of the propertyCollectionType property, which is the collection type for the property. The propertyCollectionType property, if specified, can be indexed or any fully qualified class name that implements java.util.List.
  • fixedAttributeAsConstantProperty defines the value of the fixedAttributeAsConstantProperty setting. The value can be true, false, 1 or 0.
  • generateIsSetMethod defines the setting value for generateIsSetMethod. The value can be true, false, 1, or 0. enableFailFastCheck defines the value of the enableFailFastCheck setting. The value can be true, false, 1, or 0. Note that the JAXB implementation does not support fault tolerance testing.
  • <javadoc> configures Javadoc tool annotations for the getter method of properties.

From this link

Xsd

 <xs:schema targetNamespace="http://thenamespace"> <xs:element name="ViolatingName" type="tns:ViolatingName"/> <xs:complexType name="ViolatingName"> <xs:all> <xs:element name="prova" type="xs:string"/> </xs:all> </xs:complexType> <xs:element name="AdditionalInfos" type="AdditionalInfos"/> <xs:complexType name="AdditionalInfos"> <xs:sequence> <xs:element minOccurs="1" name="ViolatingName" type="tns:ViolatingName"/> </xs:sequence> </xs:complexType> </xs:schema> 

Snap

 <bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:annox="http://annox.dev.java.net" xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix"> <bindings schemaLocation="../path/of/your.xsd"> <bindings node="//xs:complexType[@name='AdditionalInfos']//xs:sequence//xs:element[@name='ViolatingName']"> <property name="aaa" /> </bindings> </bindings> </bindings> 

Generated class

 @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "AdditionalInfos", propOrder = { "aaa", }) @XmlRootElement public class AdditionalInfos implements Serializable { private final static long serialVersionUID = 12343L; @XmlElement(name = "ViolatingName", required = true) protected ViolatingName aaa; 
+1
source share

All Articles