Orchestration with JSR181
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
We will call them in a simple way to provide an aggregate web service which will return the local time for a given city and expose it through as an HTTP/SOAP service.
For this tutorial, you will need a 3.1-incubating version of ServiceMix built from sources.
Project structure, SUs and SA
In this example, we will only use two components:
- servicemix-jsr181 for the orchestration part
- servicemix-http to expose and consume services through HTTP/SOAP
Thus we will have to create two service units and a service assembly.
First, we need to create the root maven project which will hold our SUs and SA. Launch the following commands:
mkdir citytime cd citytime
And create a file named pom.xml
with the following content:
<project> <modelVersion>4.0.0</modelVersion> <groupId>org.apache.servicemix.samples</groupId> <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 citytime
directory, launch the following commands:
cd citytime mvn archetype:create \ -DarchetypeGroupId=org.apache.servicemix.tooling \ -DarchetypeArtifactId=servicemix-http-consumer-service-unit \ -DarchetypeVersion=3.1-incubating \ -DgroupId=org.apache.servicemix.samples.citytime \ -DartifactId=citytime-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.citytime \ -DartifactId=citytime-jsr181-su mvn archetype:create \ -DarchetypeGroupId=org.apache.servicemix.tooling \ -DarchetypeArtifactId=servicemix-service-assembly \ -DarchetypeVersion=3.1-incubating \ -DgroupId=org.apache.servicemix.samples.citytime \ -DartifactId=citytime-sa
Due to a bug in the 3.1 archetypes, you need to edit the citytime-jsr181-su/pom.xml
file and edit the last xml section with the following:
<properties> <servicemix-version>3.1-incubating</servicemix-version> <xfire-version>1.2.2</xfire-version> </properties>
This will create the following directory structure:
citytime\ pom.xml citytime-http-su\ ... citytime-jsr181-su\ ... citytime-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:
cd citytime mvn eclipse:eclipse
Now, we can import the projects in Eclipse.
The jsr181 SU
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 citytime/citytime-jsr181-su/src/main/resources/service.wsdl
and replace it by the following one:
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CityTime" targetNamespace="http://servicemix.apache.org/samples/citytime" xmlns:tns="http://servicemix.apache.org/samples/citytime"> <wsdl:types> <xsd:schema targetNamespace="http://servicemix.apache.org/samples/citytime" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://servicemix.apache.org/samples/citytime"> <xsd:element name="GetCityTimeRequest"> <xsd:complexType> <xsd:sequence> <xsd:element name="City" type="xsd:string"></xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="GetCityTimeResponse"> <xsd:complexType> <xsd:sequence> <xsd:element name="string" type="xsd:string" minOccurs="0" maxOccurs="unbounded"> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </wsdl:types> <wsdl:message name="GetCityTimeRequest"> <wsdl:part name="GetCityTimeRequest" element="tns:GetCityTimeRequest"> </wsdl:part> </wsdl:message> <wsdl:message name="GetCityTimeResponse"> <wsdl:part name="GetCityTimeResponse" element="tns:GetCityTimeResponse"> </wsdl:part> </wsdl:message> <wsdl:portType name="CityTimePortType"> <wsdl:operation name="GetCityTime"> <wsdl:input message="tns:GetCityTimeRequest"></wsdl:input> <wsdl:output message="tns:GetCityTimeResponse"></wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="CityTimeSoapBinding" type="tns:CityTimePortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="GetCityTime"> <soap:operation soapAction="http://servicemix.apache.org/samples/citytime/GetCityTime" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="CityTime"> <wsdl:port name="Soap" binding="tns:CityTimeSoapBinding"> <soap:address location="http://www.example.org/" /> </wsdl:port> </wsdl:service> </wsdl:definitions>
Then, grab the WSDL definitions for the two web services we will use. On Unix systems, you can use:
cd citytime/citytime-jsr181-su/src/main/resources/ wget http://www.webservicex.com/uszip.asmx?WSDL mv uszip.asmx\@WSDL uszip.wsdl wget http://www.ripedev.com/webservices/LocalTime.asmx?WSDL mv LocalTime.asmx\@WSDL LocalTime.wsdl
If you use Windows, just download from them your web browser and put them in the above directory.
Then, we need to modify the pom.xml
file to generate the classes for the web services. The archetype we used already has a definition for the main WSDL, we just need to copy it for the two new WSDLs:
<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/LocalTime.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>
Unfortunately, the WSDL to Java generation does now handle well these WSDLs because they contain unsupported constructs.
You need the following service definitions:
<wsdl:service name="USZip"> <wsdl:port name="USZipSoap" binding="tns:USZipSoap"> <soap:address location="http://www.webservicex.com/uszip.asmx" /> </wsdl:port> </wsdl:service>
Now, generate all the classes from these three WSDLs by launching:
cd citytime/citytime-jsr181-su mvn generate-sources
Before refreshing your project, you can create the folder that will hold our implementation:
cd citytime/citytime-jsr181-su mkdir src/main/java mvn eclipse:eclipse
We will now create the service implementation. A skeleton has already been generated by the wsdl 2 java tool. We will just copy and rename this class in the src/main/java/org/apache/servicemix/samples/citytime
folder so that it won't be erased when generating the project again.
package org.apache.servicemix.samples.citytime; import javax.jws.WebService; @WebService(serviceName = "CityTime", targetNamespace = "http://servicemix.apache.org/samples/citytime", endpointInterface = "org.apache.servicemix.samples.citytime.CityTimePortType") public class CityTimeImpl implements CityTimePortType { public GetCityTimeResponse getCityTime(org.apache.servicemix.samples.citytime.GetCityTimeRequest GetCityTimeRequest) { throw new UnsupportedOperationException(); } }
But we need to remove the generation of this skeleton. In the pom.xml
of the citytime-jsr181-su
, add the generateServerStubs="false"
attribute on the three c<wsgen/>
tasks.
Now, create two properties for the services we use:
private USZipSoap usZip; private LocalTimeSoap localTime; public void setLocalTime(LocalTimeSoap localTime) { this.localTime = localTime; } public void setUsZip(USZipSoap usZip) { this.usZip = usZip; }
We can now code our orchestration logic in the getWeather
method:
public GetCityTimeResponse getCityTime(org.apache.servicemix.samples.citytime.GetCityTimeRequest GetCityTimeRequest) { GetInfoByCity GetInfoByCity = new GetInfoByCity(); GetInfoByCity.setUSCity(GetCityTimeRequest.getCity()); GetInfoByCityResponse r = usZip.getInfoByCity(GetInfoByCity); Element e = (Element) r.getGetInfoByCityResult().getContent().get(0); e = (Element) e.getElementsByTagName("Table").item(0); e = (Element) e.getElementsByTagName("ZIP").item(0); String ZipCode = e.getTextContent(); String lt = localTime.localTimeByZipCode(ZipCode); GetCityTimeResponse rep = new GetCityTimeResponse(); rep.setTime(lt); return rep; }
Writing JUnit test
A good habit is to write unit tests. One of the most common framework used is JUnit. Let's follow the maven conventions and create a few directories:
cd citytime/citytime-jsr181-su mkdir src/test mkdir src/test/java mkdir src/test/resources mvn eclipse:eclipse
We have regenerated the eclipse project, so we need to refresh it in eclipse to see the new folders.
Create a class in CityTimeTest
in the src/test/java
folder using Eclipse.
package org.apache.servicemix.samples.citytime; import java.text.SimpleDateFormat; import java.util.Date; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import junit.framework.TestCase; import net.webservicex.GetInfoByAreaCode; import net.webservicex.GetInfoByAreaCodeResponse; import net.webservicex.GetInfoByCity; import net.webservicex.GetInfoByCityResponse; import net.webservicex.GetInfoByState; import net.webservicex.GetInfoByStateResponse; import net.webservicex.GetInfoByZIP; import net.webservicex.GetInfoByZIPResponse; import net.webservicex.USZipSoap; import com.ripedev.xsd.zipcoderesults.LocalTimeSoap; public class CityTimeTest extends TestCase { public void test() throws Exception { CityTimeImpl citytime = new CityTimeImpl(); citytime.setUsZip(new MockUSZip()); citytime.setLocalTime(new MockLocalTime()); GetCityTimeRequest req = new GetCityTimeRequest(); req.setCity("New York"); GetCityTimeResponse resp = citytime.getCityTime(req); assertNotNull(resp.getTime()); System.out.println(resp.getTime()); } public static class MockUSZip implements USZipSoap { public GetInfoByAreaCodeResponse getInfoByAreaCode(GetInfoByAreaCode GetInfoByAreaCode) { return null; } public GetInfoByCityResponse getInfoByCity(GetInfoByCity GetInfoByCity) { try { JAXBContext ctx = JAXBContext.newInstance(GetInfoByCityResponse.class); Object r = ctx.createUnmarshaller().unmarshal(getClass().getResource("/GetInfoByCityResponse.xml")); return (GetInfoByCityResponse) r; } catch (JAXBException e) { e.printStackTrace(); return null; } } public GetInfoByStateResponse getInfoByState(GetInfoByState GetInfoByState) { return null; } public GetInfoByZIPResponse getInfoByZIP(GetInfoByZIP GetInfoByZIP) { return null; } } public static class MockLocalTime implements LocalTimeSoap { public String localTimeByZipCode(String ZipCode) { return new SimpleDateFormat().format(new Date()); } } }
The USZip service returns some data not described by the wsdl. Using SOAP UI, we can easily send a real request to the service and store the response in the src/test/resources/GetInfoByCityResponse.xml
file:
<?xml version="1.0" encoding="UTF-8"?> <GetInfoByCityResponse xmlns="http://www.webserviceX.NET"> <GetInfoByCityResult> <NewDataSet xmlns=""> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10001</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10002</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10003</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10004</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10005</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10006</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10007</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10008</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10009</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10010</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10011</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10012</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10013</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10014</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10015</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10016</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10017</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10018</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10019</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10020</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10021</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10022</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10023</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10024</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10025</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10026</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10027</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10028</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10029</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10030</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10031</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10032</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10033</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10034</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10035</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10036</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10037</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10038</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10039</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10040</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10041</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10043</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10044</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10045</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10046</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10047</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10048</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10055</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10060</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10069</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10072</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10079</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10080</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10081</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10082</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10087</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10090</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10094</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10095</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10096</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10098</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10099</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10101</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10102</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10103</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10104</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10105</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10106</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10107</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10108</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10109</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10110</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10111</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10112</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10113</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10114</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10115</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10116</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10117</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10118</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10119</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10120</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10121</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10122</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10123</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10124</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10125</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10126</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10128</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10129</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10130</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10131</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10132</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10133</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10138</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10149</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10150</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10151</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10152</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10153</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10154</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10155</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10156</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10157</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10158</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10159</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10160</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10161</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10162</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10163</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10164</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10165</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10166</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10167</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10168</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10169</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10170</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10171</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10172</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10173</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10174</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10175</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10176</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10177</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10178</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10184</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10185</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10196</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10197</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10199</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10203</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10211</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10212</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10213</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10242</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10249</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10256</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10257</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10258</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10259</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10260</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10261</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10265</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10268</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10269</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10270</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10271</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10272</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10273</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10274</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10275</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10276</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10277</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10278</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10279</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10280</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10281</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10282</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10285</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10286</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> <Table> <CITY>New York</CITY> <STATE>NY</STATE> <ZIP>10292</ZIP> <AREA_CODE>212</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> </NewDataSet> </GetInfoByCityResult> </GetInfoByCityResponse>
For this simple service, we will just extract the ZIP
of the first Table
element. That's the reason why the code of the CityTimeImpl
class uses the DOM Api to retrieve the Zip code.
Now, if you run the test (right-click on the class in the Eclipse explorer and launch "Run as ...|Unit test|". The test should be successful.
XBean.xml files
We have just coded and tested the service implementation, but we need to actually write the Service Units ...
The JSR181 SU will leverage the client proxy feature:
<beans xmlns:jsr181="http://servicemix.apache.org/jsr181/1.0" xmlns:localtime="http://ripedev.com/xsd/ZipCodeResults.xsd" xmlns:uszip="http://www.webserviceX.NET"> <jsr181:endpoint pojo="#citytime" wsdlResource="classpath:service.wsdl" typeMapping="jaxb2" annotations="jsr181" style="document" /> <bean id="citytime" class="org.apache.servicemix.samples.citytime.CityTimeImpl"> <property name="usZip"> <jsr181:proxy context="#context" type="net.webservicex.USZipSoap" service="uszip:USZip" /> </property> <property name="localTime"> <jsr181:proxy context="#context" type="com.ripedev.xsd.zipcoderesults.LocalTimeSoap" service="localtime:LocalTime" /> </property> </bean> </beans>
The HTTP SU will contain the two HTTP provider endpoints for SUZip and LocalTime services, along with the HTTP consumer for the CityTime service we are writing:
<beans xmlns:http="http://servicemix.apache.org/http/1.0" xmlns:citytime="http://servicemix.apache.org/samples/citytime" xmlns:localtime="http://ripedev.com/xsd/ZipCodeResults.xsd" xmlns:uszip="http://www.webserviceX.NET"> <http:endpoint service="citytime:CityTime" endpoint="Soap" role="consumer" locationURI="http://0.0.0.0:8192/citytime/" soap="true" /> <http:endpoint service="localtime:LocalTime" endpoint="LocalTimeSoap" role="provider" locationURI="http://www.ripedev.com/webservices/LocalTime.asmx" soap="true" soapAction="http://ripedev.com/xsd/ZipCodeResults.xsd/LocalTimeByZipCode" soapVersion="1.1" /> <http:endpoint service="uszip:USZip" endpoint="USZipSoap" role="provider" locationURI="http://www.webservicex.com/uszip.asmx" soap="true" soapAction="http://www.webserviceX.NET/GetInfoByCity" soapVersion="1.1" /> </beans>
Hey !