com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_link3' is unknown.

Sample 654: Smooks Mediator

Introduction

This sample demonstrates how theĀ Smooks mediatorĀ in WSO2 ESB is used to process an EDI message before sending it to the back-end service. In this demonstration, you will deploy a sample back-end service in WSO2 ESB, and then provide an EDI message as the input. The Smooks mediator configuration will then translate the EDI message to XML. The ESB sequence will further process the XML message, and theĀ Iterate mediatorĀ will send the message to the back-end service.

Prerequisites

For a list of prerequisites, seeĀ Prerequisites to Start Samples.

Building the sample

Here is the sample with Smooks mediator.

<definitions xmlns="http://ws.apache.org/ns/synapse">    <localEntry key="transform-xslt-key"
                src="file:repository/samples/resources/smooks/transform.xslt"/>
    <localEntry key="smooks-key" src="file:repository/samples/resources/smooks/smooks-config.xml"/>
    <proxy name="StockQuoteProxy" transports="vfs">
        <parameter name="transport.vfs.ContentType">text/plain</parameter>
        <!--CHANGE-->
        <parameter name="transport.vfs.ContentType">text/plain</parameter>
       <parameter name="transport.vfs.FileURI">file:///home/user/dev/test/smooks/in</parameter>
       <parameter name="transport.vfs.FileNamePattern">.*\.txt</parameter>
        <parameter name="transport.PollInterval">5</parameter>
        <!--CHANGE-->
        <parameter name="transport.vfs.MoveAfterProcess">file:///home/user/dev/test/smooks/original</parameter>
        <!--CHANGE-->
        <parameter name="transport.vfs.MoveAfterFailure">file:///home/user/dev/test/smooks/original</parameter>
        <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
        <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
        <parameter name="Operation">urn:placeOrder</parameter>
        <target>
            <inSequence>
                <smooks config-key="smooks-key"/>
                <xslt key="transform-xslt-key"/>
                <iterate expression="//m0:placeOrder/m0:order" preservePayload="true"
                         attachPath="//m0:placeOrder" xmlns:m0="http://services.samples">
                    <target>
                        <sequence>
                            <header name="Action" value="urn:placeOrder"/>
                            <property action="set" name="OUT_ONLY" value="true"/>
                            <send>
                                <endpoint>
                                    <address format="soap11"
                                            uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                                </endpoint>
                            </send>
                        </sequence>
                    </target>
                </iterate>
            </inSequence>
            <outSequence/>
        </target>
        <publishWSDL uri="file:repository/samples/resources/smooks/PlaceStockOrder.wsdl"/>
    </proxy>
</definitions>

To build the sample:

  1. Deploy the back-end service (SimpleStockQuoteService) in the Axis2 server. For instructions on deploying sample back-end services, seeĀ Deploying sample back-end services.

  2. Start the Axis2 server. For instructions on starting the Axis2 server, seeĀ Starting the Axis2 server.
  3. Enable theĀ plain text message builder in theĀ axis2.xmlĀ file (found inĀ theĀ <ESB_HOME>/repository/conf/axis2Ā directory) as shown below.


    <messageBuilder contentType="text/plain" class="org.apache.axis2.format.PlainTextBuilder"/>
  4. Enable theĀ vfsĀ transport in theĀ axis2.xmlĀ file by uncommenting the vfs transport sender and receiver configurations as shown below.
    <transportReceiver name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportListener"/>
    <transportSender name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportSender"/>
  5. Create three folders on your computer for the following purposes:

    • To store the original text file with the EDI message.

    • To store the text file with the EDI message after the file has been successfullyĀ processed by the Smooks mediator.
    • To store the text file with the EDI message if the file processing fails.
  6. Update the sample configuration file (which is theĀ synapse_sample_654.xmlĀ file foundĀ inĀ theĀ <ESB_HOME>/repository/samples/Ā directory) with the paths to the folders created in the previous step. Listed below are the parameters you need toĀ update:

    • transport.vfs.FileURI: This parameter specifies the path to the folder that stores the text file withĀ the EDI message.
    • transport.vfs.MoveAfterProcess: This specifies the path to the folder that stores the same text file afterĀ it is successfully converted by theĀ Smooks mediator.
    • transport.vfs.ActionAfterFailure: This specifies the path to the folder that stores the same text file if an error occurs during the processing.

    See the following example of the sample configuration:

    <parameter name="transport.vfs.FileURI">file:///home/user/test/in</parameter>
    <parameter name="transport.vfs.MoveAfterProcess">file:///home/user/test/original</parameter>
    <parameter name="transport.vfs.MoveAfterFailure">file:///home/user/test/original</parameter>

