You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicemix.apache.org by Dan Diephouse <da...@envoisolutions.com> on 2007/03/16 23:51:29 UTC

XPath and Drools routing with SXC?

Hi All,

I think I wrote something which may be of use to ServiceMix, but
unfortunately I don't have time to integrate it myself - so I'm going to
throw it out there for everyone :-)

I started a project called SXC - simple xml compiler - which creates
optimized xml parsers for various things. There is one for JAXB. But, the
one of probably the most interest to this crew is the XPath frontend. SXC
can build a streaming xpath parser for you (at runtime). This means you can
listen for XPath events as you scan over the document. This allows for very
efficient XPath based routing. In my initial performance test it was about
100x faster than Jaxen for locating nodes (although thats a very rough
benchmark, real numbers may vary!)

We also integrated it with Drools so you can write XPath expressions right
in your rules.

Check out these links for more information:

http://sxc.codehaus.org
http://sxc.codehaus.org/XPath
http://sxc.codehaus.org/Drools

The one caveat is that we support only a limited subset of XPath expressions
at the moment. But if you wanted to hack SXC, its easy enough to add more.
I'm happy to help where I can or give guidance to anyone who wants to
participate as well.

Anyone up for hacking it into servicemix? :-)

- Dan

-- 
Dan Diephouse
Envoi Solutions
http://envoisolutions.com | http://netzooid.com/blog

Re: XPath and Drools routing with SXC?

Posted by Dan Diephouse <da...@envoisolutions.com>.
Hi Guillaume,


On 3/17/07, Guillaume Nodet <gn...@gmail.com> wrote:
>
> Yeah, both Drools SE and the EIP Xpath router could benefit
> such a library.  Thanks a lot, Dan !
> However this won't avoid parsing the xml to a DOM because we
> will still have to send it to the destination after the xpath routing
> has been performed.  But I think this could still boost performances
> a lot.


Well depending on the routing scenario, you could buffer the bytes that
you've parsed and send a streamsource, no? If you're simply looking to match
an xpath expression and then stop listening for xpath events and route the
the message, for example, then that could work.

  Does it support evaluating multiple xpath expression at the same time ?
> I.e. you give all the xpath expressions, and they are all evaluated at the
> same time, so that the first one matching will be fired .... Need to
> look at SXC a bit more ...


Yes you can listen for as many xpath expressions as you want as you scan the
document.

One thing I hacked up the other day looked like this. There was a
DestinationListener which was associated with a particular xpath expression
and a destination:

public class DestinationListener extends XPathEventHandler {
    private DestinationInfo destination;

    public DestinationListener(DestinationInfo destination) {
        super();
        this.destination = destination;
    }

    @Override
    public void onMatch(XPathEvent event) throws XMLStreamException {
        throw new FoundDestinationException(destination);
    }
}

You can

try {
  evaluator.evaluate(mySource);
} catch (FoundDestinationException e) {
  // route based on e.getDestination()
}

(although the exception method is kind of ugly)

- Dan


