我试图在我的骆驼路线中使用驼峰xpath滤镜。我的单元测试中出现了一个我无法解决的错误。我会感激一些帮助。
尝试分析以下xml时:
<publication>
<publicationId>1</publicationId>
<alias>false</alias>
<publicationType>NEW</publicationType>
<zone>VALIDATION</zone>
<routingKey>WWX_VECTOR</routingKey>
<contexts>
<context>GEO</context>
</contexts>
<resource>
<resourceFamily>
<releasedOnPww>false</releasedOnPww>
</resourceFamily>
<featureType>
<name>buildings</name>
</featureType>
</resource>
</publication>
使用以下xpath:
.filter().xpath("/publication/resource/resourceFamily/releasedOnPww/text() = 'true'")
我得到以下异常:
Caused by: java.lang.RuntimeException: Unable to evaluate expression using this context
at com.sun.org.apache.xpath.internal.axes.NodeSequence.setRoot(NodeSequence.java:212)
at com.sun.org.apache.xpath.internal.axes.LocPathIterator.execute(LocPathIterator.java:210)
at com.sun.org.apache.xpath.internal.Expression.execute(Expression.java:153)
at com.sun.org.apache.xpath.internal.operations.Operation.execute(Operation.java:107)
at com.sun.org.apache.xpath.internal.XPath.execute(XPath.java:335)
奇怪的是,代码似乎在运行时运行正常,错误仅在单元测试期间发生。
答案 0 :(得分:2)
我认为你应该试试这个
.filter().xpath("/publication/resource/resourceFamily[releasedOnPww='true']")
可能是命名空间中的问题,请参阅此帖子http://camel.465427.n5.nabble.com/fail-filter-XPATH-camel-td476424.html
编辑:我的评论能够解决问题,正如@Mylen所说。所以我将评论纳入这个答案。
甚至你的Xpath Expression看起来也不错。尝试检查正文.log(" (body) = ${body}")
中的XML。可能消耗的XML与预期的不一样。