Alexandre Mélard
Alexandre Mélard

Reputation: 12649

camel xpath: TransformerException: Unable to evaluate expression using this context

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.

Upvotes: 0

Views: 3051

Answers (1)

Honey Goyal
Honey Goyal

Reputation: 445

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.

Upvotes: 2

Related Questions