INTSAMPLES-3 moved Travel Demo from the sandbox. Added readme file, loging, fixed pom etc.

This commit is contained in:
Oleg Zhurakousky
2010-09-30 07:54:52 -04:00
parent cb205d9a02
commit cd7807e593
20 changed files with 393 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>travel</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,4 @@
#Thu Sep 30 07:28:41 EDT 2010
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/travel/src/main/resources/META-INF/spring/integration-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="GatewayModelElement" type\="gateway">\n<structure end\="875" endstart\="865" start\="484" startend\="664"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="PublishSubscribeChannelModelElement" type\="publish-subscribe-channel">\n<structure end\="930" endstart\="930" start\="882" startend\="930"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n<element clazz\="HeaderValueRouterModelElement" type\="header-value-router">\n<structure end\="1154" endstart\="1132" start\="933" startend\="1012"/>\n<bounds height\="112" width\="116" x\="291" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1198" endstart\="1198" start\="1158" startend\="1198"/>\n<bounds height\="112" width\="116" x\="19" y\="149"/>\n</element>\n<element clazz\="TransformerModelElement" type\="transformer">\n<structure end\="1407" endstart\="1393" start\="1202" startend\="1288"/>\n<bounds height\="112" width\="116" x\="155" y\="149"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1447" endstart\="1447" start\="1417" startend\="1447"/>\n<bounds height\="112" width\="116" x\="291" y\="149"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1481" endstart\="1481" start\="1451" startend\="1481"/>\n<bounds height\="112" width\="116" x\="19" y\="281"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/travel/src/main/resources/META-INF/spring/integration-ws-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="HeaderEnricherModelElement" type\="header-enricher">\n<structure end\="871" endstart\="853" start\="688" startend\="775"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="916" endstart\="916" start\="874" startend\="916"/>\n<bounds height\="112" width\="116" x\="291" y\="17"/>\n</element>\n<element clazz\="OutboundGatewayModelElement" type\="outbound-gateway">\n<structure end\="1030" endstart\="1030" start\="919" startend\="1030"/>\n<bounds height\="112" width\="116" x\="427" y\="17"/>\n</element>\n<element clazz\="ImplicitChannelModelElement" type\="channel">\n<structure end\="871" endstart\="853" start\="688" startend\="775"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n</graph>
eclipse.preferences.version=1

View File

@@ -0,0 +1,13 @@
#Sun Aug 15 16:15:17 EDT 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6

View File

@@ -0,0 +1,9 @@
#Sun Aug 15 16:14:18 EDT 2010
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[2.3.3.201006162200-CI-R3784-B775]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/main/resources/META-INF/spring/integration-ws-context.xml</config>
</configs>
<configSets>
</configSets>
</beansProjectDescription>

View File

@@ -0,0 +1,62 @@
<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>org.springframework.integration.samples</groupId>
<artifactId>travel</artifactId>
<name>Spring Integration Travel Services Sample</name>
<version>2.0.0</version>
<properties>
<spring.integration.version>2.0.0.M7</spring.integration.version>
<log4j.version>1.2.16</log4j.version>
<junit.version>4.7</junit.version>
<spring.version>3.0.4.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-ws</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-http</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- test-scoped dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</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>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>false</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,42 @@
This example demonstrates a simple process that could be useful when building travel related applications;
It defines two services:
1. Get Weather report based on the ZIP code
2. Get Traffic report based on the ZIP code
It uses real services provided by third party providers.
Get Weather report Service is a SOAP Web Service
Get Traffic report Service is an HTTP Service
This example demonstrates how to configure both:
-<2D>HTTP Outbound Gateway - to integrate with HTTP Service
-<2D>WS Outbound Gateway - to integrate with WS Service
The diagram below shows the message flow.
<09><> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> weatherPreProcessChannel <20> <20> <20> <20> <20> <20> <20> <20> <20> <20><>weatherChannel <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> weatherServiceChannel
<09><> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> |------------------------| -> transformer -> |--------------| -> header-enricher -> |---------------------| -> ws:outbound-gateway<61>
<EFBFBD><EFBFBD> <20> |-><3E>getWeatherByZip(zip) <20> <20> routingChannel <20> <20> <20> <20> <20> /
TravelGateway <20> <20> <20> <20> <20> <20> <20> <20>--> |--------------| -> h-v-r|
<EFBFBD><EFBFBD> <20> |-><3E>getTrafficByZip(zip) <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> | <20> <20> trafficChannel
<EFBFBD><EFBFBD> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> \ |-----------------| -> http:outbound-gateway <20> <20><>
Two services are exposed via the Gateway. The gateway enriches the headers of the message with the
type of request 'weather' or 'traffic' and sends the Message to the 'routingChannel' from which it is retrieved by
HeaderValueRouter (h-v-r) which routes Message to either 'weatherPreProcessChannel' or 'trafficChannel' based
on the value of the REQUEST_TYPE header hat was set by the Gateway.
WS service, requires that the message would be is a certain format. We first need to wrap it into XML request (done by a transformer),
then we need to add a SOAP Header (done by header-enricher). Once Message was properly formated it is sent to ws:outbound-gateway
which replies with XML describing real time weather conditions in a particular ZIP code.
HTTP Service does not require any pre-processing. All we need to do is map HTTP URI variable {zipCode}.
We do it via <uri-variable> element of http:outbound-gateway.
<uri-variable name="zipCode" expression="payload"/>
Here you see we are using Spring Expression Language to bind the value of the payload (zipCode) to this variable.

View File

@@ -0,0 +1,9 @@
package org.springframework.integration.samples.travel;
public interface TravelGateway {
public String getWeatherByZip(String zip);
public String getTrafficByZip(String zip);
}

View File

@@ -0,0 +1,10 @@
package org.springframework.integration.samples.travel;
public class WeatherRequestTransformer {
public String transform(String zipCode){
return "<weat:GetCityWeatherByZIP xmlns:weat=\"http://ws.cdyne.com/WeatherWS/\">" +
" <weat:ZIP>" + zipCode + "</weat:ZIP>" +
"</weat:GetCityWeatherByZIP>";
}
}

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
<gateway id="travelGateway"
service-interface="org.springframework.integration.samples.travel.TravelGateway"
default-request-channel="routingChannel">
<method name="getWeatherByZip">
<header name="REQUEST_TYPE" value="weather"/>
</method>
<method name="getTrafficByZip">
<header name="REQUEST_TYPE" value="traffic"/>
</method>
</gateway>
<publish-subscribe-channel id="routingChannel"/>
<header-value-router input-channel="routingChannel" header-name="REQUEST_TYPE">
<mapping value="weather" channel="weatherPreProcessChannel"/>
<mapping value="traffic" channel="trafficChannel"/>
</header-value-router>
<channel id="weatherPreProcessChannel"/>
<transformer input-channel="weatherPreProcessChannel" output-channel="weatherChannel">
<beans:bean class="org.springframework.integration.samples.travel.WeatherRequestTransformer"/>
</transformer>
<channel id="weatherChannel"/>
<channel id="trafficChannel"/>
</beans:beans>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration/http"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http-2.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
<outbound-gateway id="trafficGateway"
url="http://local.yahooapis.com/MapsService/V1/trafficData?appid=YdnDemo&amp;zip={zipCode}"
request-channel="trafficChannel"
http-method="GET"
expected-response-type="java.lang.String">
<uri-variable name="zipCode" expression="payload"/>
</outbound-gateway>
</beans:beans>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration/ws"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws-2.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
<header-enricher input-channel="weatherChannel" output-channel="weatherServiceChannel">
<soap-action value="http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP" />
</header-enricher>
<int:channel id="weatherServiceChannel" />
<outbound-gateway request-channel="weatherServiceChannel"
uri="http://ws.cdyne.com/WeatherWS/Weather.asmx" />
</beans:beans>

View File

@@ -0,0 +1,45 @@
package org.springframework.integration.samples.travel;
import java.io.StringWriter;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.xml.transform.StringSource;
public class TravelDemo {
private static Logger logger = Logger.getLogger(TravelDemo.class);
/**
* @param args
*/
public static void main(String[] args) throws Exception{
ApplicationContext ac = new FileSystemXmlApplicationContext("src/main/resources/META-INF/spring/*.xml");
TravelGateway travelGateway = ac.getBean("travelGateway", TravelGateway.class);
String weatherReply = travelGateway.getWeatherByZip("10035");
logger.info("### Weather: \n" + formatResult(weatherReply));
String trafficReply = travelGateway.getTrafficByZip("10035");
logger.info("### Traffic: \n" + formatResult(trafficReply));
}
private static String formatResult(String result) throws Exception{
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(2));
StreamResult streamResult = new StreamResult(new StringWriter());
Source source = new StringSource(result);
transformer.transform(source, streamResult);
String xmlString = streamResult.getWriter().toString();
return xmlString;
}
}

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
</layout>
</appender>
<!-- Loggers -->
<logger name="org.springframework">
<level value="warn" />
</logger>
<logger name="org.springframework.integration.samples">
<level value="debug" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration/ws"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws-2.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
<header-enricher input-channel="weatherChannel" output-channel="weatherServiceChannel">
<soap-action value="http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP" />
</header-enricher>
<int:channel id="weatherServiceChannel" />
<outbound-gateway request-channel="weatherServiceChannel"
uri="http://ws.cdyne.com/WeatherWS/Weather.asmx" />
</beans:beans>

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
</layout>
</appender>
<!-- Loggers -->
<logger name="org.springframework">
<level value="warn" />
</logger>
<logger name="org.springframework.integration.samples">
<level value="debug" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>