Reputation: 13
I have defined a header in my route and want to use the value of the header to determine the other header value.
Example:
<route id="use_reference_number">
<from uri="direct:file_name:use_reference_number">
<setHeader headerName="FirstNameOfStudent">
<xpath resultType="java.lang.String">//*/Student/StudentName/FirstName/text()</xpath>
</setHeader>
<setHeader headerName="NumberOfStudentByThatName">
<xpath>count(//*/Student[StudentName/FirstName/text() = ${in.header.FirstNameOfStudent}])</xpath>
</setHeader>
</route>
Basically here based on the result from separate x path I want to determine the count of students tags in second one and finally using "NumberOfStudentByThatName" in choice - when to take separate routes. but when I use this expression it returns 0. I think it is not able to resolve the header.
<setHeader headerName="NumberOfStudentByThatName">
<xpath>count(//*/Student[StudentName/FirstName/text() = 'AMAN'])</xpath>
</setHeader>
When I use it like above it works perfectly fine , but I don't want to hard code any value instead use what is in the input .
In this case I have two separate xmls and want to use them in cleaner way.
Upvotes: 1
Views: 1236
Reputation: 4120
According to Camel XPath Component Documentation there are special Camel XPath functions like in:body
, in:header
etc:
I guess you can make it like:
<setHeader headerName="NumberOfStudentByThatName">
<xpath>count(//*/Student[StudentName/FirstName/text() = in:header("FirstNameOfStudent")])</xpath>
</setHeader>
PS. I did not test it and I'm not sure about double quotes in header name - doc page shows me URL encoded values like 'FirstNameOfStudent'
. So, You can figure it out.
Upvotes: 2