...
This tutorial will explain how you can leverage the servicemix-jsr181 component to orchestrate web services. We will use two public web services:
- USZip which returns the Zip code for a US city
- LocalTime which gives the local time given a zip code
- ZIP Code Given City and State
- Forecast by ZIP Code
We will call them in a simple way to provide an aggregate web service which will return the weather forecast local time for a given city / state and expose it through as an HTTP/SOAP service.
...
First, we need to create the root maven project which will hold our SUs and SA. Launch the following commands:
Code Block |
---|
mkdir weathercitytime cd weathercitytime |
And create a file named pom.xml
with the following content:
Code Block | ||
---|---|---|
| ||
<project> <modelVersion>4.0.0</modelVersion> <groupId>org.apache.servicemix.samples</groupId> <artifactId>weather<<artifactId>citytime</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> </project> |
Then, we can use maven archetypes to create the two SUs and the SA. In the weather
citytime
directory, launch the following commands:
Code Block |
---|
cd weathercitytime mvn archetype:create \ -DarchetypeGroupId=org.apache.servicemix.tooling \ -DarchetypeArtifactId=servicemix-http-consumer-service-unit \ -DarchetypeVersion=3.1-incubating \ -DgroupId=org.apache.servicemix.samples.weathercitytime \ -DartifactId=weathercitytime-http-su mvn archetype:create \ -DarchetypeGroupId=org.apache.servicemix.tooling \ -DarchetypeArtifactId=servicemix-jsr181-wsdl-first-service-unit \ -DarchetypeVersion=3.1-incubating \ -DgroupId=org.apache.servicemix.samples.weathercitytime \ -DartifactId=weathercitytime-jsr181-su mvn archetype:create \ -DarchetypeGroupId=org.apache.servicemix.tooling \ -DarchetypeArtifactId=servicemix-service-assembly \ -DarchetypeVersion=3.1-incubating \ -DgroupId=org.apache.servicemix.samples.weathercitytime \ -DartifactId=weathercitytime-sa |
Warning | |||||
---|---|---|---|---|---|
| |||||
Due to a bug in the 3.1 archetypes, you need to edit the
|
This will create the following directory structure:
Code Block |
---|
bridgecitytime\ pom.xml weathercitytime-http-su\ ... weathercitytime-jsr181-su\ ... weathercitytime-sa\ ... |
Generating Eclipse projects
Now that we have the projects created, be can import them in Eclipse. Run the following command to build the eclipse project files:
Code Block |
---|
cd weathercitytime mvn eclipse:eclipse |
Now, we can import the projects in Eclipse.
...
The first thing to do is to design the WSDL that will be exposed as a service, so that we can generate the needed classes and implement the service.
Edit the weathercitytime/weathercitytime-jsr181-su/src/main/resources/service.wsdl
and replace it by the following one:
...
Then, grab the WSDL definitions for the two web services we will use. On Unix systems, you can use:
Code Block |
---|
cd weathercitytime/weathercitytime-jsr181-su/src/main/resources/ wget http://www.webservicex.com/uszip.asmx?WSDL mv uszip.asmx\@WSDL uszip.wsdl wget http://www.webservicexripedev.netcom/webservices/WeatherForecastLocalTime.asmx?WSDL mv WeatherForecastLocalTime.asmx\@WSDL WeatherForecastLocalTime.wsdl |
If you use Windows, just download from them your web browser and put them in the above directory.
...
Code Block | ||
---|---|---|
| ||
<wsgen outputDirectory="${basedir}/target/generated-sources" explicitAnnotation="true" profile="org.codehaus.xfire.jaxws.gen.JAXWSProfile" wsdl="${basedir}/src/main/resources/service.wsdl"></wsgen> <wsgen outputDirectory="${basedir}/target/generated-sources" explicitAnnotation="true" profile="org.codehaus.xfire.jaxws.gen.JAXWSProfile" wsdl="${basedir}/src/main/resources/WeatherForecastLocalTime.wsdl"></wsgen> <wsgen outputDirectory="${basedir}/target/generated-sources" explicitAnnotation="true" profile="org.codehaus.xfire.jaxws.gen.JAXWSProfile" wsdl="${basedir}/src/main/resources/uszip.wsdl"></wsgen> |
...
and
Code Block | ||||
---|---|---|---|---|
| ||||
<wsdl:service name="WeatherForecastLocalTime"> <wsdl:port name="WeatherForecastSoapLocalTimeSoap" binding="tns:WeatherForecastSoapLocalTimeSoap"> <soap:address location="http://www.webservicexripedev.netcom/webservices/WeatherForecastLocalTime.asmx" /> </wsdl:port> </wsdl:service> |
Now, generate all the classes from these three WSDLs by launching:
Code Block |
---|
cd weathercitytime/weathercitytime-jsr181-su mvn generate-sources |
Before refreshing your project, you can create the folder that will hold our implementation:
Code Block |
---|
cd weathercitytime/weathercitytime-jsr181-su mkdir src/main/java mvn eclipse:eclipse |
...