Apache CXF - How can I automate WSDL relative path resolution for Client Stubs generation?

时间:2015-07-28 23:51:02

标签: web-services xsd cxf maven-3 wsdl2java

enter image description here

In my maven project in order to generating client stubs using apache cxf, I've configured the pom as follows:

B12
C12
D12
E12
F12
G12
B18
C18
D18
E18
F18
G18

Then I've downloaded "manually" all the WSDLs from the server, which exposes the web services, into my resource project folder "\my-project\src\main\resources\wsdl" and all the related XSDs inside my xsd project folder "\my-project\src\main\resources\wsdl\xsd". After that I've changed manually all the schemaLocation inside the WSDLs file in order to have only relative path (then running cxf generation the java client stubs are correctly generated).

Example:

Inside a wsdl I've changed:

 <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>
        <goals>
          <goal>wsdl2java</goal>
        </goals>
        <configuration>
          <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
            <frontEnd>jaxws21</frontEnd>
            <markGenerated>true</markGenerated>
            <xjcargs>
              <xjcarg>-Xts</xjcarg>
            </xjcargs>
          </defaultOptions>
          <wsdlOptions>
            <wsdlOption>
              <wsdl>${basedir}/src/main/resources/wsdl/MyServiceA_v1.wsdl</wsdl>
              <wsdlLocation>classpath:wsdl/MyServiceA_v1.wsdl</wsdlLocation>
            </wsdlOption>
            <wsdlOption>
              <wsdl>${basedir}/src/main/resources/wsdl/MyServiceB_v1.wsdl</wsdl>
              <wsdlLocation>classpath:wsdl/MyServiceB_v1.wsdl</wsdlLocation>
            </wsdlOption>
     </wsdlOptions>
        </configuration>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>org.apache.cxf.xjcplugins</groupId>
        <artifactId>cxf-xjc-ts</artifactId>
        <version>2.6.1</version>
      </dependency>
    </dependencies>
  </plugin>
</plugins>

with the relative path (related to the folder \my-project\src\main\resources\wsdl\xsd)

 <xs:import namespace="http://ws.myproject.priv.schema/MyServiceA/v1" schemaLocation="http://161.29.123.124:8080/web-1.0/ws/MyServiceA_v1?myServiceA_v1.0.xsd"/>

Is there a way (with maven, apache cxf, ant or something else...) to download automatically all the WSDLs and XSDs from the server to my folders and then automatically changing the server paths with my project relative paths? How can I automate this process?

0 个答案:

没有答案