I have two SOAP APIs that I need to connect to through my backend API. I have two different WSDL files: commercial.wsdl and consumer.wsdl. The problem is that WBAHS120505F02327 and consumer.wsdl share XML names. When I try run the program I get the following error:
Two classes have the same XML type name "{https://secure.xxx.co.za/xxx}EmpiricaEM04". Use @XmlType.name and @XmlType.namespace to assign different names to them.
Is there a way jaxb can generate classes for both wsdl file and share the common classes? If not, is there another way around this? I am not able to change the wsdl files and have to use them as provided to me.
Generated commercial class: EmpericaEM04.java
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0
// See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2021.05.27 at 08:39:41 AM SAST
//
package com.soap.api.xxx.commercial;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for EmpiricaEM04 complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="EmpiricaEM04">
* <complexContent>
* <extension base="{https://secure.xxx.co.za/TUBureau}Empirica">
* <sequence>
* <element name="ConsumerNo" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="EmpiricaScore" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ExclusionCode" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ExclusionCodeDescription" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ReasonCode" type="{https://secure.xxx.co.za/TUBureau}ArrayOfString" minOccurs="0"/>
* <element name="ReasonDescription" type="{https://secure.xxx.co.za/TUBureau}ArrayOfString" minOccurs="0"/>
* <element name="ExpansionScore" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ExpansionScoreDescription" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* </sequence>
* </extension>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "EmpiricaEM04", propOrder = {
"consumerNo",
"empiricaScore",
"exclusionCode",
"exclusionCodeDescription",
"reasonCode",
"reasonDescription",
"expansionScore",
"expansionScoreDescription"
})
public class EmpiricaEM04
extends Empirica
{
@XmlElement(name = "ConsumerNo")
protected String consumerNo;
@XmlElement(name = "EmpiricaScore")
protected String empiricaScore;
@XmlElement(name = "ExclusionCode")
protected String exclusionCode;
@XmlElement(name = "ExclusionCodeDescription")
protected String exclusionCodeDescription;
@XmlElement(name = "ReasonCode")
protected ArrayOfString reasonCode;
@XmlElement(name = "ReasonDescription")
protected ArrayOfString reasonDescription;
@XmlElement(name = "ExpansionScore")
protected String expansionScore;
@XmlElement(name = "ExpansionScoreDescription")
protected String expansionScoreDescription;
/**
* Gets the value of the consumerNo property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getConsumerNo() {
return consumerNo;
}
/**
* Sets the value of the consumerNo property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setConsumerNo(String value) {
this.consumerNo = value;
}
/**
* Gets the value of the empiricaScore property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getEmpiricaScore() {
return empiricaScore;
}
/**
* Sets the value of the empiricaScore property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setEmpiricaScore(String value) {
this.empiricaScore = value;
}
/**
* Gets the value of the exclusionCode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExclusionCode() {
return exclusionCode;
}
/**
* Sets the value of the exclusionCode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExclusionCode(String value) {
this.exclusionCode = value;
}
/**
* Gets the value of the exclusionCodeDescription property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExclusionCodeDescription() {
return exclusionCodeDescription;
}
/**
* Sets the value of the exclusionCodeDescription property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExclusionCodeDescription(String value) {
this.exclusionCodeDescription = value;
}
/**
* Gets the value of the reasonCode property.
*
* @return
* possible object is
* {@link ArrayOfString }
*
*/
public ArrayOfString getReasonCode() {
return reasonCode;
}
/**
* Sets the value of the reasonCode property.
*
* @param value
* allowed object is
* {@link ArrayOfString }
*
*/
public void setReasonCode(ArrayOfString value) {
this.reasonCode = value;
}
/**
* Gets the value of the reasonDescription property.
*
* @return
* possible object is
* {@link ArrayOfString }
*
*/
public ArrayOfString getReasonDescription() {
return reasonDescription;
}
/**
* Sets the value of the reasonDescription property.
*
* @param value
* allowed object is
* {@link ArrayOfString }
*
*/
public void setReasonDescription(ArrayOfString value) {
this.reasonDescription = value;
}
/**
* Gets the value of the expansionScore property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExpansionScore() {
return expansionScore;
}
/**
* Sets the value of the expansionScore property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExpansionScore(String value) {
this.expansionScore = value;
}
/**
* Gets the value of the expansionScoreDescription property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExpansionScoreDescription() {
return expansionScoreDescription;
}
/**
* Sets the value of the expansionScoreDescription property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExpansionScoreDescription(String value) {
this.expansionScoreDescription = value;
}
}
Generated consumer class: EmpericaEM04.java
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0
// See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2021.05.26 at 04:38:27 PM SAST
//
package com.soap.api.xxx.consumer;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for EmpiricaEM04 complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="EmpiricaEM04">
* <complexContent>
* <extension base="{https://secure.xxx.co.za/TUBureau}Empirica">
* <sequence>
* <element name="ConsumerNo" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="EmpiricaScore" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ExclusionCode" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ExclusionCodeDescription" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ReasonCode" type="{https://secure.xxx.co.za/TUBureau}ArrayOfString" minOccurs="0"/>
* <element name="ReasonDescription" type="{https://secure.xxx.co.za/TUBureau}ArrayOfString" minOccurs="0"/>
* <element name="ExpansionScore" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="ExpansionScoreDescription" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* </sequence>
* </extension>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "EmpiricaEM04", propOrder = {
"consumerNo",
"empiricaScore",
"exclusionCode",
"exclusionCodeDescription",
"reasonCode",
"reasonDescription",
"expansionScore",
"expansionScoreDescription"
})
public class EmpiricaEM04
extends Empirica
{
@XmlElement(name = "ConsumerNo")
protected String consumerNo;
@XmlElement(name = "EmpiricaScore")
protected String empiricaScore;
@XmlElement(name = "ExclusionCode")
protected String exclusionCode;
@XmlElement(name = "ExclusionCodeDescription")
protected String exclusionCodeDescription;
@XmlElement(name = "ReasonCode")
protected ArrayOfString reasonCode;
@XmlElement(name = "ReasonDescription")
protected ArrayOfString reasonDescription;
@XmlElement(name = "ExpansionScore")
protected String expansionScore;
@XmlElement(name = "ExpansionScoreDescription")
protected String expansionScoreDescription;
/**
* Gets the value of the consumerNo property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getConsumerNo() {
return consumerNo;
}
/**
* Sets the value of the consumerNo property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setConsumerNo(String value) {
this.consumerNo = value;
}
/**
* Gets the value of the empiricaScore property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getEmpiricaScore() {
return empiricaScore;
}
/**
* Sets the value of the empiricaScore property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setEmpiricaScore(String value) {
this.empiricaScore = value;
}
/**
* Gets the value of the exclusionCode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExclusionCode() {
return exclusionCode;
}
/**
* Sets the value of the exclusionCode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExclusionCode(String value) {
this.exclusionCode = value;
}
/**
* Gets the value of the exclusionCodeDescription property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExclusionCodeDescription() {
return exclusionCodeDescription;
}
/**
* Sets the value of the exclusionCodeDescription property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExclusionCodeDescription(String value) {
this.exclusionCodeDescription = value;
}
/**
* Gets the value of the reasonCode property.
*
* @return
* possible object is
* {@link ArrayOfString }
*
*/
public ArrayOfString getReasonCode() {
return reasonCode;
}
/**
* Sets the value of the reasonCode property.
*
* @param value
* allowed object is
* {@link ArrayOfString }
*
*/
public void setReasonCode(ArrayOfString value) {
this.reasonCode = value;
}
/**
* Gets the value of the reasonDescription property.
*
* @return
* possible object is
* {@link ArrayOfString }
*
*/
public ArrayOfString getReasonDescription() {
return reasonDescription;
}
/**
* Sets the value of the reasonDescription property.
*
* @param value
* allowed object is
* {@link ArrayOfString }
*
*/
public void setReasonDescription(ArrayOfString value) {
this.reasonDescription = value;
}
/**
* Gets the value of the expansionScore property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExpansionScore() {
return expansionScore;
}
/**
* Sets the value of the expansionScore property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExpansionScore(String value) {
this.expansionScore = value;
}
/**
* Gets the value of the expansionScoreDescription property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getExpansionScoreDescription() {
return expansionScoreDescription;
}
/**
* Sets the value of the expansionScoreDescription property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setExpansionScoreDescription(String value) {
this.expansionScoreDescription = value;
}
}
SoapConfig.Java
@Configuration
public class SoapConfig {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
String[] packages = {"com.soap.api.xxx.commercial", "com.soap.api.xxx.consumer"};
marshaller.setPackagesToScan(packages);
return marshaller;
}
}
I had to generate the classes seperately because if I try generating both classes at the same time it gives me an error saying the class name has already been created.
POM.xml
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-XautoNameResolution</arg>
</args>
<generatePackage>com.soap.api.xxx.commercial</generatePackage>
<generateDirectory>${project.basedir}/src/main/java</generateDirectory>
<schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
</configuration>
</plugin>
Full Error
Two classes have the same XML type name "{https://secure.xxx.co.za/TUBureau}EmpiricaEM04". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at com.soap.api.xxx.commercial.EmpiricaEM04
at @javax.xml.bind.annotation.XmlSeeAlso(value={com.soap.api.xxx.commercial.EmpiricaEM04.class, com.soap.api.xxx.commercial.EmpiricaE1.class})
at @javax.xml.bind.annotation.XmlSeeAlso(value={com.soap.api.xxx.commercial.AccountVerificationVA.class, com.soap.api.xxx.commercial.ComplianceIndicatorLI.class