Skip navigation

User Guide

Table Of Contents


Introduction

This is the user guide for the Smooks for Mule module. The Smooks for Mule
module has two different versions. One for Mule 1.x and one for Mule 2.x. Both versions currently have almost the same features. That is why there is only one User guide.

Note that this user guide does not explain Smooks itself. The Smooks project has it's own User Guide for that. You can find it here.

Installation

There are installation packages for both the Mule 1.x and Mule 2.x versions of the Smooks for Mule module. Go to the Download page to download the package for the Mule version that you need. Take a look at the README.txt file for the installation instructions.

Configuration

The following sections explain the configuration options for the components. The configuration options for the Mule 1.x and Mule 2.x versions are the same.

For Mule 2.x the Smooks for Mule module provides a Mule configuration XML Schema. The namespace and schema location are as followed:
Namespace: http://www.muleforge.org/smooks/schema/mule-module-smooks/1.0
Schema location: http://dist.muleforge.org/smooks/schema/mule-module-smooks/1.0/mule-module-smooks.xsd

Note on XML Editors and schema validation

The mule core configuration schema on http://www.mulesource.org/schema/mule/core/2.0/mule.xsd is different from the one found in the mule-module-spring-config-2.0.1.jar. The one in the jar file is the correct one because the Configuration loader uses that one to validate the configuration. Because of these differences schema validating XML editors can report errors and give incorrect auto-completion when using the Smooks for Mule configuration schema. For instance when declaring multiple endpoints in the router.

This problem has been reported to the Mule Jira: MULE-3542.

Workaround
The workaround is to configure the XML editor to use the /META-INF/mule.xsd from the mule-module-spring-config-2.0.1.jar. Don't change the schemaLocation in the xml file! You should configure the editor to override that one with the jar version one.

In the Eclipse XML editor you do this by adding a XML Catalog entry with the following values:
Location: The path to the mule.xsd file (you probably need to unpack it out of the mule-module-spring-config-2.0.1.jar file)
Key type: Schema Location
Key: http://www.mulesource.org/schema/mule/core/2.0/mule.xsd

Transformer Configuration

Mule 1.x

The transformer is configured in your Mule Xml configuration file as follows:

mule-config.xml
<transformers>
    <transformer name="SmooksTransformer"  className="org.milyn.smooks.mule.Transformer">
            <properties>
                <property name="configFile" value="smooks-config.xml"/>
            </properties>
     </transformer>
</transformers>

And then specified for the inbound and/or outbound routers like this:

mule-config.xml
<inbound-router>
    <endpoint address="stdio://System.in" transformers="SmooksTransformer"/>
</inbound-router>

Mule 2.x

The transformer is configured in your Mule Xml configuration file as follows:

mule-config.xml
<smooks:transformer name="smooksTransformer" configFile="/transformer-smooks-config.xml" />

And then specified for the inbound and/or outbound routers like this:

mule-config.xml
<inbound>
    <vm:inbound-endpoint path="messageInput" transformer-refs="smooksTransformer"/>
</inbound>

Configuration Properties (Mule version independent)

Property Description
configFile The Smooks configuration file. Can be a path on the file system or on the classpath.
resultType Type of result expected from Smooks ("STRING", "BYTES", "JAVA", "RESULT", "NORESULT"). When setting the value to "JAVA" then you can set the "javaResultBeanId" attribute. When setting the value to "RESULT" then one of the "resultClass" or "resultFactoryClass" attributes must also be set. Default is "STRING".
javaResultBeanId The BeanId from which the Object is used as message payload if the resultType is set to "JAVA".
resultClass When the resultType is set to "RESULT" then this attribute defines the Result Class which will be used. The class must implement the "javax.xml.transform.Result" interface and must have an argumentless constructor.
resultFactoryClass When the resultType is set to "RESULT" then this attribute defines the ResultFactory Class which will be used to create the Result Class. The class must implement the "org.milyn.smooks.mule.ResultFactory" interface and must have an argumentless constructor.
profile The smooks profile to execute. If a profile name was found on the message then that one is used.
profileMessagePropertyKey The name of the message property which could contain a possible profile name. If the property is set and the value is a string then that value is used as the profile name. Default "MessageProfile".
executionContextAsMessageProperty If set to "true" then the attributes map of the Smooks execution context is added to the message properties. The property key is defined with the executionContextMessagePropertyKey property. Default is "false"
executionContextMessagePropertyKey The property key under which the execution context is put. Default is "SmooksExecutionContext"
excludeNonSerializables If non serializable attributes need to be execluded when setting the Smooks execution context attribute map as a message propeperty. Default is "true"
reportPath Specifies the path and file name for generating a Smooks Execution Report.  This is a development tool. For more information see: Smooks Reporting


Outbound Router Configuration

Mule 1.x

The router is configured in your Mule Xml configuration file as follows:

