How to use a class customization to resolve file generating conflicts
If the autoNameResolution fix
<args>
<arg>-XautoNameResolution</arg>
</args>
doesn't work, try:
<args>
<arg>-B-XautoNameResolution</arg>
</args>
The error message you are facing basically states that some names in the the types
section of your wsdl are you used two times. In your case all <element>
tags have the same name as their corresponding types (defined as <complexType>
).
Example:
<s:element name="SearchFlights">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="SoapMessage" type="tns:SearchFlights" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="SearchFlights">
<s:complexContent mixed="false">
<s:extension base="tns:SoapMessageBase">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Request" type="tns:SearchFlightsRequest" />
<s:element minOccurs="0" maxOccurs="1" name="Response" type="tns:SearchFlightsResponse" />
</s:sequence>
</s:extension>
</s:complexContent>
</s:complexType>
This is quite uncommon.
There are basically two options to resolve these issues:
Use autoNameResolution
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-XautoNameResolution</arg>
</args>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>hello.wsdl</generatePackage>
<schemas>
<schema>
<url>http://www5v80.elsyarres.net/service.asmx?wsdl</url>
</schema>
</schemas>
</configuration>
</plugin>
The plugin will resolve all naming conflicts through appending numbers to every colliding name. In the above mentioned case of SearchFlights this will result in SearchFlights and SearchFlights2 being generated.
A better way would be to use a binding file to resolve all name conflicts in advance. Binding files mostly contain XPATH
expression and transformation rules.
A binding file that appends to every declarations name is the following:
<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings wsdlLocation="http://www5v80.elsyarres.net/service.asmx?wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='ElsyArres.API']">
<jaxb:schemaBindings>
<jaxb:nameXmlTransform>
<jaxb:elementName suffix="Elem"/>
</jaxb:nameXmlTransform>
</jaxb:schemaBindings>
</jaxws:bindings>
</jaxws:bindings>
There are other options for jaxb:nameXmlTransform
like suffixes and prepending to other kind of xml elements (like types).
Sadly i could not get to work this binding file with the org.jvnet.jaxb2.maven2:maven-jaxb2-plugin
( but i am sure there is a working configuration)
It nevertheless works with the org.codehaus.mojo:jaxws-maven-plugin
and the following configuration.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/bindings.xjb</bindingFile>
</bindingFiles>
<wsdlUrls>
<wsdlUrl>http://www5v80.elsyarres.net/service.asmx?wsdl</wsdlUrl>
</wsdlUrls>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
</configuration>
</plugin>