From cd7807e5938bfc441b6c8313849b24fe28480792 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Thu, 30 Sep 2010 07:54:52 -0400 Subject: [PATCH] INTSAMPLES-3 moved Travel Demo from the sandbox. Added readme file, loging, fixed pom etc. --- .../spring-integration-travel-demo/.classpath | 10 +++ .../spring-integration-travel-demo/.project | 29 ++++++++ .../com.springsource.sts.config.flow.prefs | 4 ++ .../.settings/org.eclipse.jdt.core.prefs | 13 ++++ .../.settings/org.maven.ide.eclipse.prefs | 9 +++ .../.springBeans | 14 ++++ .../spring-integration-travel-demo/pom.xml | 62 ++++++++++++++++++ .../spring-integration-travel-demo/readme.txt | 42 ++++++++++++ .../samples/travel/TravelGateway.java | 9 +++ .../travel/WeatherRequestTransformer.java | 10 +++ .../META-INF/spring/integration-context.xml | 36 ++++++++++ .../spring/integration-http-context.xml | 18 +++++ .../spring/integration-ws-context.xml | 18 +++++ .../samples/travel/TravelDemo.java | 45 +++++++++++++ .../src/test/resources/log4j.xml | 28 ++++++++ .../spring/integration-ws-context.xml | 18 +++++ .../samples/travel/TravelGateway.class | Bin 0 -> 247 bytes .../travel/WeatherRequestTransformer.class | Bin 0 -> 894 bytes .../target/test-classes/log4j.xml | 28 ++++++++ .../samples/travel/TravelDemo.class | Bin 0 -> 2959 bytes 20 files changed, 393 insertions(+) create mode 100644 intermediate/travel/spring-integration-travel-demo/.classpath create mode 100644 intermediate/travel/spring-integration-travel-demo/.project create mode 100644 intermediate/travel/spring-integration-travel-demo/.settings/com.springsource.sts.config.flow.prefs create mode 100644 intermediate/travel/spring-integration-travel-demo/.settings/org.eclipse.jdt.core.prefs create mode 100644 intermediate/travel/spring-integration-travel-demo/.settings/org.maven.ide.eclipse.prefs create mode 100644 intermediate/travel/spring-integration-travel-demo/.springBeans create mode 100644 intermediate/travel/spring-integration-travel-demo/pom.xml create mode 100644 intermediate/travel/spring-integration-travel-demo/readme.txt create mode 100644 intermediate/travel/spring-integration-travel-demo/src/main/java/org/springframework/integration/samples/travel/TravelGateway.java create mode 100644 intermediate/travel/spring-integration-travel-demo/src/main/java/org/springframework/integration/samples/travel/WeatherRequestTransformer.java create mode 100644 intermediate/travel/spring-integration-travel-demo/src/main/resources/META-INF/spring/integration-context.xml create mode 100644 intermediate/travel/spring-integration-travel-demo/src/main/resources/META-INF/spring/integration-http-context.xml create mode 100644 intermediate/travel/spring-integration-travel-demo/src/main/resources/META-INF/spring/integration-ws-context.xml create mode 100644 intermediate/travel/spring-integration-travel-demo/src/test/java/org/springframework/integration/samples/travel/TravelDemo.java create mode 100644 intermediate/travel/spring-integration-travel-demo/src/test/resources/log4j.xml create mode 100644 intermediate/travel/spring-integration-travel-demo/target/classes/META-INF/spring/integration-ws-context.xml create mode 100644 intermediate/travel/spring-integration-travel-demo/target/classes/org/springframework/integration/samples/travel/TravelGateway.class create mode 100644 intermediate/travel/spring-integration-travel-demo/target/classes/org/springframework/integration/samples/travel/WeatherRequestTransformer.class create mode 100644 intermediate/travel/spring-integration-travel-demo/target/test-classes/log4j.xml create mode 100644 intermediate/travel/spring-integration-travel-demo/target/test-classes/org/springframework/integration/samples/travel/TravelDemo.class diff --git a/intermediate/travel/spring-integration-travel-demo/.classpath b/intermediate/travel/spring-integration-travel-demo/.classpath new file mode 100644 index 00000000..96489ff1 --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/intermediate/travel/spring-integration-travel-demo/.project b/intermediate/travel/spring-integration-travel-demo/.project new file mode 100644 index 00000000..2b3bfc4e --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/.project @@ -0,0 +1,29 @@ + + + travel + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + + org.springframework.ide.eclipse.core.springnature + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/intermediate/travel/spring-integration-travel-demo/.settings/com.springsource.sts.config.flow.prefs b/intermediate/travel/spring-integration-travel-demo/.settings/com.springsource.sts.config.flow.prefs new file mode 100644 index 00000000..ba514d1f --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/.settings/com.springsource.sts.config.flow.prefs @@ -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=\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n +//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/travel/src/main/resources/META-INF/spring/integration-ws-context.xml=\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n +eclipse.preferences.version=1 diff --git a/intermediate/travel/spring-integration-travel-demo/.settings/org.eclipse.jdt.core.prefs b/intermediate/travel/spring-integration-travel-demo/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..9352ed1f --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/intermediate/travel/spring-integration-travel-demo/.settings/org.maven.ide.eclipse.prefs b/intermediate/travel/spring-integration-travel-demo/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 00000000..ae377d5c --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/.settings/org.maven.ide.eclipse.prefs @@ -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 diff --git a/intermediate/travel/spring-integration-travel-demo/.springBeans b/intermediate/travel/spring-integration-travel-demo/.springBeans new file mode 100644 index 00000000..a388bbfa --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/.springBeans @@ -0,0 +1,14 @@ + + + 1 + + + + + + + src/main/resources/META-INF/spring/integration-ws-context.xml + + + + diff --git a/intermediate/travel/spring-integration-travel-demo/pom.xml b/intermediate/travel/spring-integration-travel-demo/pom.xml new file mode 100644 index 00000000..2e9fb4cd --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/pom.xml @@ -0,0 +1,62 @@ + + 4.0.0 + org.springframework.integration.samples + travel + Spring Integration Travel Services Sample + 2.0.0 + + 2.0.0.M7 + 1.2.16 + 4.7 + 3.0.4.RELEASE + + + + org.springframework.integration + spring-integration-core + ${spring.integration.version} + + + org.springframework.integration + spring-integration-ws + ${spring.integration.version} + + + org.springframework.integration + spring-integration-http + ${spring.integration.version} + + + org.springframework + spring-web + ${spring.version} + + + log4j + log4j + ${log4j.version} + + + + junit + junit + ${junit.version} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + -Xlint:all + true + false + + + + + \ No newline at end of file diff --git a/intermediate/travel/spring-integration-travel-demo/readme.txt b/intermediate/travel/spring-integration-travel-demo/readme.txt new file mode 100644 index 00000000..8aa7cb25 --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/readme.txt @@ -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: + -ÊHTTP Outbound Gateway - to integrate with HTTP Service + -ÊWS Outbound Gateway - to integrate with WS Service + + +The diagram below shows the message flow. + ÊÊ Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê weatherPreProcessChannel Ê Ê Ê Ê Ê Ê Ê Ê Ê ÊÊweatherChannel Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê weatherServiceChannel + ÊÊ Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê |------------------------| -> transformer -> |--------------| -> header-enricher -> |---------------------| -> ws:outbound-gatewayÊ +ÊÊ Ê |->ÊgetWeatherByZip(zip) Ê Ê routingChannel Ê Ê Ê Ê Ê / +TravelGateway Ê Ê Ê Ê Ê Ê Ê Ê--> |--------------| -> h-v-r| +ÊÊ Ê |->ÊgetTrafficByZip(zip) Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê | Ê Ê trafficChannel +ÊÊ Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê Ê \ |-----------------| -> http:outbound-gateway Ê ÊÊ + +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 element of http:outbound-gateway. + + + +Here you see we are using Spring Expression Language to bind the value of the payload (zipCode) to this variable. + + + + + + + diff --git a/intermediate/travel/spring-integration-travel-demo/src/main/java/org/springframework/integration/samples/travel/TravelGateway.java b/intermediate/travel/spring-integration-travel-demo/src/main/java/org/springframework/integration/samples/travel/TravelGateway.java new file mode 100644 index 00000000..01ef2512 --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/src/main/java/org/springframework/integration/samples/travel/TravelGateway.java @@ -0,0 +1,9 @@ +package org.springframework.integration.samples.travel; + +public interface TravelGateway { + + public String getWeatherByZip(String zip); + + public String getTrafficByZip(String zip); + +} diff --git a/intermediate/travel/spring-integration-travel-demo/src/main/java/org/springframework/integration/samples/travel/WeatherRequestTransformer.java b/intermediate/travel/spring-integration-travel-demo/src/main/java/org/springframework/integration/samples/travel/WeatherRequestTransformer.java new file mode 100644 index 00000000..5947c819 --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/src/main/java/org/springframework/integration/samples/travel/WeatherRequestTransformer.java @@ -0,0 +1,10 @@ +package org.springframework.integration.samples.travel; + +public class WeatherRequestTransformer { + + public String transform(String zipCode){ + return "" + + " " + zipCode + "" + + ""; + } +} diff --git a/intermediate/travel/spring-integration-travel-demo/src/main/resources/META-INF/spring/integration-context.xml b/intermediate/travel/spring-integration-travel-demo/src/main/resources/META-INF/spring/integration-context.xml new file mode 100644 index 00000000..1e5e585e --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/src/main/resources/META-INF/spring/integration-context.xml @@ -0,0 +1,36 @@ + + + + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + diff --git a/intermediate/travel/spring-integration-travel-demo/src/main/resources/META-INF/spring/integration-http-context.xml b/intermediate/travel/spring-integration-travel-demo/src/main/resources/META-INF/spring/integration-http-context.xml new file mode 100644 index 00000000..adeeecc0 --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/src/main/resources/META-INF/spring/integration-http-context.xml @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/intermediate/travel/spring-integration-travel-demo/src/main/resources/META-INF/spring/integration-ws-context.xml b/intermediate/travel/spring-integration-travel-demo/src/main/resources/META-INF/spring/integration-ws-context.xml new file mode 100644 index 00000000..a4da31f0 --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/src/main/resources/META-INF/spring/integration-ws-context.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/intermediate/travel/spring-integration-travel-demo/src/test/java/org/springframework/integration/samples/travel/TravelDemo.java b/intermediate/travel/spring-integration-travel-demo/src/test/java/org/springframework/integration/samples/travel/TravelDemo.java new file mode 100644 index 00000000..db872049 --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/src/test/java/org/springframework/integration/samples/travel/TravelDemo.java @@ -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; + } + +} diff --git a/intermediate/travel/spring-integration-travel-demo/src/test/resources/log4j.xml b/intermediate/travel/spring-integration-travel-demo/src/test/resources/log4j.xml new file mode 100644 index 00000000..f391e2ed --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/src/test/resources/log4j.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/intermediate/travel/spring-integration-travel-demo/target/classes/META-INF/spring/integration-ws-context.xml b/intermediate/travel/spring-integration-travel-demo/target/classes/META-INF/spring/integration-ws-context.xml new file mode 100644 index 00000000..a4da31f0 --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/target/classes/META-INF/spring/integration-ws-context.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/intermediate/travel/spring-integration-travel-demo/target/classes/org/springframework/integration/samples/travel/TravelGateway.class b/intermediate/travel/spring-integration-travel-demo/target/classes/org/springframework/integration/samples/travel/TravelGateway.class new file mode 100644 index 0000000000000000000000000000000000000000..c81ffc3ca4ef853a49c69421b61d3e1d34b29d66 GIT binary patch literal 247 zcmZXP%?<%U5QJ;|EqfszLb#a3m6HP(i35qmt!;Y8to_UEAYRSE19&L0gG9uslIpJh zs_&2M4ZsM#hl;=?GfEb@(WwdzC4A1zLF&}9GGuj@%7T(S=0aLSCywR%C3CWTri+J~ zKqsOT$(T|lm%E4qE6`SKH%xZVW_sD`T%gxqeAiai;l_i1>m4l_VW@*o)L&&s6YxyO gEYSVo58cg%fIzi;38<8H>S(~#@|>2Frt{Hy0-Rz-_y7O^ literal 0 HcmV?d00001 diff --git a/intermediate/travel/spring-integration-travel-demo/target/classes/org/springframework/integration/samples/travel/WeatherRequestTransformer.class b/intermediate/travel/spring-integration-travel-demo/target/classes/org/springframework/integration/samples/travel/WeatherRequestTransformer.class new file mode 100644 index 0000000000000000000000000000000000000000..6c953fa64af1e2e3cd59bf18fcbebb4a1cd2086c GIT binary patch literal 894 zcmb_a+ip@p6kS7UIZ(8CY>SH4idv~gCh-xFhc@vR;*EwzeHvg2Q_sygLlM79U)n?y zKfsSN?tx=W3Xi_5J+p7K_L}|c_xGOw9^qaFDTZgE9`HEQDi|DT;mdKTKXMfqInctW zFyOK9BTvTMXmKJvekg?*O8r)T8p+rkXc5Fmq4uTDAk9!X7AJyxA{g*j-DBA^3@Z&4 zDAQzEs_b?c()(dw=CFip9?Mu^SZk?3z8v{osSiZglMHSv>MKb6!JY1AIH&H^p?%+DZYJ*S7+gBZIF_aR=f@!9-w)41!GJ|8nnPv>@ zl?AdfWWK1#e!czP^YYPGHVx+pZ5ULrN|>J|ki9@RhKpDuw8bANBSp6K1BG|4dxrG~rzpB53pWT(aq}yM lQ?M;vqzPA$rBW9TigdQ^H)k!9_S6iwafcpYxI3-g`2!k3=u!Xx literal 0 HcmV?d00001 diff --git a/intermediate/travel/spring-integration-travel-demo/target/test-classes/log4j.xml b/intermediate/travel/spring-integration-travel-demo/target/test-classes/log4j.xml new file mode 100644 index 00000000..f391e2ed --- /dev/null +++ b/intermediate/travel/spring-integration-travel-demo/target/test-classes/log4j.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/intermediate/travel/spring-integration-travel-demo/target/test-classes/org/springframework/integration/samples/travel/TravelDemo.class b/intermediate/travel/spring-integration-travel-demo/target/test-classes/org/springframework/integration/samples/travel/TravelDemo.class new file mode 100644 index 0000000000000000000000000000000000000000..b872104995df5a6bd690cab46068fc5435b1dc9e GIT binary patch literal 2959 zcmbVO`%~0b6#gzOWLcu(swk~5L}eFPg0G4!rR5=(b^$90qOCTB%M#2cX_Dokec1Q= z{rEfjm;o&_o&MVXQJtQfyTFQJaLUY*>{6gI z9NcEBirv`5P?P6@^u^GY%58$^w{+jnrnf!01`K;uRH2$-PtLUYNU<=@y>Wfo;ta{0 zW9Zg|?wR7bv{>C80!^S2^(yuwPGEyM(`U$r$NVqyh=N!_H*JRc)U7i7V}Zy-Rxpyd zyku}!h8I<<-DXj(Jei=&facT-c-@sjVZ(T@Qt(!h~`81|twjb!WL2ap}ME=g(DSeZ8UBzwOAyUan*$E6yJNqGp>y&M$U4v7@(N}dj_nYXiaD6naD5((76Z2!T=g86djWCR9HGi5=}b?=ahHV1ZNr(N z#u!I|>hJpaV5Tz;l3TTD&u}}4<4uP2{kb4;yEMUZyPP^>4-NJ z$fRcm+)Lmd>JwPPJEEDsOL{M{LUz)ECV_(YwrO~ei%B{j3;T8g4@8^b_)x`1_?QOf zhUlnu$V0ZON$$*sN!a>M20~y2*iTh_hR@{?mMEzd*89UIaxpObC`B|&s5OzMHz0_Q zgT}~n%H%3aNs=iKrvyiCkv5MJPFt(x{9-s9xv3N@#XuZN;%MN?RWT{4r4tnT-Vq-< z?ILw(q^4U*A5LT^J|E~VhBy@Zkr#T(&{h1^B-ukGen;J}^iY8${ZG&p*h{8$*cYw} zH}oY@+N#l2Y_4iq#evOj)#0MtqDliC#33@QK?9y4r_a)TjNTj$5&TW}RkU(v4M(Sv z$5(M8*P1+)Y<`4vCH_M5a9dJ)gfkTw`3-ezxGvR_*I~s1=1~~Q*6DxR)qI)Aby@Hw6P+DRP4 zDWnN*C(W^5qzHPN!e}WAa137(aL}$CzQWfOU?&Ch4ZbC>y(EI~@I3{1m3}{j0W$m; Hp7_&$R6Q`> literal 0 HcmV?d00001