mule-config.xml
<outbound-router>
    <router className="org.milyn.smooks.mule.Router">
        <endpoint name="order" address="jms://order.queue"/>
        <endpoint name="order-important" address="jms://order.important.queue"/>
        <properties>
            <property name="configFile" value="/router-smooks-config.xml" />
        </properties>
    </router>
</outbound-router>

In the Smooks configuration you use the org.milyn.smooks.mule.MuleDispatcher to route to one of the endpoints you defined in the Mule configuration. More on the MuleDispatcher can be found in the Smooks MuleDispatcher section.

Mule 2.x

The router is configured in your Mule Xml configuration file as follows:

mule-config.xml
<outbound>
    <smooks:router configFile="/smooks-config.xml">
        <jms:outbound-endpoint name="order" queue="order.queue"/>
        <jms:outbound-endpoint name="order-important" queue="order.important.queue"/>
    </smooks:router>
</outbound>

In the Smooks configuration you use the org.milyn.smooks.mule.MuleDispatcher to route to one of the endpoints you defined in the Mule configuration. More on the MuleDispatcher can be found in the Smooks MuleDispatcher section.

Configuration Properties (Mule version independent)

Property Description
configFile The Smooks configuration file. Can be a path on the file system or on the classpath.
profile The smooks profile to execute. If a profile name was found on the message then that one is used.
profileMessagePropertyKey The name of the message property which could contain a possible profile name. If the property is set and the value is a string then that value is used as the profile name. Default "MessageProfile".
executionContextAsMessageProperty If set to "true" then the attributes map of the Smooks execution context is added to the message properties of every message that gets created by this router. The property key is defined with the executionContextMessagePropertyKey property. Default is "false"
executionContextMessagePropertyKey The property key under which the execution context is put. Default is "SmooksExecutionContext"
excludeNonSerializables If non serializable attributes need to be execluded when setting the Smooks execution context attribute map as a message propeperty. Default is "true"
honorSynchronicity If the synchronicity of the endpoint should override the general synchronicity settings
reportPath Specifies the path and file name for generating a Smooks Execution Report.  This is a development tool. For more information see: Smooks Reporting

Smooks MuleDispatcher

A MuleDispatcher is defined as follows:

smooks-config.xml
<resource-config selector="order">
    <resource>org.milyn.smooks.mule.MuleDispatcher</resource>
    <param name="endpointName">order</param>
    <param name="beanId">order</param>
</resource-config>
Property Description
endpointName The name of the endpoint which will be used when routing the message. If no endpoint can be found under that name then an exception is thrown.
expression A MVEL script. The result of the script is used as the message payload. This overrides the beanId property. The context of the MVEL script contains all the beans of the bean map.
beanId The bean id of the bean which will be used as the message payload.
resultBeanId If the endpoint returns a result then the payload of that result is bounded to the resultBeanId. When the resultBeanId isn't set then the result is discarded. If the resultBeanId is set then the endpoint is forced to distpatch synchronous.
messageProperties Properties that will be set on the message before dispatching. The MuleDispatcher messageProperties attribute section explains how to set the message properties
messagePropertiesBeanId The bean id of the Map which must contain the message properties. The object must be a Map. The properties defined in the map overwrite the message properties from the messageProperties parameter

MuleDispatcher messageProperties attribute
Message properties are defined as folows:

<resource-config selector="order">
    <resource>org.milyn.smooks.mule.MuleDispatcher</resource>
    <param name="endpointName">testEndpoint</param>
    <param name="beanId">test</param>
    <param name="messageProperties">
        <property name="prop1" value="prop1Value" />
        <property name="prop2">"prop2Value"</property>
        <property name="intProp" value="10" type="Integer" />
        <property name="dateProp" value="2008-07-11 12:30:56" type="DateTime" />
    </param>
</resource-config>

<resource-config selector="decoder:DateTime">
   <resource>org.milyn.javabean.decoders.DateDecoder</resource>
   <param name="format">yyyy-MM-dd HH:mm:ss</param>
</resource-config>

The following points explain the four properties:

  • The first property uses a attribute to set the value.
  • The second property takes the property element content and parses it as a MVEL expression.
  • The third property uses the type attribute to define a Integer type. This will convert the value into an Integer. This uses the standard DataDecoder feature from Smooks.
  • The fourth property uses the type attribute to define a custom configured Date type. This will convert the value into a Date. The configuration is set in the resource-config with the "decoder:DateTime" selector. This uses the standard DataDecoder feature from Smooks.

Description of the property attributes

Property Description
name The message property name (required)
value The value of the property. The property element content can also be set. If both are set then the value attribute is used.
type The type of the property value. This uses the standard DataDecoder feature from Smooks. DataDecoders can be configured using a "decoder:decoderName" resource-config selector. The decoderName must be set as type then. (Default: String)

Description of the property element content
The property element content is parsed as a MVEL expression. This gives great flexibility. The MVEL context contains all the beans from the bean map. The type and value attribute are ignored when the element content is set.


Adaptavist Theme Builder Powered by Atlassian Confluence