1

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.

1 Answer 1

2

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 &#39;FirstNameOfStudent&#39;. So, You can figure it out.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.