You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ychawla <pr...@yahoo.com> on 2013/08/27 17:40:41 UTC

Xpath parameter binding NodeList vs. Node

Hello All,
I am using Camel Xpath parameter binding.  I have a method that has an
expression like this for example:

	public void process(Exchange exchange,
			@OJBCamelXPath("/foo:Container") NodeList containerNodeList) throws
Exception

I know that the Xpath will only return a single node, however, I need to
bind to  the parameter NodeList or else I get this exception:

camel  No type converter available to convert from type:
org.apache.xml.dtm.ref.DTMNodeList to the required type: org.w3c.dom.Node

I saw this Camel issue that was resolved:

https://issues.apache.org/jira/browse/CAMEL-5403

This suggests that there is a type converter to go from a NodeList of size 1
to a Node.  I am using Camel 2.10.3 so I should have this typeconverter.

Is this typeconverter used with parameter binding or only in the Xpath in
the DSL?

Thanks,
Yogesh



--
View this message in context: http://camel.465427.n5.nabble.com/Xpath-parameter-binding-NodeList-vs-Node-tp5738067.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Xpath parameter binding NodeList vs. Node

Posted by ychawla <pr...@yahoo.com>.
Hi Raul,
Thanks for you reply.  The query returns exactly one node. To retrieve the
node, I do something like this:

Node containerNode = containerNodeList.item(0);

The OJBCamelXpath annotation is a class like this:

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
@LanguageAnnotation(language = "xpath", factory =
XPathAnnotationExpressionFactory.class)
public @interface OJBCamelXpath {
    String value();

    // You can add the namespaces as the default value of the annotation
    NamespacePrefix[] namespaces() default {
    @NamespacePrefix(prefix = "foo", uri = "http://someNamespace/1.0")
    };

    Class<?> resultType() default NodeList.class;
}

It allows you to do an Xpath bean parameter binding.  It allows for "Xpath
injection" as described on this page:

http://camel.apache.org/xpath.html

Thanks!

Yogesh



--
View this message in context: http://camel.465427.n5.nabble.com/Xpath-parameter-binding-NodeList-vs-Node-tp5738067p5738072.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Xpath parameter binding NodeList vs. Node

Posted by Raul Kripalani <ra...@evosent.com>.
I wonder if your XPath is returning zero nodes. Try to find out the length
of the NodeList with the getLength method.

What exactly is this @OJBCamelXPath annotation? And how does it recognise
namespace "foo"? You don't seem to declare it (unless the custom annotation
is taking care of it somehow - an extension of the standard XPath?).

Please paste the source of @OJBCamelXPath and a sample input XML document.

Thanks,

*Raúl Kripalani*
Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Tue, Aug 27, 2013 at 4:40 PM, ychawla <pr...@yahoo.com>wrote:

> Hello All,
> I am using Camel Xpath parameter binding.  I have a method that has an
> expression like this for example:
>
>         public void process(Exchange exchange,
>                         @OJBCamelXPath("/foo:Container") NodeList
> containerNodeList) throws
> Exception
>
> I know that the Xpath will only return a single node, however, I need to
> bind to  the parameter NodeList or else I get this exception:
>
> camel  No type converter available to convert from type:
> org.apache.xml.dtm.ref.DTMNodeList to the required type: org.w3c.dom.Node
>
> I saw this Camel issue that was resolved:
>
> https://issues.apache.org/jira/browse/CAMEL-5403
>
> This suggests that there is a type converter to go from a NodeList of size
> 1
> to a Node.  I am using Camel 2.10.3 so I should have this typeconverter.
>
> Is this typeconverter used with parameter binding or only in the Xpath in
> the DSL?
>
> Thanks,
> Yogesh
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Xpath-parameter-binding-NodeList-vs-Node-tp5738067.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Xpath parameter binding NodeList vs. Node

Posted by Claus Ibsen <cl...@gmail.com>.
I logged a ticket about this
https://issues.apache.org/jira/browse/CAMEL-6674

On Wed, Aug 28, 2013 at 8:04 AM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> When you have Node as the type. Can you try test
>
> a)
> first with a use-case where there is only 1 element. And then onwards,
> 0 or 2+ elements?
>
> b)
> And then do another test where the first use-case has 2+ elements,.
> and then 1 element.
>
> I suspend in (b) Camel regards the type converter NodeList -> Node as
> not good as it failed the first time.
>
> The code in camel-core is likely wrong and we would need to fix that.
>
>
> On Tue, Aug 27, 2013 at 5:40 PM, ychawla <pr...@yahoo.com> wrote:
>> Hello All,
>> I am using Camel Xpath parameter binding.  I have a method that has an
>> expression like this for example:
>>
>>         public void process(Exchange exchange,
>>                         @OJBCamelXPath("/foo:Container") NodeList containerNodeList) throws
>> Exception
>>
>> I know that the Xpath will only return a single node, however, I need to
>> bind to  the parameter NodeList or else I get this exception:
>>
>> camel  No type converter available to convert from type:
>> org.apache.xml.dtm.ref.DTMNodeList to the required type: org.w3c.dom.Node
>>
>> I saw this Camel issue that was resolved:
>>
>> https://issues.apache.org/jira/browse/CAMEL-5403
>>
>> This suggests that there is a type converter to go from a NodeList of size 1
>> to a Node.  I am using Camel 2.10.3 so I should have this typeconverter.
>>
>> Is this typeconverter used with parameter binding or only in the Xpath in
>> the DSL?
>>
>> Thanks,
>> Yogesh
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Xpath-parameter-binding-NodeList-vs-Node-tp5738067.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Xpath parameter binding NodeList vs. Node

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

When you have Node as the type. Can you try test

a)
first with a use-case where there is only 1 element. And then onwards,
0 or 2+ elements?

b)
And then do another test where the first use-case has 2+ elements,.
and then 1 element.

I suspend in (b) Camel regards the type converter NodeList -> Node as
not good as it failed the first time.

The code in camel-core is likely wrong and we would need to fix that.


On Tue, Aug 27, 2013 at 5:40 PM, ychawla <pr...@yahoo.com> wrote:
> Hello All,
> I am using Camel Xpath parameter binding.  I have a method that has an
> expression like this for example:
>
>         public void process(Exchange exchange,
>                         @OJBCamelXPath("/foo:Container") NodeList containerNodeList) throws
> Exception
>
> I know that the Xpath will only return a single node, however, I need to
> bind to  the parameter NodeList or else I get this exception:
>
> camel  No type converter available to convert from type:
> org.apache.xml.dtm.ref.DTMNodeList to the required type: org.w3c.dom.Node
>
> I saw this Camel issue that was resolved:
>
> https://issues.apache.org/jira/browse/CAMEL-5403
>
> This suggests that there is a type converter to go from a NodeList of size 1
> to a Node.  I am using Camel 2.10.3 so I should have this typeconverter.
>
> Is this typeconverter used with parameter binding or only in the Xpath in
> the DSL?
>
> Thanks,
> Yogesh
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Xpath-parameter-binding-NodeList-vs-Node-tp5738067.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen