Reputation: 2623
I have two WSDLs from which I generate Java code using maven cxf-codegen-plugin (org.apache.cxf). Both of them use the same namespace and contains complex types of the same name which was reason why I experienced issues with conflicting java class names. I decided to solve it using bindings.xml:
<jaxws:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns="http://www.w3.org/2001/XMLSchema"
version="2.1">
<jaxws:bindings wsdlLocation="./TaskService_v1.wsdl" node="xsd:schema">
<jaxb:schemaBindings>
<jaxb:nameXmlTransform>
<jaxb:typeName prefix="TaskService" />
<jaxb:elementName prefix="TaskService" />
</jaxb:nameXmlTransform>
</jaxb:schemaBindings>
</jaxws:bindings>
</jaxws:bindings>
This renamed for example generated class B2BParameter to TaskServiceB2BParameter so I stopped getting conflicting names issues but I ran into another issue:
Unknown JAXB exception; nested exception is com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 4 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://serviceinterface.b2b.adx.com}B2BParameter". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at com.adx.b2b.serviceinterface.TaskServiceB2BParameter
this problem is related to the following location:
at com.adx.b2b.serviceinterface.B2BParameter
at protected java.util.List com.adx.b2b.serviceinterface.B2BRequest.parameter
at com.adx.b2b.serviceinterface.B2BRequest
...
This is generated TaskServiceB2BParameter.java:
package com.axd.b2b.serviceinterface_v1;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "B2BParameter", propOrder = {
"name",
"value"
})
public class TaskServiceB2BParameter {
...
}
How can update my bindings.xml to change @XmlType.name appropriately? Or do I really need to change target package? Thank you in advance!
Upvotes: 2
Views: 4149
Reputation: 2623
The problem was that single marshaller found classes with the same element name. I resolved this problem this way:
1) Generate classes into different packages
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.3.3</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/META-INF/wsdl/Service1.xml</wsdl>
<packagenames>
<packagename>com.xxx.service1</packagename>
</packagenames>
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/META-INF/wsdl/Service2.xml</wsdl>
<packagenames>
<packagename>com.xxx.service2</packagename>
</packagenames>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
2) Create special marshaller bean for each service
@Configuration
public class WebServiceConfig {
@Bean
public Jaxb2Marshaller service1Marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("com.xxx.service1");
return marshaller;
}
@Bean
public Jaxb2Marshaller service2Marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("com.xxx.service2");
return marshaller;
}
}
Upvotes: 1