javamavencxfcxf-codegen-plugin

How to generate WebService client with CXF wsdl2java for online WSDL URL link


I am trying to generate a webservice client with the wsdl2java goal of the Apache CXF Maven Plugin. I have a WSDL URL link, but when using the Maven plugin, it is not generating the sources. Sample WSDL link is http://www.webservicex.com/globalweather.asmx?WSDL.

<properties>
        <src.generated.dir>src/main/java</src.generated.dir>
        <artifact.cxf.version>3.1.6 </artifact.cxf.version>
        <xerces.version>2.11.0</xerces.version>
        <inbound.wsdl>http://www.webservicex.com/globalweather.asmx?WSDL</inbound.wsdl>
        <inbound.wsdl.location>http://www.webservicex.com/globalweather.asmx?WSDL</inbound.wsdl.location>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${artifact.cxf.version}</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>${src.generated.dir}</sourceRoot>
                            <defaultOptions>
                                <noAddressBinding>true</noAddressBinding>
                                <faultSerialVersionUID>3105839350746982386</faultSerialVersionUID>
                            </defaultOptions>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${inbound.wsdl}</wsdl>
                                    <wsdlLocation>${inbound.wsdl.location}</wsdlLocation>
                                    <serviceName>webservicex</serviceName>
                                    <extraargs>
                                        <extraarg>-client</extraarg>
                                        <extraarg>-verbose</extraarg>
                                        <extraarg>-p</extraarg>
                                        <extraarg>http://webservicex.ent.com/arm/=com.ent.webservicex.arm</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>xerces</groupId>
                        <artifactId>xercesImpl</artifactId>
                        <version>${xerces.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

Solution

  • The problem is not related to the use of a HTTP link to a WSDL file. The error that the CXF Codegen Plugin returns is:

    No service was found in wsdl: webservicex

    This is normal because the WSDL hosted at http://www.webservicex.com/globalweather.asmx?WSDL only has a single service named GlobalWeather; it does not have a service called webservicex. A service definition in a WSDL corresponds to a wsdl:service element, and if you peek into the WSDL, you'll only see

    <wsdl:service name="GlobalWeather">
      <!-- ... -->
    </wsdl:service>
    

    Thus, you should change your CXF configuration to

    <serviceName>GlobalWeather</serviceName>
    

    or even omit the parameter completely and let the plugin generate it automatically (since there's only one service).


    There are other related notes with your current configuration that it would be best to change: