camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject Re: an un-easy way to use camel-xpath in:header() function
Date Sat, 21 May 2011 11:58:54 GMT

You can use a POJO to set the header using xpath.
The xpath builder was designed to work on the message body.

I wonder if your use case is widespread used, so its okay to alter the
code to support the use case?

On Fri, May 20, 2011 at 11:23 AM, tobeand <> wrote:
> I guess the XPath language of Camel has one limitation. That is the
> body of input message must be a valid XML or null.
> In this problem, user want use XPath to process a xml in message
> header, but the message body is a plain text (not valid XML), and an
> exception occurs in parsing the content to DOM.
> After reading source code, we found that the
> XPathBuilder.doInEvaluateAs() method try to extract the document from
> the input message, and pass the document to XPathExpression.evaluate()
> method. The XPathBuilder.getDocument() method creates an InputSource
> for the text body and then the XPathExpression.evaluate() method
> creates a DocumentBuilder to parse the InputSource.
> On Fri, May 20, 2011 at 2:24 PM, Taariq Levack <> wrote:
>> Also if null or an empty xml is valid in some situations, then a content
>> based router in front of this should do niely.
>> On Fri, May 20, 2011 at 8:18 AM, Taariq Levack <> wrote:
>>> Have you looked at the Validation component?
>>> On Fri, May 20, 2011 at 7:10 AM, ext2 <> wrote:
>>>> Using camel's in:header() xpath function,  we can deal with  xml stored
>>>> message header very easy; for example:
>>>>        <setHeader name="cheaperBooks">
>>>>  <xpath>in:header('bookstore')/child::book[price<100]</xpath>
>>>>        </setHeader>
>>>> The setHeader could retrieve all cheaper books(price less than 100) from
>>>> bookstore xml (which already stored in message header('bookstore')
>>>> But in camel, things are not always so easy. The user must make sure input
>>>> message's body must be a valid XML or null(although the body's content may
>>>> have nothing to do with the bookstore xml). Otherwise the above xapth
>>>> express will failed;
>>>> Suggestion(Maybe):
>>>> Camel's XPath expression should check if the input body's content could be
>>>> convert to xml. If the body cannot, then using a null instead of original
>>>> message body to do XPathExpression.evaluate;

Claus Ibsen
CamelOne 2011:
Twitter: davsclaus, fusenews
Author of Camel in Action:

View raw message