WSDL consume - What tool to use?
Question
I'm having trouble understanding how to make a web service client. The story is that I need to make a call to a web service. As I then understand it I need to somehow consume the web service to get the correct classes of the web service.
I've investigated a numerous of ways to do this. For example I've tried consuming them with a script and then just import the classes.
However, a colleague of my recommended that I would try using the Maven-plugin wsdl2code since we already use Maven-2 . Doing this works but creates a lot of junk files as I see it. I've added following into my pom.xml file:
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<packageName>ws.client.test</packageName>
<wsdlFile>http://localhost:8088/test?WSDL</wsdlFile>
<databindingName>xmlbeans</databindingName>
<outputDirectory>target/ws/test</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
This creates the files successfully, but as said, there's also a lot of junk files( xmlsoap/schemas/soap/encoding/...) or at least a lot more files for no use (as I see it) than the other WSDLconsume I tried.
Questions
Is there a general guidelines how to consume a web service? Since the WSDL file is external it could also be changing, and therefor I thought it could be good having this done automatically in Maven (though there would be other side effects if the WSDL suddenly changed...).
If the wsdl2code is a good choice, should all the files always be created in the target-catalouge so
that they are being removed when executing mvn clean)?Is there any other tool that might fit better?
Update/Edit
By using for example JAX-WS wsimport I get the generated files that I desire.
However, by having these created in the /target-folder I want to reach them in the same project to actually call the web service. Is this possible?
Solution
If you have java-1.6 you can (should) use jax-ws, its very easy with onboard java tools. There is a good maven plugin that will create a webservice client, that can be used without any additional dependencies. Have a look at http://jax-ws-commons.java.net/jaxws-maven-plugin/
See http://blogs.oracle.com/enterprisetechtips/entry/using_jax_ws_with_maven for a detailed walkthrough.
OTHER TIPS
You can try CXF wsdl2java plugin. Also it's a good idea to store generated source in a separate source folder to avoid mess. So finally the configurations looks like this:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.3.0</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>src/main/generated</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>src/main/resources/your-service.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
<configuration>
<filesets>
<fileset>
<directory>src/main/generated</directory>
<includes>
<include>**/*.java</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/generated</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>