SOAP Client with Maven

In combination with maven it is very simple to generate the access layer to an webservice by using its wsdl.

For this example I used an web service which gives access to the results of soccer league games: http://www.openligadb.de/.

First of all i had to decide which SOAP implementation and generator to use. I found three candidates:

To use them with maven an corresponding plugin is needed. The plugin for jax-ws was the simplest one to use:

https://jax-ws-commons.dev.java.net/jaxws-maven-plugin/

After creating the maven project i modified the pom.xml and added this plugin:


<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.uebelacker.openligaclient</groupId>
<artifactId>openligaclient</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>openligaclient</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlUrls>
<param>http://www.openligadb.de/Webservices/Sportsdata.asmx?WSDL</param>
</wsdlUrls>
<packageName>ch.uebelacker.openligaclient</packageName>
<extension>true</extension>
</configuration>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.1.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

After executing mvn install, i have everything i need to access the webservice:

Sportsdata tSportsdata = new Sportsdata();
for ( League tLeague : tSportsdata.getSportsdataSoap().getAvailLeagues().league )
{
    System.out.println(tLeague.getLeagueShortcut() + " - " + tLeague.getLeagueName());
}

Proxy
If you’re behind a proxy you can pass the proxy configuration to the vm:

-Dhttp.proxyHost=192.168.82.1
-Dhttp.proxyPort=3128

posted in Development by david

Follow comments via the RSS Feed | Einen Kommentar hinterlassen | Trackback URL

Leave Your Comment