You should have deployed instantsoap-ws-echotest.war to Tomcat as described in the section Deploying the Echotest WAR . If you have worked through Using the JSP Management Interface then you will also have invoked exposed applications through the web interface.
In this section, we will develop a Java command-line application that accesses the available applications, build it using Maven and run it to invoke the application.
Before you start this section, you should ensure that you have a working deployment of instantsoap-ws-echotest.war as described in Deploying the Echotest WAR . You must also have Maven 2 installed and configured on your system, as described in requirements .
Firstly, we will set up a maven project with the source code for a client and a pom.xml file to tell maven how to build it.
echo-client
and change directory into it.
<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>uk.ac.ncl.cs.instantsoap.examples</groupId>
<artifactId>gettingStartedCommandLineClient</artifactId>
<packaging>jar</packaging>
<name>Test Client for instantsoap</name>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>uk.ac.ncl.cs.instantsoap</groupId>
<artifactId>instantsoap-api</artifactId>
<version>1.0</version>
</dependency>
<!-- CXF -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>Client</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/assemble/src.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>fluxion</id>
<name>Fluxion repository</name>
<url>http://metagenome.ncl.ac.uk/fluxions/repo</url>
</repository>
<repository>
<id>apache-snapshots</id>
<name>Apache SNAPSHOT Repository</name>
<url>http://people.apache.org/repo/m2-snapshot-repository/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>apache-incubating</id>
<name>Apache Incubating Repository</name>
<url>http://people.apache.org/repo/m2-incubating-repository/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>fluxion</id>
<name>Fluxion repository</name>
<url>http://metagenome.ncl.ac.uk/fluxions/repo</url>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<repository>
<id>fluxions</id>
<name>Fluxion repository</name>
<url>scp://metagenome.ncl.ac.uk/var/www/fluxions/repo/</url>
</repository>
<snapshotRepository>
<id>fluxions-snapshot</id>
<name>Fluxion snapshot repository</name>
<url>scp://metagenome.ncl.ac.uk/var/www/fluxions/repo-snapshot/</url>
</snapshotRepository>
</distributionManagement>
</project>
echo-client
called src/main/java and copy the
following
text into a file in that
directory called
Client.java.
import org.springframework.context.support.*;
import uk.ac.ncl.cs.instantsoap.wsapi.*;
import static uk.ac.ncl.cs.instantsoap.wsapi.Wsapi.*;
import java.util.*;
public class Client
{
public static void main(String[] args)
throws Throwable
{
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext(new String[] {"client-beans.xml"});
WebServiceDispatcher dispatcher = (WebServiceDispatcher) context.getBean("client");
JobSpecification js = jobSpecification(
"stringEcho",
pair("messageIn", "Hi Mum!"));
Map<String, String> results = invoke(dispatcher, js);
System.out.println("The message was: " + results.get("messageOut"));
}
}
echo-client
called src/main/resources and copy the
following
text into a file in that directory called
client-beans.xml.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schema/jaxws.xsd">
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property
name="serviceClass"
value="uk.ac.ncl.cs.instantsoap.wsapi.WebServiceDispatcher"/>
<property
name="address"
value="http://localhost:8080/instantsoap-ws-echotest-1.0/services/instantsoap/applications"/>
</bean>
<bean id="client" class="uk.ac.ncl.cs.instantsoap.wsapi.WebServiceDispatcher"
factory-bean="clientFactory" factory-method="create"/>
</beans>
echo-client.
mvn install exec:java
If this has gone as expected, maven should build the
project and run the client. In amongst the logging
information (lines starting with
INFO:) there should be the output
The message was: Hi Mum!
If instead there was some error, try running maven with
-X
to get it to display verbose information including
stack-traces.
mvn -X install exec:java
Also, ensure that you have a running instantsoap
installation, and that the
client-beans.xml
file is pointing to the right URL for it.
You can obtain the compete source for this example in tar.gz or zip formats.