This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, go to https://wso2.com/documentation/.

Message Translator

Typically, different applications use different data types. Therefore, for two applications to successfully communicate, you should intermediately translate the messages that pass from one application to the data type compatible with the receiving application. A translator changes the context of a message from one interface to another, allowing messages to adhere to message context rules of the back-end service.

The Message Translator EIP is responsible for message translating to ensure compatibility between applications supporting different data types.

For more information, go to Message Translator

The following sections explain how you can implement a sample scenario of this EIP using the ESB profile of WSO2 EI. 

Sample scenario

The example scenario depicts an inventory of stocks. It illustrates how the sender sends a request in one format, which is then transformed into another format compatible with the receiver. The format of the request is as follows:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
   <soapenv:Header>    
   </soapenv:Header> 
   <soapenv:Body>
        <ser:Code>foo</ser:Code>
   </soapenv:Body>
</soapenv:Envelope>

 The message format compatible with the receiver is as follows:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getQuote>
         <!--Optional:-->
         <ser:request>
            <!--Optional:-->
            <ser:symbol>foo</ser:symbol>
         </ser:request>
      </ser:getQuote>
   </soapenv:Body>
</soapenv:Envelope>

All requests in the first format should be translated to the second by the ESB profile of WSO2 EI. 

The translation is done through the Payload Factory Mediator.

 The Synapse configurations of the artifacts

When you unzip the ZIP file you download below in Step 6 when simulating the sample scenario, you can find the below configurations in the <UNZIPPED_FILE>/src/main/synapse-config directory. For more information about these artifacts, go to WSO2 EI Documentation.

Proxy Service
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="message-translator-proxy" startOnLoad="true" transports="http https"
    xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <inSequence>
            <!-- Will transform the incoming message to the format specified below -->
            <payloadFactory media-type="xml">
                <format>
                    <m:getQuote
                        xmlns:m="http://services.samples">
                        <m:request>
                            <m:symbol>$1</m:symbol>
                        </m:request>
                    </m:getQuote>
                </format>
                <args>
                    <arg evaluator="xml" expression="//m0:Code"
                        xmlns:m0="http://services.samples"/>
                    </args>
                </payloadFactory>
                <send>
                    <endpoint>
                        <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                    </endpoint>
                </send>
            </inSequence>
            <outSequence>
                <respond/>
            </outSequence>
            <faultSequence/>
        </target>
    </proxy>

Setting up the sample scenario

Follow the below instructions to simulate this sample scenario.

Executing the sample

Send the following request to the ESB Profile using SOAP UI (or any other SOAP client).

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
   <soapenv:Header>    
   </soapenv:Header> 
   <soapenv:Body>
        <ser:Code>foo</ser:Code>
   </soapenv:Body>
</soapenv:Envelope>

Analyzing the output

After sending the request to the ESB profile of WSO2 EI through the client, notice that the request is successfully generated in the Stock Quote server.  The following output will be printed on the Axis2 server's Console, confirming that the request is successfully received by the back-end service.


You can view the response in the SOAP UI as follows.