Petals-SE-XSLT 2.4

Features

The XSLT Service-Engine allows to transform Petals messages using XSL style sheets.

Each configuration of this component embeds an XSL style sheet.
When such a configuration (i.e. service, i.e. service-unit) is called, it transforms the received message into another one.
The XML payload of the input message is transformed using the XSL style sheet.
The resulting XML document is then returned in the response, either as the payload, or as an attachment.

This component only acts as service provider, not as a service consumer.
In fact, it provides a transformation service.

Additional information about XSLT can be found at http://www.w3.org/TR/xslt.

XSLT Component overview
Contributors
No contributors found for: authors on selected page(s)

Recommended usage

The XSLT component should be used when chaining calls to services whose output and input do not match.
It can also be used to expose XSL transformations as a service, provided that the content to transform is passed in the message payload, and not as attachment.

Taking an example

Let's take the example of two "white pages" services.
These services aims at helping in finding where a person lives (or how to contact this person).

First, you want to call the operation lookup of a service "White Pages".
This operation takes the first name and the family name of a person, and returns a list of phone numbers.
Each phone number is given as a string.

Its prototype looks like

lookup( String firstName, String familyName ) --> String[] phoneNumbers

Do not forget this prototype would be in fact described in the WSDL interface of the service (under an XML shape).

Then, you want to call a service that finds a geographical area (e.g. a city) from a phone prefix.
It is the operation resolve from a service "PrefixToAreaLocalizer".
From a phone prefix, it returns a geographical area.

Its prototype looks like

resolve( int phonePrefix ) --> String areaName

Once again, this prototype is described in the WSDL interface of this second service.

To chain these calls, you have to transform the output of the operation lookup to match the input of the operation resolve.
Indeed, you cannot directly execute

resolve( lookup( "Pierre", "Paul"));

What you will do in your XSL style sheet is extracting the phone prefix from a phone number.
The list go-through will most likely not be made in the XSLT transformation.

There is no more simple way to make the transformation.
In Petals, as well as in most of SOA-related technologies, messages are XML messages.
And for every service, the operations, with their in and out parameters, are described in their WSDL interface.
So, the output message of the resolve operation is an XML (SOAP) message, and the input message of resolve operation is an XML message too.
These XML messages must match the WSDL descriptions of these services.

Obviously, this example is extremely simple.
But the usage remains the same, even with complex XML structures.

XSLT and chaining services

Following our previous example, it appears that chaining and transforming service calls implies using a chaining service (some could say an orchestration service).
This chaining service would do the following calls:

  1. Message from the chaining service to a first service.
  2. Response from the first service to the chaining service (we assume the first service works in InOut message exchange pattern).
  3. Message from the chaining service to the XSLT service.
  4. Response from the XSLT service to the chaining service (the MEP is InOut, always).
  5. Message from the chaining service to a second service. The transformed message is sent to it.
  6. Optional response, depending on the MEP for the second service.

This chaining service can be implemented by a POJO (an home made Java Class) or an Enterprise Integration Pattern (EIP).
It could also be implemented by a BPEL process, but in fact, that would not be a great idea.
BPEL supports the extraction of data from XML messages during the orchestration. When you have a BPEL process, you do not need XSLT. You can use XPath expressions and functions directly in the BPEL. Besides, working with BPEL would require the XSLT configuration to have a WSDL interface while they do not always have one.

Limitations and warnings

The transformed content is always the payload from the input message.
Do not mistake XSLT services for interceptors.

A XSL transformation service cannot transform messages addressed to another service.
Neither to transform attachments, nor to intercept messages on the fly. An orchestration service is required to make the link.
Interceptors would better fit this kind of use case.

To work with XSL style sheets of more than 1000 lines, you have to use another engine than the default one shipped with Java (Xalan 2.6.0 for Java 6 for Petals <5 and Xalan 2.7.0 for Java 7 for Petals >5).

This is due to a bug of Xalan of versions previous than 2.7.1. To bypass it, you have to use a newer version of Xalan (2.7.1 +) or another XSLT engine using a Shared-Library.
Note that for version 2.5 up to 2.7, Saxon is the default engine, so the problem does not arise.