Executing the sample

Follow the steps given below.

  1. Start WSO2 ESB with the sample 654 configuration. For instructions on starting a sample configuration, seeĀ Starting a sample configuration.

    The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."

  2. Now you need to provide a text file with an EDI message.Ā WSO2 ESB is shipped with a sample file named edi.txt insideĀ theĀ <ESB_HOME>/repository/samples/resources/smooksĀ directory. CopyĀ thisĀ edi.txtĀ fileĀ to the folder you specified forĀ theĀ transport.vfs.FileURIĀ parameterĀ in the sample configuration.

Analyzing the output

The Smooks mediator will first translate the EDI message into XML as shown below.

Ā Original EDI message (edi.txt file)
HDR*1200*2008-01-01
ORD*50.00*500*IBM*REF 10053
ORD*170.00*100*MSFT*--
ORD*85.00*200*SUN*A1249
ORD*138.00*100*IBM*--
ORD*18.00*500*MSFT*ref 20088398289
Ā EDI message translated to XML
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><orders>
	<header>
		<batch-id>1200</batch-id>
		<date>2008-01-01</date>
	</header>
	<order>
		<price>50.00</price>
		<quantity>500</quantity>
		<symbol>IBM</symbol>
		<comment>REF 10053</comment>
	</order>
	<order>
		<price>170.00</price>
		<quantity>100</quantity>
		<symbol>MSFT</symbol>
		<comment>--</comment>
	</order>
	<order>
		<price>85.00</price>
		<quantity>200</quantity>
		<symbol>SUN</symbol>
		<comment>A1249</comment>
	</order>
	<order>
		<price>138.00</price>
		<quantity>100</quantity>
		<symbol>IBM</symbol>
		<comment>--</comment>
	</order>
	<order>
		<price>18.00</price>
		<quantity>500</quantity>
		<symbol>MSFT</symbol>
		<comment>ref 20088398289</comment>
	</order>
</orders>
</soapenv:Body></soapenv:Envelope>

The XML shown above will then be transformed into the following format after XSLT translation:

Ā XML message translated by XSLT
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><m0:placeOrder xmlns:m0="http://services.samples">
   <m0:order>
      <m0:price>50.00</m0:price>
      <m0:quantity>500</m0:quantity>
      <m0:symbol>IBM</m0:symbol>
   </m0:order>
   <m0:order>
      <m0:price>170.00</m0:price>
      <m0:quantity>100</m0:quantity>
      <m0:symbol>MSFT</m0:symbol>
   </m0:order>
   <m0:order>
      <m0:price>85.00</m0:price>
      <m0:quantity>200</m0:quantity>
      <m0:symbol>SUN</m0:symbol>
   </m0:order>
   <m0:order>
      <m0:price>138.00</m0:price>
      <m0:quantity>100</m0:quantity>
      <m0:symbol>IBM</m0:symbol>
   </m0:order>
   <m0:order>
      <m0:price>18.00</m0:price>
      <m0:quantity>500</m0:quantity>
      <m0:symbol>MSFT</m0:symbol>
   </m0:order>
</m0:placeOrder>
</soapenv:Body></soapenv:Envelope>

The XML message (after XSLT translation) is then sent to the back-end service (SimpleStockQuoteService) by theĀ Iterate mediator. You can see how the contents of the above message (orders) are received by the SimpleStockQuoteService, by checking the logs in the Axis2 server's terminal:

Accepted order #12 for : 200 stocks of SUN at $ 85.0
Accepted order #13 for : 500 stocks of IBM at $ 50.0
Accepted order #11 for : 100 stocks of MSFT at $ 170.0
Accepted order #14 for : 100 stocks of IBM at $ 138.0
Accepted order #15 for : 500 stocks of MSFT at $ 18.0
com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.