gpt4 book ai didi

java - xpath-router 不使用 xpath-expression 路由消息

转载 作者:行者123 更新时间:2023-12-02 07:59:00 25 4
gpt4 key购买 nike

我将 Spring Integration XML 路由器与 xpath-expression 结合使用

<int:chain input-channel="routerInputChannel">
<int-xml:xpath-router default-output-channel="routerOutputChannel">
<int-xml:xpath-expression expression="//actor[1]/text()"/>
<int-xml:mapping value="Christian Bale" channel="routerBaleChannel"/>
</int-xml:xpath-router>
</int:chain>

并期望此 XML 字符串作为 SI 消息有效负载

<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
<actors>
<actor id="1">Christian Bale</actor>
<actor id="2">Liam Neeson</actor>
<actor id="3">Michael Caine</actor>
</actors>
<foo:singers>
<foo:singer id="4">Tom Waits</foo:singer>
<foo:singer id="5">B.B. King</foo:singer>
<foo:singer id="6">Ray Charles</foo:singer>
</foo:singers>
</root>

将被发送到routerBaleChannel,但由于某种原因它不起作用。

我尝试了 XPath Tester / Evaluator 处的消息和 XPath 表达式正如预期的那样,我得到了 Christian Bale 字符串。

我调试了org.springframework.integration.xml.router.XPathRouter方法getChannelKeys并在Jaxp13XPathExpressionFactory方法evaluate中看到了一些问题:执行后原因不明

NodeList 节点 = (NodeList) 评估(节点, XPathConstants.NODESET);

nodes.getLength() 返回空列表。

那么我的 XPath 路由器或 XPath 表达式配置出了什么问题?

最佳答案

对我有用:

<int:chain input-channel="inputChannel">
<int-xml:xpath-router>
<int-xml:xpath-expression expression="//actor[1]/text()"/>
<int-xml:mapping value="Christian Bale" channel="routerBaleChannel"/>
</int-xml:xpath-router>
</int:chain>

<int:channel id="routerBaleChannel">
<int:queue/>
</int:channel>

...

@Test
public void testSO45173221() {
ClassPathXmlApplicationContext ac =
new ClassPathXmlApplicationContext("XPathRouterTests-context.xml", this.getClass());
MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);
PollableChannel channelBale = ac.getBean("routerBaleChannel", PollableChannel.class);
GenericMessage<String> message =
new GenericMessage<>("<root xmlns:foo=\"http://www.foo.org/\" xmlns:bar=\"http://www.bar.org\">\n" +
" <actors>\n" +
" <actor id=\"1\">Christian Bale</actor>\n" +
" <actor id=\"2\">Liam Neeson</actor>\n" +
" <actor id=\"3\">Michael Caine</actor>\n" +
" </actors>\n" +
" <foo:singers>\n" +
" <foo:singer id=\"4\">Tom Waits</foo:singer>\n" +
" <foo:singer id=\"5\">B.B. King</foo:singer>\n" +
" <foo:singer id=\"6\">Ray Charles</foo:singer>\n" +
" </foo:singers>\n" +
"</root>");
inputChannel.send(message);
Message<?> result = channelBale.receive(0);
assertNotNull(result);
assertEquals(message.getPayload(), result.getPayload());
ac.close();
}

不确定您的情况发生了什么...

尽管我使用的是 Java 8(仅供引用)。

关于java - xpath-router 不使用 xpath-expression 路由消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45173221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com