Creating a XSL Transformation service (Provides modes)

Each XSLT service runs on the Petals XSLT component.
The Petals XSLT component has native operations to invoke. These operations are inherited by the XSLT services.
A XSLT service cannot add additional operations. It only has the ones of the XSLT component.

The version 2.4 of the Petals XSLT component exposes two operations.

  • transform: the received message is transformed with the XSL style sheet. The transformation result is returned as the response payload.
  • transformToMtomAttachment: the received message is transformed with the XSL style sheet. The transformation result is attached to the response in MTOM mode.

The "transform" operation

The fully qualified name of this operation is:

  • Name space URI: any URI, provided it is not null (e.g. *http://petals.ow2.org/components/xslt/version-2*)
  • Local part: transform

This operation only supports the InOut message exchange pattern (MEP).
When invoking this operation, you must call it using its fully qualified name.
It must also be the operation name in the WSDL of any XSLT service.

Here is the execution flow for this operation:

  1. The received message is transformed with the XSL style sheet.
  2. The transformation result is returned as the response payload.

The result of the transformation depends on the XSL style sheet.

If an error occurs during the transformation, then a fault is raised.

<?xml version="1.0" encoding="UTF-8"?>
<xsltFault xmlns="the name space of the invoked operation">
    <message>An error message</message>
    <details>A stack trace (optional)</details>
</xsltFault>

The "transformToMtomAttachment" operation

The fully qualified name of this operation is:

  • Name space URI: any URI, provided it is not null (e.g. *http://petals.ow2.org/components/xslt/version-2*)
  • Local part: transformToMtomAttachment

This operation only supports the InOut message exchange pattern (MEP).
When invoking this operation, you must call it using its fully qualified name.
This operation cannot be described in a WSDL, because of the result it returns.

Here is the execution flow for this operation:

  1. The received message is transformed with the XSL style sheet.
  2. The transformation result is attached to the response in MTOM mode.

The attachment is not sent in MTOM mode.
The result of the transformation has always the same shape.

<<attachedTransformResponse xmlns="..." xmlns:xop="http://www.w3.org/2004/08/xop/include">
    <fileContent>
        <xop:include href="cid:attachmentName" />
    </fileContent>
<<attachedTransformResponse>

... where attachmentName is the name of the attachment (as specified in the service-unit, or a default value otherwise).

If an error occurs during the transformation, then a fault is raised.

<?xml version="1.0" encoding="UTF-8"?>
<xsltFault xmlns="the name space of the invoked operation">
    <message>An error message</message>
    <details>A stack trace (optional)</details>
</xsltFault>

XSL parameters

XSL style sheets supports the definition of parameters.
These parameters can be passed dynamically when executing it.

You can find additional information about it on these web sites:

The Petals XSLT component allows you to set XSL parameters in two different ways:

  • The first one is a static definition in the jbi.xml.
    • It allows you to reuse a same XSL style sheet in several services.
    • Take a look at the jbi.xml's parameters for more information.
  • The second way is by setting them at runtime, in the message properties.
    • Please, understand that this is not the message payload that defines the parameter values.
    • It is the properties of the incoming Petals service (called an exchange). For more details, see Exchange#setInMessageProperty( String, Object ).

Static parameter values may be overriden by dynamic ones.
But only if the static values were defines as overridable.
Trying to override a parameter value that is not overridable will result in a fault.


Remember, XSL parameters are declared with a param element in the XSL style-sheet.
A XSL parameter can be global (declared as a root element) or local (declared inside a template).
The value of a XSL parameter can be retrieved with $parameter_name or {$parameter_name}, depending on the parameter usage.

WSDL definitions

Configurations (service-units) for the XSLT component do not have, in general, a WSDL definition.
However, it is possible to define one which describes the transform and "transformToMtomAttachment" operations.

The input and output messages for the transform operation are related to the XSL style sheet.
In fact, the input message should be the output message of the previous chained service (the one whose output must be transformed).
And the output message should be the input message of the next chained service.

The input message for the transformToMtomAttachment operation is related to the XSL style sheet.
In fact, the input message should be the output message of the previous chained service (the one whose output must be transformed). The WSDL message should reference a XML element of the same type than the input message of the transform operation.
And the output message should describe the MTOM structure that was documented above. In this structure, fileContent is a base64Binary element and the xop:include element does not appear.

As said at the beginning of this section, WSDL are not mandatory though. Typically, integration use cases do not require one. But not having one is bad practice in SOA.
Your XSLT service is then not reusable, and no one else will ever use it unless you give him the XSL style sheet to determine the expected input and output.

Beginning by creating a WSDL, and then continuing by the XSL style sheet appears as the best practice to have.

JBI descriptor

The Service-Unit descriptor file ( jbi.xml ) looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!--
	JBI descriptor for the Petals' "petals-se-xslt" component (XSLT).
	Originally created for the version 2.4 of the component.
 -->
<jbi:jbi version="1.0"
	xmlns:generatedNs="http://petals.ow2.org/components/xslt/version-2"
	xmlns:jbi="http://java.sun.com/xml/ns/jbi"
	xmlns:petalsCDK="http://petals.ow2.org/components/extensions/version-5"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:xslt="http://petals.ow2.org/components/xslt/version-2">

	<!-- Import a Service into Petals or Expose a Petals Service => use a BC. -->
	<jbi:services binding-component="false">

		<!-- Import a Service into Petals => provides a Service. -->
		<jbi:provides
			interface-name="generatedNs:XsltInterface"
			service-name="generatedNs:Test"
			endpoint-name="TestEndpoint">

			<!-- CDK specific elements -->
			<petalsCDK:timeout>30000</petalsCDK:timeout>
			<petalsCDK:validate-wsdl>true</petalsCDK:validate-wsdl>
			<petalsCDK:forward-security-subject>false</petalsCDK:forward-security-subject>
			<petalsCDK:forward-message-properties>false</petalsCDK:forward-message-properties>
			<petalsCDK:forward-attachments>false</petalsCDK:forward-attachments>
			<petalsCDK:wsdl>XsltService.wsdl</petalsCDK:wsdl>

			<!-- Component specific elements -->
			<xslt:stylesheet>transformation.xsl</xslt:stylesheet>

			<!-- XSL parameters -->
			<generatedNs:xsl-parameters>
				<generatedNs:xsl-parameter name="street" overridable="true">
					17, rue du Parc
				</generatedNs:xsl-parameter>
				<generatedNs:xsl-parameter name="city" overridable="false">
					Grenoble
				</generatedNs:xsl-parameter>
			</generatedNs:xsl-parameters>
		</jbi:provides>
	</jbi:services>
</jbi:jbi>

A JBI descriptor for an XSLT service-unit can only define one provides block.

Configuration of a Service Unit to provide a service (JBI)

Parameter Description
Default
Required
provides Describe the JBI service that will be exposed into the JBI bus. Interface (QName), Service (QName) and Endpoint (String) attributes are required. - Yes

Configuration of a Service Unit to provide a service (CDK)

Parameter Description
Default
Required
timeout Timeout in milliseconds of a synchronous send. This parameter is used by the method sendSync (Exchange exchange) proposes by the CDK Listeners classes.
Set it to 0 for an infinite timeout.
30000 No
exchange-properties This sections defines the list of properties to set to the JBI exchange when processing a service. - No
message-properties This sections defines the list of properties to set to the JBI message when processing a service. - No
validate-wsdl Activate the validation of the WSDL when deploying a service unit. true No
wsdl
Path to the WSDL document describing services and operations exposed by the provided JBI endpoints defined in the SU.
The value of this parameter is :
  • an URL
  • a file relative to the root of the SU package
    If not specified, a basic WSDL description is automaticaly provided by the CDK.
- No
forward-attachments
Defines if attachment will be forwarded from IN message to OUT message.
false No
forward-message-properties
Defines if the message properties will be forwarded from IN message to OUT message. false No
forward-security-subject
Defines if the security subject will be forwarded from IN message to OUT message. false No


Configuration of a Service Unit to provide a service (XSLT)

Parameter Description Default Required
stylesheet The relative file path of the XSL style sheet in the service-unit
-
Yes
output-attachment-name The attachment name to use when the transformToMtomAttachment operations is invoked
-
No
xsl-parameters A list of xsl-parameter elements
-
No

A xsl-parameter element has the following structure:

<xs:complexType name="XslParameter">
	<xs:simpleContent>
		<xs:extension base="xs:string">
			<xs:attribute name="name" type="xs:string" />
			<xs:attribute name="overridable" type="xs:boolean" default="false" />
		</xs:extension>
	</xs:simpleContent>
</xs:complexType>
  • Its value is a text.
  • The name attribute must match the name of a XSL parameter.
  • The overridable attribute defines whether this static value can be overriden by a dynamic value (from an incoming message).

Interceptor

Example of an interceptor configuration:

<?xml version="1.0" encoding="UTF-8"?>
<!--...-->
<petalsCDK:su-interceptors>
  <petalsCDK:send>
    <petalsCDK:interceptor name="myInterceptorName">
      <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
      <petalsCDK:param name="myParamName2">myParamValue2</petalsCDK:param>
    </petalsCDK:interceptor>
  </petalsCDK:send>
  <petalsCDK:accept>
    <petalsCDK:interceptor name="myInterceptorName">
      <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
    </petalsCDK:interceptor>
  </petalsCDK:accept>
  <petalsCDK:send-response>
    <petalsCDK:Interceptor name="myInterceptorName">
      <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
    </petalsCDK:Interceptor>
  </petalsCDK:send-response>
  <petalsCDK:accept-response>
    <petalsCDK:Interceptor name="myInterceptorName">
      <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
    </petalsCDK:Interceptor>
  </petalsCDK:accept-response>
</petalsCDK:su-interceptors>
<!--...-->

Interceptors configuration for SU (CDK)

Parameter Description Default Required
send Interceptor dedicated to send phase, for an exchange sent by a consumer - No
accept Interceptor dedicated to receive phase, for an exchange received by a provider - No
send-response Interceptor dedicated to send phase, for an exchange (a response) received by a consumer - No
accept-response Interceptor dedicated to receive phase, for an exchange sent (a response) by a provider - No
interceptor - name Logical name of the interceptor instance. It can be referenced to add extended parameters by a SU Interceptor configuration. - Yes
param[] - name The name of the parameter to use for the interceptor for this SU - No
param[] The value of the parameter to use for the interceptor for this SU - No

Service-Unit content

The service unit must contain the XSL style sheet.
It is also highly recommended to provide a WSDL description for this service.
This WSDL is not mandatory, but not providing it will prevent your service from interacting with other Petals services and components.

The archive may also embed a JAR containing the custom functions referenced in the XSL style sheet, if any.

The directory structure of a SU for the Petals-SE-XSLT looks like this:

su-xslt-TransformationName-provide.zip
   + META-INF
     - jbi.xml
   + XsltService.wsdl (recommended)
   + <XSL style sheet>.xsl
   + customFunctions.jar (optional)

Configuring the component

The component can be configured through its JBI descriptor file, as shown below.

<?xml version="1.0" encoding="UTF-8"?>
<jbi
	version="1.0"
	xmlns='http://java.sun.com/xml/ns/jbi'
	xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
	xmlns:petalsCDK="http://petals.ow2.org/components/extensions/version-5"
	xmlns:xslt="http://petals.ow2.org/components/xslt/version-2">

	<component type="service-engine">
		<identification>
			<name>petals-se-xslt</name>
			<description>A Xslt Service Engine</description>
		</identification>

		<component-class-name description="Xslt Component class">org.ow2.petals.se.xslt.XsltSe</component-class-name>
		<component-class-path><path-element/></component-class-path>
		<bootstrap-class-name>org.ow2.petals.component.framework.DefaultBootstrap</bootstrap-class-name>
		<bootstrap-class-path><path-element/></bootstrap-class-path>

		<petalsCDK:acceptor-pool-size>3</petalsCDK:acceptor-pool-size>
		<petalsCDK:processor-pool-size>10</petalsCDK:processor-pool-size>
		<petalsCDK:processor-max-pool-size>50</petalsCDK:processor-max-pool-size>
		<petalsCDK:ignored-status>DONE_AND_ERROR_IGNORED</petalsCDK:ignored-status>
		<petalsCDK:properties-file></petalsCDK:properties-file>
		<petalsCDK:notifications>false</petalsCDK:notifications>
		<petalsCDK:jbi-listener-class-name>org.ow2.petals.se.xslt.XsltJBIListener</petalsCDK:jbi-listener-class-name>
	</component>
</jbi>

The component configuration includes the configuration of the CDK. The following parameters correspond to the CDK configuration.

Configuration of the component (CDK)

Parameter Description Default Required Required
acceptor-pool-size The size of the thread pool used to accept Message Exchanges from the NMR. Once a message is accepted, its processing is delegated to the processor pool thread. 3 Yes Runtime
processor-pool-size The size of the thread pool used to process Message Exchanges. Once a message is accepted, its processing is delegated to one of the thread of this pool. 10 Yes Runtime
processor-max-pool-size The maximum size of the thread pool used to process Message Exchanges. The difference between this size and the processorpool-size represents the dynamic threads that can be created and destroyed during overhead processing time. 50 No Runtime
notifications Enable the EDA mode. The component produces and consumes notifications. See the EDA documentation for further details. false No Installation
properties-file Name of the file containing properties used as reference by other parameters. Parameters reference the property name in the following pattern ${myPropertyName}. At runtime, the expression is replaced by the value of the property.
The value of this parameter is:
  • an URL
  • a file relative to the PEtALS installation path
  • an empty value to stipulate a non-using file
- No Installation

Definition of CDK parameter scope :

  • Installation: The parameter can be set during the installation of the component, by using the installation MBean (see JBI specifications for details about the installation sequence). If the parameter is optional and has not been defined during the development of the component, it is not available at installation time.
  • Runtime: The paramater can be set during the installation of the component and during runtime. The runtime configuration can be changed using the CDK custom MBean named RuntimeConfiguration. If the parameter is optional and has not been defined during the development of the component, it is not available at installation and runtime times.

Interceptor

Interceptors can be defined to inject some post or pre processing in the component during service processing.

Using interceptor is very sensitive and must be manipulate only by power users. An non properly coded interceptor engaged in a component can lead to uncontrolled behaviors, out of the standard process.

Example of an interceptor configuration:

<?xml version="1.0" encoding="UTF-8"?>
<!--...-->
<petalsCDK:component-interceptors>
  <petalsCDK:interceptor active="true" class="org.ow2.petals.myInterceptor" name="myInterceptorName">
    <petalsCDK:param name="myParamName">myParamValue</petalsCDK:param>
    <petalsCDK:param name="myParamName2">myParamValue2</petalsCDK:param>
  </petalsCDK:interceptor>
</petalsCDK:component-interceptors>
<!--...-->

Interceptors configuration for Component (CDK)

Parameter Description Default Required
interceptor - class Name of the interceptor class to implement. This class must extend the abstract class org.ow2.petals.component.common.interceptor.Interceptor. This class must be loadable from the component classloader, or in a dependent Shared Library classloader. - Yes
interceptor - name Logical name of the interceptor instance. It can be referenced to add extended parameters by a SU Interceptor configuration. - Yes
interceptor - active If true, the Interceptor instance is activated for every SU deployed on the component.
If false, the Interceptor can be activated:
-by the InterceptorManager Mbean at runtime, to activate the interceptor for every deployed SU.
-by a SU configuration
- Yes
param[] - name The name of the parameter to use for the interceptor. - No
param[] The value of the parameter to use for the interceptor. - No

This component does not have any specific configuration parameter.

Labels

components-se-family components-se-family Delete
petals petals Delete
component component Delete
se se Delete
xslt xslt Delete
user user Delete
guide guide Delete
2-4 2-4 Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.