You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "chris.koester" <ch...@catify.com> on 2012/08/13 16:04:11 UTC

XPathBuilder used in Processor() throws XPathException for header variables

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.

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.

Re: XPathBuilder used in Processor() throws XPathException for header variables

Posted by "chris.koester" <ch...@catify.com>.
Awesome, that did it. 

Thanks for the quick reply.



--
View this message in context: http://camel.465427.n5.nabble.com/XPathBuilder-used-in-Processor-throws-XPathException-for-header-variables-tp5717243p5717245.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: XPathBuilder used in Processor() throws XPathException for header variables

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Aug 13, 2012 at 4:04 PM, chris.koester
<ch...@catify.com> 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: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen