diff --git a/spring-integration-xml/.springBeans b/spring-integration-xml/.springBeans
deleted file mode 100644
index 03a170852e..0000000000
--- a/spring-integration-xml/.springBeans
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
- 1
-
-
-
-
-
-
- src/test/java/org/springframework/integration/xml/transformer/XsltTransformerTests-context.xml
-
-
-
-
diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathRouterParser.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathRouterParser.java
index c7f4ca8ddc..95f5a7de6a 100644
--- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathRouterParser.java
+++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathRouterParser.java
@@ -16,16 +16,21 @@
package org.springframework.integration.xml.config;
+import java.util.List;
+
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
+import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractConsumerEndpointParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
+import org.springframework.util.xml.DomUtils;
/**
* Parser for the <xpath-router/> element.
@@ -63,6 +68,19 @@ public class XPathRouterParser extends AbstractConsumerEndpointParser {
String classname = "org.springframework.integration.xml.router." +
((multiChannel) ? "XPathMultiChannelRouter" : "XPathSingleChannelRouter");
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(classname);
+
+
+ List childElements = DomUtils.getChildElementsByTagName(element, "mapping");
+ if (childElements != null && childElements.size() > 0) {
+ ManagedMap channelMap = new ManagedMap();
+ for (Element childElement : childElements) {
+ String key = childElement.getAttribute("value");
+ channelMap.put(key, childElement.getAttribute("channel"));
+ }
+ builder.addPropertyValue("channelIdentifierMap", channelMap);
+ }
+
+
if (xPathExpressionChildPresent) {
BeanDefinition beanDefinition = this.xpathParser.parse(
(Element) xPathExpressionNodes.item(0), parserContext);
diff --git a/spring-integration-xml/src/main/resources/org/springframework/integration/xml/config/spring-integration-xml-2.0.xsd b/spring-integration-xml/src/main/resources/org/springframework/integration/xml/config/spring-integration-xml-2.0.xsd
index 85290c7a1b..adf751481d 100644
--- a/spring-integration-xml/src/main/resources/org/springframework/integration/xml/config/spring-integration-xml-2.0.xsd
+++ b/spring-integration-xml/src/main/resources/org/springframework/integration/xml/config/spring-integration-xml-2.0.xsd
@@ -352,6 +352,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathRouterParserTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathRouterParserTests.java
index 80c3dfe2c7..18abbb4381 100644
--- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathRouterParserTests.java
+++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathRouterParserTests.java
@@ -16,6 +16,8 @@
package org.springframework.integration.xml.config;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import org.junit.After;
@@ -25,11 +27,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
+import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.message.GenericMessage;
+import org.springframework.integration.router.AbstractMessageRouter;
import org.springframework.integration.support.MessageBuilder;
+import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.test.context.ContextConfiguration;
import org.w3c.dom.Document;
@@ -195,5 +201,68 @@ public class XPathRouterParserTests {
inputChannel.send(MessageBuilder.withPayload("").build());
assertEquals("Wrong count of messages on default output channel",1, defaultOutput.getQueueSize());
}
+ @Test
+ public void testWithDynamicChanges() throws Exception {
+ ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("XPathRouterTests-context.xml", this.getClass());
+
+ MessageChannel inputChannel = ac.getBean("xpathRouterEmptyChannel", MessageChannel.class);
+ PollableChannel channelA = ac.getBean("channelA", PollableChannel.class);
+ PollableChannel channelB = ac.getBean("channelB", PollableChannel.class);
+ Document doc = XmlTestUtil.getDocumentForString("channelA");
+ GenericMessage docMessage = new GenericMessage(doc);
+ inputChannel.send(docMessage);
+ assertNotNull(channelA.receive(10));
+ assertNull(channelB.receive(10));
+
+ EventDrivenConsumer routerEndpoint = ac.getBean("xpathRouterEmpty", EventDrivenConsumer.class);
+ AbstractMessageRouter xpathRouter = (AbstractMessageRouter) TestUtils.getPropertyValue(routerEndpoint, "handler");
+ xpathRouter.setChannelMapping("channelA", "channelB");
+ inputChannel.send(docMessage);
+ assertNotNull(channelB.receive(10));
+ assertNull(channelA.receive(10));
+ }
+ @Test
+ public void testWithDynamicChangesWithExistingMappings() throws Exception {
+ ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("XPathRouterTests-context.xml", this.getClass());
+
+ MessageChannel inputChannel = ac.getBean("xpathRouterWithMappingChannel", MessageChannel.class);
+ PollableChannel channelA = ac.getBean("channelA", PollableChannel.class);
+ PollableChannel channelB = ac.getBean("channelB", PollableChannel.class);
+ Document doc = XmlTestUtil.getDocumentForString("channelA");
+ GenericMessage docMessage = new GenericMessage(doc);
+ inputChannel.send(docMessage);
+ assertNull(channelA.receive(10));
+ assertNotNull(channelB.receive(10));
+
+ EventDrivenConsumer routerEndpoint = ac.getBean("xpathRouterWithMapping", EventDrivenConsumer.class);
+ AbstractMessageRouter xpathRouter = (AbstractMessageRouter) TestUtils.getPropertyValue(routerEndpoint, "handler");
+ xpathRouter.removeChannelMapping("channelA");
+ inputChannel.send(docMessage);
+ assertNotNull(channelA.receive(10));
+ assertNull(channelB.receive(10));
+ }
+
+ @Test
+ public void testWithDynamicChangesWithExistingMappingsAndMultiChannel() throws Exception {
+ ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("XPathRouterTests-context.xml", this.getClass());
+
+ MessageChannel inputChannel = ac.getBean("multiChannelRouterChannel", MessageChannel.class);
+ PollableChannel channelA = ac.getBean("channelA", PollableChannel.class);
+ PollableChannel channelB = ac.getBean("channelB", PollableChannel.class);
+ Document doc = XmlTestUtil.getDocumentForString("channelAchannelB");
+ GenericMessage docMessage = new GenericMessage(doc);
+ inputChannel.send(docMessage);
+ assertNotNull(channelA.receive(10));
+ assertNotNull(channelA.receive(10));
+ assertNull(channelB.receive(10));
+
+ EventDrivenConsumer routerEndpoint = ac.getBean("xpathRouterWithMappingMultiChannel", EventDrivenConsumer.class);
+ AbstractMessageRouter xpathRouter = (AbstractMessageRouter) TestUtils.getPropertyValue(routerEndpoint, "handler");
+ xpathRouter.removeChannelMapping("channelA");
+ xpathRouter.removeChannelMapping("channelB");
+ inputChannel.send(docMessage);
+ assertNotNull(channelA.receive(10));
+ assertNotNull(channelB.receive(10));
+ }
}
diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathRouterTests-context.xml b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathRouterTests-context.xml
new file mode 100644
index 0000000000..f9ecfa7233
--- /dev/null
+++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathRouterTests-context.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+