![](/img/trans.png)
[英]Spring int-xml:xpath-expression erros with node function
[英]xpath-router doesn't route message with xpath-expression
我將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 nodes = (NodeList) evaluate(node, 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 FYI。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.