Reputation: 364
I'm currently involved in a project where we have to integrate our system to an external system. The company responsible for the external system have provided us multiple WSDL and corresponding XSD files (Over 100 WSDL files). Each WSDL file contains information about various services and the XSD files contains information about the types used for each service.
The problem I'm currently facing is when I'm generating Java classes from these XSD files. Many of the XSD files contains the same type. Lets say that almost all of these XSD files contains information about "User". The User type is identical in all the XSD files and have the same namespace. When generating Java classes from these WSDL files and placing them in different packages, I end up with over hundred version of the same class. If I put all the Java classes in the same package, I override ObjectFactory.
So when I generate Java classes from one WSDL file, the result will be in about hundred Java classes. Fifty of these classes are the same in all the other WSDL files and the rest are unique for just that WSDL file.
My question is the following: What is the best practice to handle these kind of scenarios? Would it be possible to merge all these WSDL files into one file and then generate classes from that? Or when I'm generating the Java classes, would it be possible to extract all the common classes into a separate package?
At the moment we use Apache CXF and Maven (cxf-codegen-plugin) to generate our classes and then do some manual work. However, I believe there should be a more efficient method to handle this.
I appreciate all the help I can get on the problem.
Upvotes: 3
Views: 7692
Reputation: 455
This is how i managed to solve the problem.
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.basedir}/src/main/java</sourceRoot>
<wsdlOptions>
<!-- for debtProjections.wsdl -->
<wsdlOption>
<autoNameResolution>true</autoNameResolution>
<wsdl>${project.basedir}/src/main/resources/wsdl/debtProjections.wsdl</wsdl>
<wsdlLocation>classpath:/wsdl/debtProjections.wsdl</wsdlLocation>
<extraargs>
<extraarg>-verbose</extraarg>
<extraarg>-p</extraarg>
<extraarg>com.mof.ws.debtprojections.service</extraarg>
</extraargs>
</wsdlOption>
<!-- for reference.wsdl -->
<wsdlOption>
<autoNameResolution>false</autoNameResolution>
<wsdl>${project.basedir}/src/main/resources/wsdl/reference.wsdl</wsdl>
<wsdlLocation>classpath:/wsdl/reference.wsdl</wsdlLocation>
<extraargs>
<extraarg>-verbose</extraarg>
<extraarg>-p</extraarg>
<extraarg>com.mof.ws.reference.service</extraarg>
</extraargs>
</wsdlOption>
<!-- for dsbProjections.wsdl -->
<wsdlOption>
<autoNameResolution>false</autoNameResolution>
<wsdl>${project.basedir}/src/main/resources/wsdl/dsbProjections.wsdl</wsdl>
<wsdlLocation>classpath:/wsdl/dsbProjections.wsdl</wsdlLocation>
<extraargs>
<extraarg>-verbose</extraarg>
<extraarg>-p</extraarg>
<extraarg>com.mof.ws.dbsprojections.service</extraarg>
</extraargs>
</wsdlOption>
<!-- for debtService?wsdl -->
<wsdlOption>
<autoNameResolution>false</autoNameResolution>
<wsdl>${project.basedir}/src/main/resources/wsdl/debtService.wsdl</wsdl>
<wsdlLocation>classpath:/wsdl/debtService.wsdl</wsdlLocation>
<extraargs>
<extraarg>-verbose</extraarg>
<extraarg>-p</extraarg>
<extraarg>com.mof.ws.debtservice.service</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
Upvotes: 0
Reputation: 67370
In the jaxws-maven-plugin you can specify multiple wsdls at once:
<configuration>
<keep>true</keep>
<extension>true</extension>
<catalog>XXX-models/catalog.xml</catalog>
<packageName>com.yyy.client</packageName>
<wsdlUrls>
<wsdlUrl>${basedir}/xml-resources/web-service-references/JobSession/wsdl/JobSessionService.wsdl</wsdlUrl>
<wsdlUrl>${basedir}/xml-resources/web-service-references/ZZZWSService/wsdl/ZZZWSService.wsdl</wsdlUrl>
....
Looking at the documentation, it looks like you can do this with CXF, too. See the wsdlOptions
element.
If this doesn't help, you should post the relevant part of your pom.xml.
Upvotes: 1