INTSAMPLES-3, restructured project directory to remove subdirectory
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package org.springframework.integration.samples.travel;
|
||||
|
||||
public interface TravelGateway {
|
||||
|
||||
public String getWeatherByZip(String zip);
|
||||
|
||||
public String getTrafficByZip(String zip);
|
||||
|
||||
}
|
||||
@@ -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>";
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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&zip={zipCode}"
|
||||
request-channel="trafficChannel"
|
||||
http-method="GET"
|
||||
expected-response-type="java.lang.String">
|
||||
<uri-variable name="zipCode" expression="payload"/>
|
||||
</outbound-gateway>
|
||||
|
||||
</beans:beans>
|
||||
@@ -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>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
28
intermediate/travel/src/test/resources/log4j.xml
Normal file
28
intermediate/travel/src/test/resources/log4j.xml
Normal 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>
|
||||
Reference in New Issue
Block a user