From 010ed56035f7f7ad537a02cf9eaef6e8b24c86e6 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 7 Oct 2025 16:00:44 -0400 Subject: [PATCH] GH-6786: Demonstrate `#xpath()` with a `recipient-list-router` Fixes: https://github.com/spring-projects/spring-integration/issues/6786 The original request was about an `xpath-router`, however using the `#xpath()` SpEL function we don't need anything else * Show-case the `#xpath()` with a `` * Mention such a feature in the `xpath-routing.adoc` --- .../xml/xpath/XPathTests-context.xml | 5 +++++ .../integration/xml/xpath/XPathTests.java | 19 +++++++++++++++++++ .../modules/ROOT/pages/xml/xpath-routing.adoc | 9 +++++++++ 3 files changed, 33 insertions(+) diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/xpath/XPathTests-context.xml b/spring-integration-xml/src/test/java/org/springframework/integration/xml/xpath/XPathTests-context.xml index 489cbfec981..cd246ea22b6 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/xpath/XPathTests-context.xml +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/xpath/XPathTests-context.xml @@ -36,4 +36,9 @@ + + + + + diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/xpath/XPathTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/xpath/XPathTests.java index 3382ed41a7d..9e46b76a7a5 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/xpath/XPathTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/xpath/XPathTests.java @@ -77,6 +77,9 @@ public class XPathTests { @Autowired private MessageChannel xpathRouterInput; + @Autowired + private MessageChannel xpathRecipientsInput; + @Test @SuppressWarnings("unchecked") public void testXPathUtils() { @@ -205,6 +208,22 @@ public void testInt3140Router() { assertThat(receive.getPayload()).isEqualTo("X"); } + @Test + public void recipientListRouteByXpath() { + this.xpathRecipientsInput.send(new GenericMessage<>("2")); + this.xpathRecipientsInput.send(new GenericMessage<>("16")); + + Message receive = this.channelA.receive(1000); + assertThat(receive) + .extracting(Message::getPayload) + .isEqualTo("2"); + + receive = this.channelB.receive(1000); + assertThat(receive) + .extracting(Message::getPayload) + .isEqualTo("16"); + } + public static class TestNodeMapper implements NodeMapper { @Override diff --git a/src/reference/antora/modules/ROOT/pages/xml/xpath-routing.adoc b/src/reference/antora/modules/ROOT/pages/xml/xpath-routing.adoc index 42c7f4f2a60..4eb6e26f8a0 100644 --- a/src/reference/antora/modules/ROOT/pages/xml/xpath-routing.adoc +++ b/src/reference/antora/modules/ROOT/pages/xml/xpath-routing.adoc @@ -89,7 +89,16 @@ For example, if we want to route based on the name of the root node, we can use evaluate-as-string="true"> +---- + +The out-of-the-box `#xpath()` xref:spel.adoc#built-in-spel-functions[SpEL function] is also powerful enough to use with a generic router definition, including recipient list router: +[source,xml] +---- + + + + ---- [[xpath-routing-converter]]