Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Java files from multiple WSDL files

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.

like image 246
Karl Dahlgren Avatar asked Apr 28 '26 20:04

Karl Dahlgren


1 Answers

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.

like image 160
Daniel Kaplan Avatar answered May 01 '26 08:05

Daniel Kaplan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!