diff --git a/docs/src/reference/docbook/xml.xml b/docs/src/reference/docbook/xml.xml
index 8b2c276cf7..5e467b93e7 100644
--- a/docs/src/reference/docbook/xml.xml
+++ b/docs/src/reference/docbook/xml.xml
@@ -295,8 +295,14 @@
]]>
-
-
+
+ The XPath Router does support custom implementations of the XmlPayloadConverter strategy, and when configuring
+ an 'xpath-router' element in XML, a reference to such an implementation may be provided via the 'converter' attribute.
+ However, the DefaultXmlPayloadConverter is used if this reference is not provided, and it
+ should be sufficient in most cases since it can convert from Node, Document, Source,
+ File, and String typed payloads. If you need to extend beyond the capabilities of
+ that default implementation, then an upstream Transformer is probably a better option
+ than providing a reference to a custom implementation of this strategy here.
@@ -395,7 +401,7 @@
XML Payload Converter
- You can also use implementation of the org.springframework.integration.xml.XmlPayloadConverter to
+ You can also use an implementation of the org.springframework.integration.xml.XmlPayloadConverter to
provide more granular transformation:
@@ -421,6 +427,12 @@
}
}]]>
+ The DefaultXmlPayloadConverter is used if this reference is not provided, and it
+ should be sufficient in most cases since it can convert from Node, Document, Source,
+ File, and String typed payloads. If you need to extend beyond the capabilities of
+ that default implementation, then an upstream Transformer is probably a better option
+ than providing a reference to a custom implementation of this strategy here.
+
Combination of SpEL and XPath expressions
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 caeada5fd7..ad5b5c7499 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
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors.
+ * Copyright 2002-2011 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.
@@ -60,6 +60,7 @@ public class XPathRouterParser extends AbstractRouterParser {
else {
xpathRouterBuilder.addConstructorArgReference(xPathExpressionRef);
}
+ IntegrationNamespaceUtils.setReferenceIfAttributeDefined(xpathRouterBuilder, element, "converter");
return xpathRouterBuilder.getBeanDefinition();
}
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 c4c66153c5..c28d265041 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
@@ -225,6 +225,11 @@
Specify the XmlPayloadConverter to use when converting a Message payload prior to XPath evaluation.
+ The DefaultXmlPayloadConverter is used if this reference is not provided, and it
+ should be sufficient in most cases since it can convert from Node, Document, Source,
+ File, and String typed payloads. If you need to extend beyond the capabilities of
+ that default implementation, then an upstream Transformer is probably a better option
+ than providing a reference to a custom implementation of this strategy here.
@@ -399,6 +404,23 @@
+
+
+
+ Specify the Converter to use when converting payloads prior to XPath evaluation.
+ The DefaultXmlPayloadConverter is used if this reference is not provided, and it
+ should be sufficient in most cases since it can convert from Node, Document, Source,
+ File, and String typed payloads. If you need to extend beyond the capabilities of
+ that default implementation, then an upstream Transformer is probably a better option
+ than providing a reference to a custom implementation of this strategy here.
+
+
+
+
+
+
+
+
diff --git a/spring-integration-xml/src/main/resources/org/springframework/integration/xml/config/spring-integration-xml-2.1.xsd b/spring-integration-xml/src/main/resources/org/springframework/integration/xml/config/spring-integration-xml-2.1.xsd
index b743625446..39981b23eb 100644
--- a/spring-integration-xml/src/main/resources/org/springframework/integration/xml/config/spring-integration-xml-2.1.xsd
+++ b/spring-integration-xml/src/main/resources/org/springframework/integration/xml/config/spring-integration-xml-2.1.xsd
@@ -225,6 +225,11 @@
Specify the XmlPayloadConverter to use when converting a Message payload prior to XPath evaluation.
+ The DefaultXmlPayloadConverter is used if this reference is not provided, and it
+ should be sufficient in most cases since it can convert from Node, Document, Source,
+ File, and String typed payloads. If you need to extend beyond the capabilities of
+ that default implementation, then an upstream Transformer is probably a better option
+ than providing a reference to a custom implementation of this strategy here.
@@ -411,6 +416,23 @@
+
+
+
+ Specify the Converter to use when converting payloads prior to XPath evaluation.
+ The DefaultXmlPayloadConverter is used if this reference is not provided, and it
+ should be sufficient in most cases since it can convert from Node, Document, Source,
+ File, and String typed payloads. If you need to extend beyond the capabilities of
+ that default implementation, then an upstream Transformer is probably a better option
+ than providing a reference to a custom implementation of this strategy here.
+
+
+
+
+
+
+
+
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 69b62d47d6..84c7e5e7cb 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
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors.
+ * Copyright 2002-2011 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.
@@ -20,14 +20,18 @@ import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertEquals;
+import org.w3c.dom.Document;
+
import org.junit.After;
import org.junit.Test;
+
import org.springframework.beans.DirectFieldAccessor;
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.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.core.PollableChannel;
@@ -36,9 +40,9 @@ 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.DefaultXmlPayloadConverter;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.test.context.ContextConfiguration;
-import org.w3c.dom.Document;
/**
* @author Jonas Partner
@@ -235,7 +239,31 @@ public class XPathRouterParserTests {
GenericMessage docMessage = new GenericMessage(doc);
inputChannel.send(docMessage);
assertNotNull(channelA.receive(10));
-
+ }
+
+ @Test
+ public void testWithCustomXmlPayloadConverter() throws Exception {
+ ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("XPathRouterTests-context.xml", this.getClass());
+ MessageChannel inputChannel = ac.getBean("customConverterChannel", MessageChannel.class);
+ PollableChannel channelZ = ac.getBean("channelZ", PollableChannel.class);
+ GenericMessage message = new GenericMessage("channelA");
+ inputChannel.send(message);
+ Message> result = channelZ.receive(0);
+ assertNotNull(result);
+ assertEquals("channelA", result.getPayload());
+ }
+
+
+ @SuppressWarnings("unused")
+ private static class TestXmlPayloadConverter extends DefaultXmlPayloadConverter {
+
+ @Override
+ public Document convertToDocument(Object object) {
+ if (object instanceof String) {
+ object = ((String) object).replace("A", "Z");
+ }
+ return super.convertToDocument(object);
+ }
}
}
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
index cd5f805613..0b8a83dc3c 100644
--- 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
@@ -4,8 +4,8 @@
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-xml="http://www.springframework.org/schema/integration/xml"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
- http://www.springframework.org/schema/integration/xml http://www.springframework.org/schema/integration/xml/spring-integration-xml-2.0.xsd">
+ http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsd
+ http://www.springframework.org/schema/integration/xml http://www.springframework.org/schema/integration/xml/spring-integration-xml-2.1.xsd">
@@ -26,6 +26,10 @@
+
+
+
+
@@ -35,4 +39,10 @@
+
+
+
+
+
+