0

I'm trying to use camel xpath filter in my camel route. I get an error in my unit test that I cannot solve. I Would appreciate some help.

When trying to analyse the following 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>

With the following xpath:

.filter().xpath("/publication/resource/resourceFamily/releasedOnPww/text() = 'true'")

I get the following exception:

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)

What's kind of weird is that the code seems to run OK in run-time, the error occurs only during unit testing.

Konstantin V. Salikhov
  • 4,554
  • 2
  • 35
  • 48
Alexandre Mélard
  • 12,229
  • 3
  • 36
  • 46
  • Can you share parts from your route and unit test? – ltsallas Nov 26 '14 at 09:16
  • Would be difficult to share the code Itsallas because it's quite big... Anyway I think that the message might be empty before rushing my xpath. If the event is null, could that explain the matter? – Alexandre Mélard Nov 26 '14 at 15:02
  • 2
    There is nothing wrong in your xpath expression. I got the same exception in a unit test with null body in the exchange. When the exchange body is not null it works as expected. – ltsallas Nov 26 '14 at 17:52

1 Answers1

2

I think you should try this

.filter().xpath("/publication/resource/resourceFamily[releasedOnPww='true']")

May be the problem in namespace see this thread http://camel.465427.n5.nabble.com/fail-filter-XPATH-camel-td476424.html

EDIT: My comment able to solve the problem, as @Mylen said. So i am including the comment into this answer. Even your Xpath Expression looks fine. Once try to check XML in body .log(" (body) = ${body}"). May be consumed XML is not same as expected one.

Honey Goyal
  • 445
  • 4
  • 22