3

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.

3
  • have you tried generating those java classes into the same package? perhaps the duplicates will overwrite each other? Aug 26, 2014 at 21:23
  • 1
    Yes, I have tried that already. However, the problem is that my solution overrides ObjectFactory, which is generated from each WSDL file. Each ObjectFactory is more or less unique for each WSDL file. Aug 27, 2014 at 20:11
  • ah.. didn't think about that scenario. i'm not sure if this can be avoided without further tweaking of the actual source that converts those definitions to POJOs. I guess you could copy to the common package to serve as your base, and then run wsimport separately to get all the ObjectFactory definitions for your purposes. Tedious work, but still a viable workaround. OR, perhaps if you can find a tool that can merge multiple wsdl's properly... maybe that can be a better solution? Aug 27, 2014 at 20:34

2 Answers 2

1

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.

4
  • 1
    Thank you so much for your answer. I tried your solution, However, this did not solve my problem. It generates the classes for each WSDL file. But it also overwrites the ObjectFactory class. I need a solution where the ObjectFactory is either merged or each ObjectFactory change name. Sep 1, 2014 at 7:52
  • You sure it's not merged? Consider asking on the CXF mailing list. Sep 2, 2014 at 4:30
  • Yes, I'm sure that it is not merged. Thank you for the suggestion. I will do so. Sep 3, 2014 at 6:19
  • 1
    Did you find a solution to the issue of ObjectFactory class not being merged or it being overwritten on every iteration over the wsdl files? Sep 11, 2021 at 22:32
0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.