Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 897
Withheld Avatar asked Nov 22 '13 20:11

Withheld


2 Answers

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.

like image 200
Heri Avatar answered Oct 07 '22 08:10

Heri


I notice the cfx examples use slightly different locations for sourceRoot, wsdl and wsdlLocation.

Remember that typically, files in src/main/resources are included in the produced artifact. In order for files in src/main/wsdl to be included, it needs to be added as a resource in the pom.xml:

<resources>
    <resource>
        <directory>src/main/wsdl</directory>
    </resource>
</resources>

Tips:

  • Set the paths you suspect to known bad paths and see if you get the same error-message.
  • Unzip the produced *.jar-file(s) and check if the wsdl is included, and what the path is.
like image 43
andrel Avatar answered Oct 07 '22 10:10

andrel