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.
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.
Understand the problematic
Let's suppose you want to know where lives a person.
You have two services that can help you in this task.
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:
- Message from the chaining service to a first service.
- Response from the first service to the chaining service (we assume the first service works in InOut message exchange pattern).
- Message from the chaining service to the XSLT service.
- Response from the XSLT service to the chaining service (the MEP is InOut, always).
- Message from the chaining service to a second service. The transformed message is sent to it.
- Optional response, depending on the MEP for the second service.
This chaining service can be implemented by a POJO (a Java service that runs in Petals) 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
Configurations for this component cannot be used as a proxy to call other services.
Neither to transform attachments, nor to intercept messages on the fly.
Interceptors would better fit this kind of use case.
The transformed content is always the payload from the input message.
And a chaining service is always required.
XSLT configurations and WSDL interfaces
Configurations (service-units) for the XSLT component do not have, in general, a WSDL interface.
However, it is possible to define one. This WSDL must define two operations, being transform and transformToAttachment.
These two operations are the ones the component supports. The associated name space (WSDL operation names are QNames) depends on the version of the component.
For the versions 2.3 of the XSLT component, this name space is http://petals.ow2.org/components/xslt/version-2
When calling transform, the transformed message is returned as the message payload.
When calling transformToAttachment, the transformed message is attached to the response.
In this second case, the payload is
<attached-files>
<file-name>myOutputAttachmentName</file-name>
<attached-files>
The input and output messages for these operations is related to the XSL style sheet.
In fact, the input message should be the output message of the previous service (the one whose output must be transformed).
And the output message depends on the operation.
For the transform operation, it should be the input message of the next service to be called.
For the other operation, it is almost the same every time, since it is an attachment.
Obviously, each time it is written service, it means service operation. Because you cannot chain calls to services, but only chain calls to service operations.
| The XSLT component supports only the InOut message exchange pattern. |
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.
Thus, beginning by creating a WSDL, and then continuing by the XSL style sheet appears as the best practice to have.
Component configuration
The component can be configured through its JBI descriptor file, as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<?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">
<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.XsltComponent</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:ignored-status>DONE_AND_ERROR_IGNORED</petalsCDK:ignored-status>
<petalsCDK:notifications>false</petalsCDK:notifications>
<petalsCDK:jbi-listener-class-name>org.ow2.petals.se.xslt.listener.JBIListener</petalsCDK:jbi-listener-class-name>
</component>
</jbi>
The component configuration includes the configuration of the CDK. The following parameters correspond to the CDK configuration.
Unable to render {include} Couldn't find a page to include called: 0 CDK Component Configuration Table
This component does not have any specific configuration parameter.
| The Petals-SE-XSLT component can only handle messages coming from inside the bus. Therefore, you cannot specify an external-listener class-name. |
Service Configuration
Service Unit descriptor
The Service Unit descriptor file ( jbi.xml ) looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!--
JBI descriptor for the Petals' "petals-se-xslt" component (XSLT).
Originally created for the version 2.3 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">
use a BC. -->
<jbi:services binding-component="false">
provides a Service. -->
<jbi:provides
interface-name="generatedNs:XsltInterface"
service-name="generatedNs:PersonLocalizer"
endpoint-name="PersonLocalizerEndpoint">
<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>
<xslt:stylesheet>fromTo.xsl</xslt:stylesheet>
<xslt:output-attachment-name>TransformedMessage</xslt:output-attachment-name>
</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 expose an XSLT-transformation service into Petals ESB :
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 operation transformToAttachment is invoked |
- |
No |
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 |
Unable to render {include} Couldn't find a page to include called: 0 CDK Interceptor configuration for SU
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:
|