...
Project structure, SUs and SA
Section |
---|
Column |
---|
In this example, we will only use two components: 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: Code Block |
---|
mkdir citytime
cd citytime
|
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>citytime</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
</project>
|
|
Column |
---|
Gliffy Diagram |
---|
size | M |
---|
name | citytime-sa |
---|
page | Orchestration with JSR181 |
---|
space | SM |
---|
|
|
|
Then, we can use maven archetypes to create the two SUs and the SA. In the citytime
directory, launch the following commands:
...
Code Block |
---|
cd citytime/citytime-jsr181-su
mkdir src/main/java
mvn eclipse:eclipse
|
In Eclipse, after having refreshed the project, create a new class in the java source folder: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.
Code Block |
---|
|
package org.apache.servicemix.samples.weathercitytime;
import javax.jws.WebService;
@WebService(serviceName = "WeatherCityTime",
targetNamespace = "http://servicemix.apache.org/samples/weathercitytime",
endpointInterface = "org.apache.servicemix.samples.weathercitytime.WeatherPortTypeCityTimePortType")
public class CityTimeImpl
WeatherServiceImpl implements WeatherPortType CityTimePortType
{
public GetWeatherResponseGetCityTimeResponse getWeather(GetWeatherRequest GetWeatherRequestgetCityTime(org.apache.servicemix.samples.citytime.GetCityTimeRequest GetCityTimeRequest) {
return nullthrow 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:
Code Block |
---|
|
private WeatherForecastSoapUSZipSoap weatherForecastusZip;
private USZipSoapLocalTimeSoap usZiplocalTime;
public void setUsZipsetLocalTime(USZipSoapLocalTimeSoap usZiplocalTime) {
this.usZiplocalTime = usZiplocalTime;
}
public void setWeatherForecastsetUsZip(WeatherForecastSoapUSZipSoap weatherForecastusZip) {
this.weatherForecastusZip = weatherForecastusZip;
}
|
We can now code our orchestration logic in the getWeather
method:
Code Block |
---|
|
public GetWeatherResponseGetCityTimeResponse getWeather(GetWeatherRequest getWeatherRequestgetCityTime(org.apache.servicemix.samples.citytime.GetCityTimeRequest GetCityTimeRequest) {
List<String> zips = zipByCityState.getZipByCityState(getWeatherRequest.getCity(),
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) getWeatherRequest.getState(), 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:
Code Block |
---|
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.
Code Block |
---|
lang | java |
---|
title | CityTimeTest.java |
---|
|
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:
Code Block |
---|
lang | xml |
---|
title | GetInfoByCityResponse.xml |
---|
|
<?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:
Code Block |
---|
lang | xml |
---|
title | JSR181 xbean.xml |
---|
|
<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:
Code Block |
---|
lang | xml |
---|
title | HTTP xbean.xml |
---|
|
<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"
licenseInfo,
locationURI="http://www.webservicex.com/uszip.asmx"
soap="true"
soapAction="http://www.webserviceX.NET/GetInfoByCity"
new Holder<SubscriptionInfo>()).getString();
GetForecastByZip getForecastByZip = new GetForecastByZip();
getForecastByZip.setZipCode(zips.get(0));
GetForecastByZipResponse forecast = forecastByZip.getForecastByZip(getForecastByZip, licenseInfo, new Holder<SubscriptionInfo>());
GetWeatherResponse response = new GetWeatherResponse();
response.getString().addAll(forecast.getGetForecastByZipResult().getString());
return response;
}
soapVersion="1.1" />
</beans>
|
Hey !