You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Jan Matèrne (jhm)" <ap...@materne.de> on 2013/07/30 10:57:12 UTC

XPath + DOM-reuse

I have a route dispatching an exchange according to a XPath evaluation to
different targets.

Sadly it doesnt perform very well. I think that the DOM is built for every
XPath evalutation.

Is it true? Can we configure Camel to reuse the DOM?

 

I think in this Route Camel builds the same DOM 4 times.

 

public class MyRouter extends RouteBuilder {

    @Override

    public void configure() throws Exception {

        Namespaces v1 = new Namespaces("v1", "...");

        Namespaces v2 = new Namespaces("v2", "...");

           

        from("direct:dispatcher")

            .id("dispatcher")

            .choice()

                .when().xpath("/v1:TypeA",
v1).to("bean:beanA?method=execute")

                .when().xpath("/v1:TypeB",
v1).to("bean:beanB?method=execute")

                .when().xpath("/v2:TypeA",
v2).to("bean:beanC?method=execute")

                .when().xpath("/v2:TypeB",
v2).to("bean:beanD?method=execute")

                // many more when().xpath().to() statements

            .end();

    }

}

 

 

Jan


AW: XPath + DOM-reuse

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
Thanks

Jan

> -----Ursprüngliche Nachricht-----
> Von: Raul Kripalani [mailto:raul@evosent.com]
> Gesendet: Dienstag, 30. Juli 2013 12:07
> An: users@camel.apache.org
> Betreff: Re: XPath + DOM-reuse
> 
> Just a little tip. Be careful with concurrency as DOM is not thread-
> safe.
> 
> So if you've got multiple XPath expressions or XSLT transformations
> running in parallel (e.g. multicast EIP), you might get errors.
> 
> Regards,
> Raúl.
> 
> On Tue, Jul 30, 2013 at 10:16 AM, Jan Matèrne (jhm)
> <ap...@materne.de>wrote:
> 
> > Thanks, I will try ...
> >
> > Jan
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> > > Gesendet: Dienstag, 30. Juli 2013 11:09
> > > An: users@camel.apache.org
> > > Betreff: Re: XPath + DOM-reuse
> > >
> > > Hi
> > >
> > > You can convert the body to DOM first
> > >
> > > from
> > > .convertBodyTo(Document.class)
> > > choice
> > >
> > >
> > >
> > >
> > > Also you can add camel-saxon to the classpath to use saxon as the
> > > xpath engine. Its faster than what comes out of the box in the JDK.
> > >
> > >
> > > You can use vtd-xml for an xpath language that can work with
> > > streamed data types http://camel.apache.org/vtd-xml
> > >
> > > On Tue, Jul 30, 2013 at 10:57 AM, Jan Matèrne (jhm)
> > > <ap...@materne.de>
> > > wrote:
> > > > I have a route dispatching an exchange according to a XPath
> > > evaluation
> > > > to different targets.
> > > >
> > > > Sadly it doesnt perform very well. I think that the DOM is built
> > > > for every XPath evalutation.
> > > >
> > > > Is it true? Can we configure Camel to reuse the DOM?
> > > >
> > > >
> > > >
> > > > I think in this Route Camel builds the same DOM 4 times.
> > > >
> > > >
> > > >
> > > > public class MyRouter extends RouteBuilder {
> > > >
> > > >     @Override
> > > >
> > > >     public void configure() throws Exception {
> > > >
> > > >         Namespaces v1 = new Namespaces("v1", "...");
> > > >
> > > >         Namespaces v2 = new Namespaces("v2", "...");
> > > >
> > > >
> > > >
> > > >         from("direct:dispatcher")
> > > >
> > > >             .id("dispatcher")
> > > >
> > > >             .choice()
> > > >
> > > >                 .when().xpath("/v1:TypeA",
> > > > v1).to("bean:beanA?method=execute")
> > > >
> > > >                 .when().xpath("/v1:TypeB",
> > > > v1).to("bean:beanB?method=execute")
> > > >
> > > >                 .when().xpath("/v2:TypeA",
> > > > v2).to("bean:beanC?method=execute")
> > > >
> > > >                 .when().xpath("/v2:TypeB",
> > > > v2).to("bean:beanD?method=execute")
> > > >
> > > >                 // many more when().xpath().to() statements
> > > >
> > > >             .end();
> > > >
> > > >     }
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Jan
> > > >
> > >
> > >
> > >
> > > --
> > > 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 + DOM-reuse

Posted by Raul Kripalani <ra...@evosent.com>.
Just a little tip. Be careful with concurrency as DOM is not thread-safe.

So if you've got multiple XPath expressions or XSLT transformations running
in parallel (e.g. multicast EIP), you might get errors.

Regards,
Raúl.

On Tue, Jul 30, 2013 at 10:16 AM, Jan Matèrne (jhm) <ap...@materne.de>wrote:

> Thanks, I will try ...
>
> Jan
>
> > -----Ursprüngliche Nachricht-----
> > Von: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> > Gesendet: Dienstag, 30. Juli 2013 11:09
> > An: users@camel.apache.org
> > Betreff: Re: XPath + DOM-reuse
> >
> > Hi
> >
> > You can convert the body to DOM first
> >
> > from
> > .convertBodyTo(Document.class)
> > choice
> >
> >
> >
> >
> > Also you can add camel-saxon to the classpath to use saxon as the xpath
> > engine. Its faster than what comes out of the box in the JDK.
> >
> >
> > You can use vtd-xml for an xpath language that can work with streamed
> > data types http://camel.apache.org/vtd-xml
> >
> > On Tue, Jul 30, 2013 at 10:57 AM, Jan Matèrne (jhm) <ap...@materne.de>
> > wrote:
> > > I have a route dispatching an exchange according to a XPath
> > evaluation
> > > to different targets.
> > >
> > > Sadly it doesnt perform very well. I think that the DOM is built for
> > > every XPath evalutation.
> > >
> > > Is it true? Can we configure Camel to reuse the DOM?
> > >
> > >
> > >
> > > I think in this Route Camel builds the same DOM 4 times.
> > >
> > >
> > >
> > > public class MyRouter extends RouteBuilder {
> > >
> > >     @Override
> > >
> > >     public void configure() throws Exception {
> > >
> > >         Namespaces v1 = new Namespaces("v1", "...");
> > >
> > >         Namespaces v2 = new Namespaces("v2", "...");
> > >
> > >
> > >
> > >         from("direct:dispatcher")
> > >
> > >             .id("dispatcher")
> > >
> > >             .choice()
> > >
> > >                 .when().xpath("/v1:TypeA",
> > > v1).to("bean:beanA?method=execute")
> > >
> > >                 .when().xpath("/v1:TypeB",
> > > v1).to("bean:beanB?method=execute")
> > >
> > >                 .when().xpath("/v2:TypeA",
> > > v2).to("bean:beanC?method=execute")
> > >
> > >                 .when().xpath("/v2:TypeB",
> > > v2).to("bean:beanD?method=execute")
> > >
> > >                 // many more when().xpath().to() statements
> > >
> > >             .end();
> > >
> > >     }
> > >
> > > }
> > >
> > >
> > >
> > >
> > >
> > > Jan
> > >
> >
> >
> >
> > --
> > 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
>
>

AW: XPath + DOM-reuse

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
Thanks, I will try ...

Jan

> -----Ursprüngliche Nachricht-----
> Von: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Gesendet: Dienstag, 30. Juli 2013 11:09
> An: users@camel.apache.org
> Betreff: Re: XPath + DOM-reuse
> 
> Hi
> 
> You can convert the body to DOM first
> 
> from
> .convertBodyTo(Document.class)
> choice
> 
> 
> 
> 
> Also you can add camel-saxon to the classpath to use saxon as the xpath
> engine. Its faster than what comes out of the box in the JDK.
> 
> 
> You can use vtd-xml for an xpath language that can work with streamed
> data types http://camel.apache.org/vtd-xml
> 
> On Tue, Jul 30, 2013 at 10:57 AM, Jan Matèrne (jhm) <ap...@materne.de>
> wrote:
> > I have a route dispatching an exchange according to a XPath
> evaluation
> > to different targets.
> >
> > Sadly it doesnt perform very well. I think that the DOM is built for
> > every XPath evalutation.
> >
> > Is it true? Can we configure Camel to reuse the DOM?
> >
> >
> >
> > I think in this Route Camel builds the same DOM 4 times.
> >
> >
> >
> > public class MyRouter extends RouteBuilder {
> >
> >     @Override
> >
> >     public void configure() throws Exception {
> >
> >         Namespaces v1 = new Namespaces("v1", "...");
> >
> >         Namespaces v2 = new Namespaces("v2", "...");
> >
> >
> >
> >         from("direct:dispatcher")
> >
> >             .id("dispatcher")
> >
> >             .choice()
> >
> >                 .when().xpath("/v1:TypeA",
> > v1).to("bean:beanA?method=execute")
> >
> >                 .when().xpath("/v1:TypeB",
> > v1).to("bean:beanB?method=execute")
> >
> >                 .when().xpath("/v2:TypeA",
> > v2).to("bean:beanC?method=execute")
> >
> >                 .when().xpath("/v2:TypeB",
> > v2).to("bean:beanD?method=execute")
> >
> >                 // many more when().xpath().to() statements
> >
> >             .end();
> >
> >     }
> >
> > }
> >
> >
> >
> >
> >
> > Jan
> >
> 
> 
> 
> --
> 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 + DOM-reuse

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

You can convert the body to DOM first

from
.convertBodyTo(Document.class)
choice




Also you can add camel-saxon to the classpath to use saxon as the
xpath engine. Its faster than what comes out of the box in the JDK.


You can use vtd-xml for an xpath language that can work with streamed data types
http://camel.apache.org/vtd-xml

On Tue, Jul 30, 2013 at 10:57 AM, Jan Matèrne (jhm) <ap...@materne.de> wrote:
> I have a route dispatching an exchange according to a XPath evaluation to
> different targets.
>
> Sadly it doesnt perform very well. I think that the DOM is built for every
> XPath evalutation.
>
> Is it true? Can we configure Camel to reuse the DOM?
>
>
>
> I think in this Route Camel builds the same DOM 4 times.
>
>
>
> public class MyRouter extends RouteBuilder {
>
>     @Override
>
>     public void configure() throws Exception {
>
>         Namespaces v1 = new Namespaces("v1", "...");
>
>         Namespaces v2 = new Namespaces("v2", "...");
>
>
>
>         from("direct:dispatcher")
>
>             .id("dispatcher")
>
>             .choice()
>
>                 .when().xpath("/v1:TypeA",
> v1).to("bean:beanA?method=execute")
>
>                 .when().xpath("/v1:TypeB",
> v1).to("bean:beanB?method=execute")
>
>                 .when().xpath("/v2:TypeA",
> v2).to("bean:beanC?method=execute")
>
>                 .when().xpath("/v2:TypeB",
> v2).to("bean:beanD?method=execute")
>
>                 // many more when().xpath().to() statements
>
>             .end();
>
>     }
>
> }
>
>
>
>
>
> Jan
>



-- 
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