Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting java classes from multiple wsdls

Tags:

java

wsdl

maven

I have a Maven project where i need to generate java classes from multiple wsdl files. I have analysed using maven plugins axistools-maven-plugin and cxf-codegen-plugin but the problem i am facing are is that Java files from different wsdl's should go to different packages.

I have checked this link : http://decimalsolutions.blogspot.in/2011/10/wsdl2java-maven2.html but it doesn't solve my problem.

How to achieve this?

like image 652
Lokesh Avatar asked Sep 03 '13 14:09

Lokesh


3 Answers

The documentation states you can use the <extraarg> element to pass in parameters to the wdsl to java process. So, you can configure your cxf-codegen-plugin in the following manner

<configuration>
    <sourceRoot>${project.build.directory}/generated-code/mywebservice</sourceRoot>
    <wsdlOptions>
        <wsdlOption>
            <wsdl>${basedir}/src/main/resources/wsdl/serviceOne.wsdl</wsdl>
            <extraargs>
                <extraarg>-p</extraarg>
                <extraarg>first.packagename</extraarg>
            </extraargs>
        </wsdlOption>
        <wsdlOption>
            <wsdl>${basedir}/src/main/resources/wsdl/serviceTwo.wsdl</wsdl>
                <extraargs>
                <extraarg>-p</extraarg>
                <extraarg>another.packagename</extraarg>
            </extraargs>
        </wsdlOption>
    </wsdlOptions>
</configuration>
like image 169
JustDanyul Avatar answered Nov 10 '22 05:11

JustDanyul


With a jaxb binding file, you can change the package (see this documentation).

If you're using maven and the cxf plugin, you can add this to your pom.xml:

      <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>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl><path_to_wsdl</wsdl>
                                <frontEnd>jaxws21</frontEnd>
                                <faultSerialVersionUID>1</faultSerialVersionUID>
                                <bindingFiles>
                                    <bindingFile>src/main/resources/binding.xml</bindingFile>
                                </bindingFiles>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-fluent-api</artifactId>
                    <version>3.0</version>
                </dependency>
                <dependency>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics</artifactId>
                    <version>0.6.4</version>
                </dependency>
            </dependencies>
        </plugin>
like image 21
MystyxMac Avatar answered Nov 10 '22 05:11

MystyxMac


Have you looked at XJC bindings, there are some notes on the Oracle site and if you are happy with the CXF plugin you can pass a separate bindings file for each WSDL using the code you can see in example one on the plugin's site.

An example fragment from the plugin configuration:

...
<configuration>
   <wsdlOptions>
      <wsdlOption>
          <wsdl>${basedir}/src/main/resources/wsdl/first.wsdl</wsdl>
          <bindingFiles>
              <bindingFile>${basedir}/src/main/resources/first.xjb</bindingFile>
          </bindingFiles>
      </wsdlOption>
      <wsdlOption>
          <wsdl>${basedir}/src/main/resources/wsdl/second.wsdl</wsdl>
          <bindingFiles>
              <bindingFile>${basedir}/src/main/resources/second.xjb</bindingFile>
          </bindingFiles>
      </wsdlOption>
   </wsdlOptions>
</configuration>
...

Where first.xjb would contain:

<jaxws:bindings wsdlLocation="path/to//serviceOne.wsdl"
      xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema">
    <jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        ...
    </jxb:globalBindings>

    <jxb:schemaBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
        <jxb:package name="your.first.package"/>
    </jxb:schemaBindings>
  </jaxws:bindings>
</jaxws:bindings>

Now you can configure all manner of translations and mappings.

like image 2
JohnMark13 Avatar answered Nov 10 '22 04:11

JohnMark13