Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jaxws-maven-plugin resolving WSDL location relative to class location, why?

I'm using the jaxws-maven-plugin version 2.1. I've found out very strange code generated for WSDL location from jar resources:

                <configuration>
                    <keep>true</keep>
                    <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
                    <extension>true</extension>
                    <wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
                    <packageName>my.package.gen</packageName>
                    <wsdlLocation>wsdl/*</wsdlLocation>
                    <wsdlFiles>
                        <wsdlFile>mywsdl.wsdl</wsdlFile>                            
                    </wsdlFiles>
                </configuration>

And the code generated is:

static {
    URL url = null;
    try {
        URL baseUrl;
        baseUrl = my.package.gen.My_Service.class.getResource(".");
        url = new URL(baseUrl, "wsdl/mywsdl.wsdl");
    } catch (MalformedURLException e) {
        logger.warning("Failed to create URL for the wsdl Location: 'wsdl/mywsdl.wsdl', retrying as a local file");
        logger.warning(e.getMessage());
    }
    MYSERVICE_WSDL_LOCATION = url; }

So the wsdl file is looked up in the directory (package) the generated class residents, and not in the main jar directory, as would be logical. And the WSDL can't be found.

Is it a bug in jaxws-maven-plugin, or it is the error in my configuration?

like image 944
Danubian Sailor Avatar asked Jan 10 '13 09:01

Danubian Sailor


People also ask

What is WSDL location?

The wsdl-location command specifies the name and the location of the WSDL document that defines the web service that is used by the API type is SOAP. This command is relevant only when the value of the type command is wsdl .

Where do I put WSDL files?

The files referenced by the <wsdl-file> element in the webservices. xml might import other WSDL or XML Schema Definition (XSD) files. Typically, all WSDL or XSD files are initially placed into the META-INF/wsdl directory when using Enterprise JavaBeans (EJB) or the WEB-INF/wsdl directory when using Java™.

What is wsimport?

The wsimport tool reads an existing WSDL file and generates the following artifacts: Service Endpoint Interface (SEI) - The SEI is the annotated Java representation of the WSDL file for the web service. This interface is used for implementing JavaBeans endpoints or creating dynamic proxy client instances. javax. xml.


2 Answers

You should use jaxws-maven-plugin version 2.3 instead of 2.1 and the result will be as you would expected.

The output of version 2.3 like this (if your wsdl folder is under src/main/resources):

URL url = <Any>.class.getClassLoader().getResource("wsdl/anywsdl.wsdl");
like image 140
Miklos Krivan Avatar answered Oct 18 '22 19:10

Miklos Krivan


For the generation of

url = new URL(baseUrl, "wsdl/mywsdl.wsdl");

This is the intended behavior, according to this,

http://jax-ws-commons.java.net/jaxws-maven-plugin/wsimport-mojo.html#wsdlLocation

It depends on what you want to do.

If what troubles you is

My_Service.class.getResource(".");

You can get rid of the point (relative path) with something like :

<plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>replacer</artifactId>
        <version>1.5.0</version>
        <executions>
          <execution>
            <phase>process-sources</phase>
            <goals>
              <goal>replace</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <file>target/generated-sources/wsimport/lu/hitec/webservices/pssu/${wsdl.app}/${interface.name}_Service.java</file>
          <replacements>
            <replacement>
              <token>_Service\.class\.getResource\("\."\)</token>
              <value>_Service\.class\.getResource\(""\)</value>
            </replacement>
          </replacements>
        </configuration>
      </plugin>
like image 28
Samuel EUSTACHI Avatar answered Oct 18 '22 19:10

Samuel EUSTACHI