Its often a requirement to perform content based routing in an ESB. This means you route messages around your service bus based on the message properties or the content of the messages. When integrating systems across language boundaries its common to use XML as a universal message format; so XPath is an ideal tool to perform content based routing and transformation.

We support a XPath based routing and transformation mechanism designed for high performance and power.

Example

The following is an example routing and transformation template. Firstly we reuse the XSLT basd transform component.

{snippet:id=xslt|lang=xml|url=servicemix/smx3/trunk/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/router-example.xml}

 

Then we provide a file in XSLT format, with some JBI extensions

{snippet:id=route|lang=xml|url=servicemix/smx3/trunk/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/router.xsl}

 

In the above example, depending on the value of the @id attribute, we invoke different services.

Notice that we declare the jbi namespace and some attributes on the root XSLT stylesheet element. We then have the following extension elements available to the XSTL

Xalan extension summary

The following new XML tags are available in Xalan when working with ServiceMix

Element

Description

forward

will forward the current inbound message to the given service, interface and/or operation. This mechanism will use the properties and content of the inbound message to create the outbound message

invoke

will perform a one way service invocation where the body of the invoke tag represents the XML content of the message. Notice from the above we can use XPath expressions to create the XML

Invoking multiple service endpoints

The following example shows a number of services being invoked one after the other, using optionally different properties. In each case the original XML message is used as the body of the new inbound request.

{snippet:id=route|lang=xml|url=servicemix/smx3/trunk/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/publish.xsl}

 

Splitting up an XML message into multiple service invocations

This example demonstrates a message being split into multiple different sections of XML which are then invoked on different services.

{snippet:id=example|lang=xml|url=servicemix/smx3/trunk/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/split.xsl}

 

Why use Xalan?

We use Xalan to implement our XPath based router and transformation engine. The main reasons for doing so are

  • we typically need to evaluate many XPath expressions on a single message exchange; so we can create them all inside the stylesheet such that they are evaluated efficiently each time.
  • Xalan can turn the stylesheet into bytecode, which we can then cache/pool to ensure the routing and transformations are as fast as possible while still using the power and flexiblity of XPath.
  • Xalan is optimised to only parse what is required of a document to satisfy the template
  • No labels