Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

ServiceMix Saxon

The servicemix-saxon ServiceMix Saxon component is a standard JBI Service Engine for XSLT / XQuery. This component is based on Saxon and supports XSLT 2.0 and XPath 2.0, and XQuery 1.0.

Warning
titleUse of result property

Due to a bug in the latest release of Saxon, the dom value of the result attribute causes exceptions to be thrown. Hence, the default value has been changed to string to avoid problems.

...

This bug only affects the XSLT endpoint, so feel free to use the dom value for XQuery endpoints.

Maven Archetype

You can use Maven servicemix-saxon

...

Installation

Installing the servicemix-saxon component can be done in several ways:

  • drop the installer zip in an hotdeploy directory monitored by ServiceMix
  • using ant tasks

Note that when using ant tasks, the component is not started, you will have to start it manually using ant tasks or a console.

Service Unit packaging

A service unit will typically consist in:

  • an xbean.xml configuration file
  • the associated xslt / xquery document

Content of xbean.xml file to be packaged as a SU

...


<beans xmlns:saxon="http://servicemix.apache.org/saxon/1.0">

  ... add endpoints here ...

</beans>

-service-unit archetype to create a Saxon service unit:

Code Block

mvn archetype:create \
  -DarchetypeGroupId=org.apache.servicemix.tooling \
  -DarchetypeArtifactId=servicemix-saxon-service-unit \
  -DarchetypeVersion=2010.01 \
  -DgroupId=your.group.id \
  -DartifactId=your.artifact.id \
  -Dversion=your-version

Endpoints Configuration

XSLT Endpoint

The XSLT endpoint can be used to apply an XSLT stylesheet to the incoming exchange and will return the transformed result as the output message.

Simple transformation:

Code Block
langxml

<saxon:xslt service="test:xslt" endpoint="endpoint"
            resource="classpath:transform.xsl" />

Dynamic stylesheet selection:

Code Block
langxml

<saxon:xslt service="test:xslt-dynamic" endpoint="endpoint">
  <saxon:expression>
    <bean class="org.apache.servicemix.expression.PropertyExpression">
      <property name="property" value="xslt.source" />
    </bean>
  </saxon:expression>
</saxon:xslt>
Info
titleEndpoint attributes
borderStylesolidbgColor='lighblue'

Name

Type

Description

Required

resource

Spring resource

the spring resource pointing to the XSLT stylesheet

one of (resource, expression)

expression

ServiceMix expression

expression used to dynamically load the stylesheet

one of (resource, expression)

wsdlResource

Spring resource

if set, the wsdl will be retrieved from the given Spring resource

no

transformerFactory

TransformerFactory

TraX factory to create transformers

defaults to Saxon implementation

configuration

Saxon configuration

Saxon configuration

no

result

String

Output result type

defaults to dom, possible values are dom, bytes, string

copyAttachments

boolean

 

defaults to true

copyProperties

boolean

 

defaults to true

copySubject

boolean

 

defaults to true

useDomSourceForXslt

boolean

force the transformation of the xslt stylesheet into a DOM document before giving it to the transformer

defaults to true

useDomSourceForContent

boolean

force the transformation of the incoming JBI message into a DOM document before giving it to the transformer

no

parameters

Map

additional parameters to give to the transformation engine

no

Using properties and parameters

All properties defined on the JBI exchange and input JBI message will be available for use inside the XSLT stylesheet as parameters.
In addtion to those properties and the one specified in the parameters property on the endpoint, the following objects are also available:

  • exchange: the JBI exchange
  • in: the input JBI NormalizedMessage
  • component: the XsltEndpoint instance being called

All those parameters can be accessed using XSLT standard ways.
For example:

Code Block
langxml

<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
  <xsl:param name="stringParam"/>
  <xsl:param name="integerParam"/>
  ...
</xsl:stylesheet>

and the configuration of those values on the endpoint (in case they are not available on the JBI exchange / message):

Code Block
langxml

<saxon:xslt service="test:xslt-params" endpoint="endpoint"
    

Using servicemix-saxon in a ServiceMix xml configuration file

Code Block
xmlxml

<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
       xmlns:saxon="http://servicemix.apache.org/saxon/1.0">

  <sm:container ...>
    <sm:activationSpecs>
      <sm:activationSpec>
        <sm:component>resource="classpath:parameter-test.xsl">
  <property name="parameters">
       <saxon:component><map>
      <entry      <saxon:endpoints>
key="stringParam" value="cheeseyCheese"/>
      <entry key="integerParam">
       ... add saxon endpoints here ...

<bean class="java.lang.Integer">
          <constructor-arg  </saxon:endpoints>index="0" value="4002"/>
          </saxon:component>bean>
        </sm:component>entry>
      </sm:activationSpec>map>
      ...
    </sm:activationSpecs>property>
  </sm:container>
  ...

</beans>saxon:xslt>

XSLT

...

Proxy

One common use case is the need to transform a request coming from a service and send it to another service and do the same with the response. A simple example is the need to translate the request and responses between two SOAP endpoints. Such a use case could be implemented using two XSLT endpoints and an EIP StaticRoutingSlip. However, there are some drawbacks, as the operation is lost in the process, and a static routing slip can not be used to process InOnly exchanges.

The XSLT endpoint can be used to apply an XSLT stylesheet to the incoming exchange and will return the transformed result as the output message.

Simple transformation:

Code Block
langxml
<saxon:xsltproxy service="test:xsltproxy" endpoint="endpoint"
             resource="classpath:transform-in.xsl" />

Dynamic stylesheet selection:

Code Block
langxml

<saxon:xslt service="test:xslt-dynamic" endpoint="endpoint">
  <saxon:expression>

             outResource="classpath:transform-out.xsl"
            <bean classfaultResource="org.apache.servicemix.expression.PropertyExpressionclasspath:transform-fault.xsl">
  <saxon:target>
    <property name="property" value="xslt.source"<saxon:exchange-target service="test:echo" />
    </bean>
  </saxon:expression>target>
</saxon:xslt>proxy>
Info
titleEndpoint attributesAttributes
borderStylesolidbgColor='lighblue'

Name

Type

Description

Required

resource

Spring resource

the spring resource pointing to the XSLT stylesheet used to transform the input message

no

outResource

Spring resource

the spring resource pointing to the XSLT stylesheet used to transform the output message

no

faultResource

Spring resource

the spring resource pointing to the XSLT stylesheet used to transform the fault message

no one of (resource, expression)

expression

ServiceMix expression

expression used to dynamically load the stylesheet. If set, it will prevail against all resource, outResource and faultResource attributes

no one of (resource, expression)

wsdlResource

Spring resource

if set, the wsdl will be retrieved from the given Spring resource

no

transformerFactory

TransformerFactory

TraX factory to create transformers

defaults to Saxon implementation

configuration

Saxon configuration

Saxon configuration

no

result

String

Output result type

defaults to dom, possible values are dom, bytes, string

copyAttachments

boolean

 

defaults to true

copyProperties

boolean

 

defaults to true

copySubject

boolean

 

defaults to true

target

...

ExchangeTarget

the destination where the transformed exchange will be sent to

yes

XQuery Endpoint

The XQuery endpoint can be used to apply a selected XQuery to the input document.

...