INT-1477 restructuring samples repo to have basic, intermediate, advancedand applications directories
This commit is contained in:
10
basic/xml/.classpath
Normal file
10
basic/xml/.classpath
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/main/resources"/>
|
||||
<classpathentry kind="src" path="src/test/java"/>
|
||||
<classpathentry kind="src" 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>
|
||||
1
basic/xml/.gitignore
vendored
Normal file
1
basic/xml/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
23
basic/xml/.project
Normal file
23
basic/xml/.project
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>xml</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>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,3 @@
|
||||
#Thu Sep 16 19:13:50 EDT 2010
|
||||
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/xml/src/main/resources/META-INF/spring/integration/orderProcessingSample.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="885" endstart\="885" start\="852" startend\="885"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="926" endstart\="926" start\="887" startend\="926"/>\n<bounds height\="112" width\="116" x\="291" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="967" endstart\="967" start\="928" startend\="967"/>\n<bounds height\="112" width\="116" x\="563" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1013" endstart\="1013" start\="969" startend\="1013"/>\n<bounds height\="112" width\="116" x\="19" y\="149"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1052" endstart\="1052" start\="1015" startend\="1052"/>\n<bounds height\="112" width\="116" x\="19" y\="281"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1094" endstart\="1094" start\="1054" startend\="1094"/>\n<bounds height\="112" width\="116" x\="291" y\="281"/>\n</element>\n<element clazz\="XpathSplitterModelElement" type\="xpath-splitter">\n<structure end\="1696" endstart\="1672" start\="1423" startend\="1560"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n<element clazz\="ServiceActivatorModelElement" type\="service-activator">\n<structure end\="1972" endstart\="1949" start\="1723" startend\="1818"/>\n<bounds height\="112" width\="116" x\="427" y\="17"/>\n</element>\n<element clazz\="XpathRouterModelElement" type\="xpath-router">\n<structure end\="2471" endstart\="2449" start\="2196" startend\="2340"/>\n<bounds height\="112" width\="116" x\="699" y\="17"/>\n</element>\n<element clazz\="OutboundChannelAdapterModelElement" type\="outbound-channel-adapter">\n<structure end\="3004" endstart\="2974" start\="2809" startend\="2891"/>\n<bounds height\="112" width\="116" x\="155" y\="149"/>\n</element>\n<element clazz\="XslTransformerModelElement" type\="xslt-transformer">\n<structure end\="3291" endstart\="3291" start\="3103" startend\="3291"/>\n<bounds height\="112" width\="116" x\="155" y\="281"/>\n</element>\n<element clazz\="OutboundChannelAdapterModelElement" type\="outbound-channel-adapter">\n<structure end\="3523" endstart\="3493" start\="3328" startend\="3411"/>\n<bounds height\="112" width\="116" x\="427" y\="281"/>\n</element>\n</graph>
|
||||
eclipse.preferences.version=1
|
||||
6
basic/xml/.settings/org.eclipse.jdt.core.prefs
Normal file
6
basic/xml/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,6 @@
|
||||
#Fri May 28 19:45:26 CEST 2010
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
9
basic/xml/.settings/org.maven.ide.eclipse.prefs
Normal file
9
basic/xml/.settings/org.maven.ide.eclipse.prefs
Normal file
@@ -0,0 +1,9 @@
|
||||
#Tue Jun 30 15:22:48 EDT 2009
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
fullBuildGoals=process-test-resources
|
||||
includeModules=false
|
||||
resolveWorkspaceProjects=true
|
||||
resourceFilterGoals=process-resources resources\:testResources
|
||||
skipCompilerPlugin=true
|
||||
version=1
|
||||
65
basic/xml/pom.xml
Normal file
65
basic/xml/pom.xml
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>xml</artifactId>
|
||||
<name>Spring Integration XML Sample</name>
|
||||
<version>2.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<spring.integration.version>2.0.0.M7</spring.integration.version>
|
||||
<log4j.version>1.2.16</log4j.version>
|
||||
<junit.version>4.7</junit.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-xml</artifactId>
|
||||
<version>${spring.integration.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>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repository.springframework.maven.release</id>
|
||||
<name>Spring Framework Maven Release Repository</name>
|
||||
<url>http://maven.springframework.org/release</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>repository.springframework.maven.milestone</id>
|
||||
<name>Spring Framework Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>repository.springframework.maven.snapshot</id>
|
||||
<name>Spring Framework Maven Snapshot Repository</name>
|
||||
<url>http://maven.springframework.org/snapshot</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
||||
25
basic/xml/readme.txt
Normal file
25
basic/xml/readme.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
This example demonstrates the following aspects of the XML support available with Spring Integration:
|
||||
1. XPath Splitter - to split an order with multiple items into several order messages for separate processing.
|
||||
2. XPath Router - to route messages according to the evaluation of an XPath expression which tests to see if the order item is in stock.
|
||||
3. XPath Expression - which tests to see if the order item is in stock
|
||||
3. XSLT Transformer - to transform the payload of the order message into a resupply message where the order item is found to be out of stock.
|
||||
|
||||
To run sample simply execute BookOrderProcessingTest. You should see the following output:
|
||||
|
||||
INFO : org.springframework.integration.samples.xml.WarehouseDispatch - Warehouse dispatching orderItem:
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<orderItem in-stock="true" xmlns="http://www.example.org/orders">
|
||||
<isbn>0321200683</isbn>
|
||||
<quantity>2</quantity>
|
||||
</orderItem>
|
||||
|
||||
INFO : org.springframework.integration.samples.xml.ExternalResupply - Placing resupply order:
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<bb:bigBooksOrder xmlns:bb="http://www.example.org/orders-bigbooks"
|
||||
xmlns:sb="http://www.example.org/orders">
|
||||
<bb:order>
|
||||
<bb:purchaser>smallbooks</bb:purchaser>
|
||||
<bb:quantity>5</bb:quantity>
|
||||
<bb:isbn>1590596439</bb:isbn>
|
||||
</bb:order>
|
||||
</bb:bigBooksOrder>
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.samples.xml;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.w3c.dom.Document;
|
||||
/**
|
||||
*
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
public class ExternalResupply {
|
||||
private static Logger logger = Logger.getLogger(ExternalResupply.class);
|
||||
|
||||
public void orderResupply(Document resupplyOrder) {
|
||||
logger.info("Placing resupply order: \n" + XmlUtil.docAsString(resupplyOrder));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.samples.xml;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.xml.xpath.XPathExpression;
|
||||
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
public class StockChecker {
|
||||
|
||||
private final XPathExpression isbnSelectingXPath;
|
||||
|
||||
public StockChecker(XPathExpression isbnSelectingXPath) {
|
||||
this.isbnSelectingXPath = isbnSelectingXPath;
|
||||
}
|
||||
|
||||
public Document checkStockLevel(Document doc) {
|
||||
String isbn = isbnSelectingXPath.evaluateAsString(doc);
|
||||
boolean inStock = false;
|
||||
|
||||
// we only carry stock of one book currently
|
||||
if ("0321200683".equals(isbn)) {
|
||||
inStock = true;
|
||||
}
|
||||
doc.getDocumentElement().setAttribute("in-stock", String.valueOf(inStock));
|
||||
return doc;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.samples.xml;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.w3c.dom.Document;
|
||||
/**
|
||||
*
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
public class WarehouseDispatch {
|
||||
private static Logger logger = Logger.getLogger(WarehouseDispatch.class);
|
||||
|
||||
public void dispatch(Document orderItem){
|
||||
logger.info("Warehouse dispatching orderItem: \n" + XmlUtil.docAsString(orderItem));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.samples.xml;
|
||||
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
public class XmlUtil {
|
||||
|
||||
public static String docAsString(Document doc) {
|
||||
try {
|
||||
StringResult res = new StringResult();
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer.transform(new DOMSource(doc), res);
|
||||
return res.toString();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:sb="http://www.example.org/orders"
|
||||
xmlns:bb="http://www.example.org/orders-bigbooks">
|
||||
<xsl:template match="/sb:orderItem" >
|
||||
<bb:bigBooksOrder>
|
||||
<bb:order>
|
||||
<bb:purchaser>smallbooks</bb:purchaser>
|
||||
<bb:quantity>5</bb:quantity>
|
||||
<bb:isbn>
|
||||
<xsl:value-of select="./sb:isbn/text()"/>
|
||||
</bb:isbn>
|
||||
</bb:order>
|
||||
|
||||
</bb:bigBooksOrder>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<order xmlns="http://www.example.org/orders">
|
||||
<orderItem>
|
||||
<isbn>0321200683</isbn>
|
||||
<quantity>2</quantity>
|
||||
</orderItem>
|
||||
<orderItem>
|
||||
<isbn>1590596439</isbn>
|
||||
<quantity>1</quantity>
|
||||
</orderItem>
|
||||
</order>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:si-xml="http://www.springframework.org/schema/integration/xml"
|
||||
xmlns:si="http://www.springframework.org/schema/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
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.xsd
|
||||
http://www.springframework.org/schema/integration/xml
|
||||
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd
|
||||
http://www.springframework.org/schema/util
|
||||
http://www.springframework.org/schema/util/spring-util.xsd">
|
||||
|
||||
<si:channel id="ordersChannel" />
|
||||
<si:channel id="stockCheckerChannel" />
|
||||
<si:channel id="orderRoutingChannel" />
|
||||
<si:channel id="warehouseDispatchChannel" />
|
||||
<si:channel id="outOfStockChannel" />
|
||||
<si:channel id="resupplyOrderChannel" />
|
||||
|
||||
<!-- map of namespace prefix to URI -->
|
||||
<util:map id="orderNamespaceMap">
|
||||
<entry key="orderNs" value="http://www.example.org/orders" />
|
||||
<entry key="productNs" value="http://www.example.org/prodcuts" />
|
||||
</util:map>
|
||||
|
||||
<!-- split the inbound order into a number of orderItem documents that can be processed separately -->
|
||||
<si-xml:xpath-splitter id="orderItemSplitter" input-channel="ordersChannel" output-channel="stockCheckerChannel" create-documents="true">
|
||||
<si-xml:xpath-expression expression="/orderNs:order/orderNs:orderItem" namespace-map="orderNamespaceMap" />
|
||||
</si-xml:xpath-splitter>
|
||||
|
||||
<!-- if each order -->
|
||||
<si:service-activator input-channel="stockCheckerChannel" output-channel="orderRoutingChannel">
|
||||
<bean class="org.springframework.integration.samples.xml.StockChecker">
|
||||
<constructor-arg ref="selectIsbnXpath" />
|
||||
</bean>
|
||||
</si:service-activator>
|
||||
|
||||
<si-xml:xpath-expression id="selectIsbnXpath" namespace-map="orderNamespaceMap" expression="/orderNs:orderItem/orderNs:isbn/text()" />
|
||||
|
||||
<!-- if in stock route to the warehouse else route to the out of stock channel -->
|
||||
<si-xml:xpath-router id="instockRouter" channel-resolver="mapChannelResolver"
|
||||
input-channel="orderRoutingChannel" resolution-required="true">
|
||||
<si-xml:xpath-expression expression="/orderNs:orderItem/@in-stock" namespace-map="orderNamespaceMap" />
|
||||
</si-xml:xpath-router>
|
||||
|
||||
<bean id="mapChannelResolver" class="org.springframework.integration.channel.MapBasedChannelResolver">
|
||||
<property name="channelMap">
|
||||
<map>
|
||||
<entry key="true" value-ref="warehouseDispatchChannel" />
|
||||
<entry key="false" value-ref="outOfStockChannel" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- dispatch order if in stock -->
|
||||
<si:outbound-channel-adapter method="dispatch" channel="warehouseDispatchChannel">
|
||||
<bean class="org.springframework.integration.samples.xml.WarehouseDispatch" />
|
||||
</si:outbound-channel-adapter>
|
||||
|
||||
<!-- convert the order item to a format that can be understood by BigBooks the wholesaler -->
|
||||
<si-xml:xslt-transformer input-channel="outOfStockChannel" output-channel="resupplyOrderChannel"
|
||||
xsl-resource="classpath:/META-INF/spring/integration/bigBooksSupplierTransformer.xsl"/>
|
||||
|
||||
<!-- send the resupply order -->
|
||||
<si:outbound-channel-adapter method="orderResupply" channel="resupplyOrderChannel">
|
||||
<bean class="org.springframework.integration.samples.xml.ExternalResupply" />
|
||||
</si:outbound-channel-adapter>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.samples.xml;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
|
||||
/**
|
||||
* This example demonstrates the processing of an order for books using
|
||||
* several of the components provided by the Spring Integration Xml
|
||||
* module for dealing with Xml payloads. This includes:
|
||||
*
|
||||
* <ul>
|
||||
* <li>an XPath based implementation of the splitter pattern to split an
|
||||
* order with multiple items into several order messages for separate
|
||||
* processing.</li>
|
||||
* <li>XPath expression namespace support to build an XPath expression to
|
||||
* extract the isbn from each order item.</li>
|
||||
* <li>an XPath router implementation to route messages according to the
|
||||
* evaluation of an XPath expression which tests to see if the order item is in
|
||||
* stock.</li>
|
||||
* <li>an XSLT transformer implementation to transform the payload of the
|
||||
* order message into a resupply message where the order item is found to be
|
||||
* out of stock.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
public class BookOrderProcessingTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
AbstractApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("/META-INF/spring/integration/orderProcessingSample.xml",
|
||||
BookOrderProcessingTest.class);
|
||||
MessageChannel messageChannel = (MessageChannel) applicationContext.getBean("ordersChannel");
|
||||
GenericMessage<Document> orderMessage =
|
||||
createXmlMessageFromResource("META-INF/spring/integration/order.xml");
|
||||
messageChannel.send(orderMessage);
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
private static GenericMessage<Document> createXmlMessageFromResource(String path) throws Exception {
|
||||
Resource orderRes = new ClassPathResource(path);
|
||||
|
||||
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
|
||||
builderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder builder = builderFactory.newDocumentBuilder();
|
||||
|
||||
Document orderDoc = builder.parse(orderRes.getInputStream());
|
||||
return new GenericMessage<Document>(orderDoc);
|
||||
}
|
||||
|
||||
}
|
||||
28
basic/xml/src/test/resources/log4j.xml
Normal file
28
basic/xml/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