1

The input looks like below,

<book author="ABC" type="Children">
    <id>123</id>
    <name>XYZ</name>
</book>

I have set the above in property in an xml route as:

<camel:setProperty propertyName="REQUEST">
    <camel:xpath>/node()</camel:xpath>
</camel:setProperty>

Then I do some other processing and based on the new response I want to extract the value of an author(i.e. ABC) from this Property and compare it with a element's text string from the response.

I tried a few ways using camel:xpath and camel:simple but am not able to extract the value from property.

What is the correct way to extract this property?

SAM
  • 49
  • 1
  • 11

2 Answers2

1

To access the REQUEST property using simple you can do this:

${property.REQUEST}

To access properties using xpath:

<camel:xpath>
    function:properties("REQUEST")/[add your xpath expression here]
</camel:xpath>

More info on the properties function can be found here - https://camel.apache.org/xpath.html

Matthew Wilson
  • 2,045
  • 14
  • 27
0

I don't know if it's possible using properties, but you should be able to do it with headers.

Firstly:

<setHeader headerName="REQUEST">
    <xpath>/node()</xpath>
</setHeader>

Then if you wanted to set another header with just the author value:

<setHeader headerName="REQUEST2">
    <xpath headerName="REQUEST" resultType="java.lang.String">/book/@author</xpath>
</setHeader>

Or if you wanted to evaluate the value as a <choice> condition:

<when>
    <xpath headerName="REQUEST">/book/@author = 'ABC'</xpath>
bgossit
  • 1,086
  • 9
  • 13
  • This headerName in xpath only works from camel 2.11 and we are using 2.10. Also, I want the above one using propery only. – SAM Mar 27 '14 at 08:54