On 3/17/07, Grant M <cl...@gmail.com> wrote:
> >
> > Were you thinking of integrating it with EIP routing? That could
> > possibly be done.
> >
> > On 3/17/07, Dan Diephouse <da...@envoisolutions.com> wrote:
> > > Hi All,
> > >
> > > I think I wrote something which may be of use to ServiceMix, but
> > > unfortunately I don't have time to integrate it myself - so I'm going
> to
> > > throw it out there for everyone :-)
> > >
> > > I started a project called SXC - simple xml compiler - which creates
> > > optimized xml parsers for various things. There is one for JAXB. But,
> > the
> > > one of probably the most interest to this crew is the XPath frontend.
> > SXC
> > > can build a streaming xpath parser for you (at runtime). This means
> you
> > can
> > > listen for XPath events as you scan over the document. This allows for
> > very
> > > efficient XPath based routing. In my initial performance test it was
> > about
> > > 100x faster than Jaxen for locating nodes (although thats a very rough
> > > benchmark, real numbers may vary!)
> > >
> > > We also integrated it with Drools so you can write XPath expressions
> > right
> > > in your rules.
> > >
> > > Check out these links for more information:
> > >
> > > http://sxc.codehaus.org
> > > http://sxc.codehaus.org/XPath
> > > http://sxc.codehaus.org/Drools
> > >
> > > The one caveat is that we support only a limited subset of XPath
> > expressions
> > > at the moment. But if you wanted to hack SXC, its easy enough to add
> > more.
> > > I'm happy to help where I can or give guidance to anyone who wants to
> > > participate as well.
> > >
> > > Anyone up for hacking it into servicemix? :-)
> > >
> > > - Dan
> > >
> > > --
> > > Dan Diephouse
> > > Envoi Solutions
> > > http://envoisolutions.com | http://netzooid.com/blog
> > >
> >
>
>
>
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Architect, LogicBlaze (http://www.logicblaze.com/)
> Blog: http://gnodet.blogspot.com/
>



-- 
Dan Diephouse
Envoi Solutions
http://envoisolutions.com | http://netzooid.com/blog

Re: XPath and Drools routing with SXC?

Posted by Guillaume Nodet <gn...@gmail.com>.
Yeah, both Drools SE and the EIP Xpath router could benefit
such a library.  Thanks a lot, Dan !
However this won't avoid parsing the xml to a DOM because we
will still have to send it to the destination after the xpath routing
has been performed.  But I think this could still boost performances
a lot.
  Does it support evaluating multiple xpath expression at the same time ?
I.e. you give all the xpath expressions, and they are all evaluated at the
same time, so that the first one matching will be fired .... Need to
look at SXC a bit more ...

On 3/17/07, Grant M <cl...@gmail.com> wrote:
>
> Were you thinking of integrating it with EIP routing? That could
> possibly be done.
>
> On 3/17/07, Dan Diephouse <da...@envoisolutions.com> wrote:
> > Hi All,
> >
> > I think I wrote something which may be of use to ServiceMix, but
> > unfortunately I don't have time to integrate it myself - so I'm going to
> > throw it out there for everyone :-)
> >
> > I started a project called SXC - simple xml compiler - which creates
> > optimized xml parsers for various things. There is one for JAXB. But,
> the
> > one of probably the most interest to this crew is the XPath frontend.
> SXC
> > can build a streaming xpath parser for you (at runtime). This means you
> can
> > listen for XPath events as you scan over the document. This allows for
> very
> > efficient XPath based routing. In my initial performance test it was
> about
> > 100x faster than Jaxen for locating nodes (although thats a very rough
> > benchmark, real numbers may vary!)
> >
> > We also integrated it with Drools so you can write XPath expressions
> right
> > in your rules.
> >
> > Check out these links for more information:
> >
> > http://sxc.codehaus.org
> > http://sxc.codehaus.org/XPath
> > http://sxc.codehaus.org/Drools
> >
> > The one caveat is that we support only a limited subset of XPath
> expressions
> > at the moment. But if you wanted to hack SXC, its easy enough to add
> more.
> > I'm happy to help where I can or give guidance to anyone who wants to
> > participate as well.
> >
> > Anyone up for hacking it into servicemix? :-)
> >
> > - Dan
> >
> > --
> > Dan Diephouse
> > Envoi Solutions
> > http://envoisolutions.com | http://netzooid.com/blog
> >
>



-- 
Cheers,
Guillaume Nodet
------------------------
Architect, LogicBlaze (http://www.logicblaze.com/)
Blog: http://gnodet.blogspot.com/

Re: XPath and Drools routing with SXC?

Posted by Grant M <cl...@gmail.com>.
Were you thinking of integrating it with EIP routing? That could
possibly be done.

On 3/17/07, Dan Diephouse <da...@envoisolutions.com> wrote:
> Hi All,
>
> I think I wrote something which may be of use to ServiceMix, but
> unfortunately I don't have time to integrate it myself - so I'm going to
> throw it out there for everyone :-)
>
> I started a project called SXC - simple xml compiler - which creates
> optimized xml parsers for various things. There is one for JAXB. But, the
> one of probably the most interest to this crew is the XPath frontend. SXC
> can build a streaming xpath parser for you (at runtime). This means you can
> listen for XPath events as you scan over the document. This allows for very
> efficient XPath based routing. In my initial performance test it was about
> 100x faster than Jaxen for locating nodes (although thats a very rough
> benchmark, real numbers may vary!)
>
> We also integrated it with Drools so you can write XPath expressions right
> in your rules.
>
> Check out these links for more information:
>
> http://sxc.codehaus.org
> http://sxc.codehaus.org/XPath
> http://sxc.codehaus.org/Drools
>
> The one caveat is that we support only a limited subset of XPath expressions
> at the moment. But if you wanted to hack SXC, its easy enough to add more.
> I'm happy to help where I can or give guidance to anyone who wants to
> participate as well.
>
> Anyone up for hacking it into servicemix? :-)
>
> - Dan
>
> --
> Dan Diephouse
> Envoi Solutions
> http://envoisolutions.com | http://netzooid.com/blog
>