SAM
SAM

Reputation: 47

Extract a value from a property in camel-context.xml

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?

Upvotes: 1

Views: 3201

Answers (2)

Matthew Wilson
Matthew Wilson

Reputation: 2065

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

Upvotes: 1

bgossit
bgossit

Reputation: 1086

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>

Upvotes: 0

Related Questions