Search code examples
wso2smookswso2-esb

WSO2 ESB custom properties for Smooks mediator


I need to use some configuration settings to transform message with Smooks mediator. For example I want to inject a base URL into attribute value of outgoing xml during transformation.

In Java I'd do it by adding beans to ExecutionContext. Looking at SmooksMediator code I do not see this. Can I do it somehow or I should extend and recompile SmooksMediator to supply properties form MessageContext?


Solution

  • For the input as the Smooks mediator we can feed only one stream from the ESB. So if you want to transform a message by injecting a property, you can't achieve it with the smooks mediator.

    Use XSLT mediator for this [1]. When configuring the XSLT mediator you can define properties to be passed into the transformation.

    ex:

     <xslt key="orderTransformer">
       <property expression="get-property('name')" name="name"/>
       <property expression="get-property('email')" name="email"/>
    </xslt>
    

    Then inside the XSLT you can define the two properties as below,

    <xsl:param name="email"/>
    <xsl:param name="name"/>
    

    and use them appropraitely as $email and $name in templates.

    <ns1:email>
            <xsl:value-of select="$email"/>
        </ns1:email>
        <ns1:name>
            <xsl:value-of select="$name"/>
        </ns1:name>
    

    [1] http://docs.wso2.org/wiki/display/ESB460/XSLT+Mediator