On Mon, Aug 13, 2012 at 4:04 PM, chris.koester
<[email protected]> wrote:
> I am trying to get a camel header variable via an xpath expression in a
> processor.
>
> import org.apache.camel.builder.xml.XPathBuilder;
> ...
>
> from(endpointUri)
>         .process(new Processor() {
>
>                 @Override
>                 public void process(Exchange ex) throws Exception {
>
>                 result = XPathBuilder.xpath("in:header('breadcrumbId')")
>                                                         .evaluate(ex, 
> String.class);
>
>                 }
> }}).end();
>
> However this will trow a
> "XPathException: Can not convert #STRING to a NodeList!" exception.
> Trying simlpe xpath expressions like "foo/bar" works, so this might be an
> error in the camel XPathBuilder.
>
> While debugging it is getting the actual breadcrumb id, but although the
> result type is set to String there seems to happen a convertion to a
> NodeList, which fails.
>

Its better to configure it to use a stringResult explicit when you do
it like that

                 result =
XPathBuilder.xpath("in:header('breadcrumbId')").stringResult().
                                                         .evaluate(ex,
String.class);

There is a number of buit-in types that the xpath engine support, and
you can configure them using the xxxResult method, or the
resultType(class) method.

Then it ought to use String directly.



> Am I using it wrong or is this a bug?
>
> Trace: http://pastebin.com/ESZTx53R
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/XPathBuilder-used-in-Processor-throws-XPathException-for-header-variables-tp5717243.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: [email protected]
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Reply via email to