"Can not initialize the default wsdl from..." -- Why?

Withheld picture Withheld · Nov 22, 2013 · Viewed 7.1k times · Source

My pom.xml contains the following to auto generate a client for a working web service having the WSDL specified below:

        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>2.3.1</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <configuration>
                        <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl>${basedir}/src/main/wsdl/myclient.wsdl</wsdl>
                                <extraargs>
                                    <extraarg>-client</extraarg>
                                    <extraarg>-verbose</extraarg>
                                </extraargs>
                                <wsdlLocation>wsdl/myclient.wsdl</wsdlLocation>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

The project builds fine, without any errors or warnings and I can see the the file myclient.wsdl in the JAR file right under a wsdl folder.

But when I try running that JAR:

  java -Xmx1028m -jar myclient-jar-with-dependencies.jar

It complains that "Can not initialize the default wsdl from wsdl/myclient.wsdl"

Why?

What am I missing?

How can I find out what path that wsdl/myclient.wsdl in pom.xml translates into, that makes the client's JAR complain at run time?

Update: I am aware of some solutions/workarounds that involve modifying the auto-generated code:

  1. Pass "null" for the wsdl URL and then use the ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://example.com/....") to set the address.
  2. load the WSDL as a Java resource and pass its location into your service's constructor.

But I am more interested in a solution that requires entering the right values into the pom.xml like the classpath approach (but unfortunately classpath didn't work for me for some reason).

Any ideas what I should be typing there instead? Apparently this is a very simply case of figuring out the correct path rules for that particular plugin, but I am missing something and I don't know what it is.

Answer

Heri picture Heri · Feb 16, 2015

The error comes from the static initializer of your generated service class (which is annotated by @WebServiceClient). It tries to load the wsdl file as resource. The generator uses the value which you have provided by the parameter wsdlLocation. You should leave away the "wsdl/" prefix:

<wsdlLocation>myclient.wsdl</wsdlLocation>

because the wsdl is located directly in the root of the classpath folder.

BTW: If you omit the parameter <wsdlLocation> the value of the param <wsdl> is used (which is not correct at runtime in your case, but would be correct if the provided URL would be a remote URL address, i.e. directly fetched from the webservice server).

BTW2: Your workaround 2 is in fact +/- what the generated code of the service class does if you use the parameterless constructor.