All docs This doc
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Introduction to Content-Based Router

Translator will basically change the context of a message from one interface to the other so that the message passed will adhere to the message context rules of the back end service. When communicating in between several applications each of the application might use a different standard of a data type. Therefore, to successfully maintain the communication, the messages should be intermediately be translated to a data format which will be compatible to the receiving application.

Message Translator is responsible to translate a message to ensure compatibility between two applications supporting two different data types. For more information please refer http://www.eaipatterns.com/MessageTranslator.html    

Figure 1: Message Translator EIP

Example Scenario for the EIP

The rest of this document explains, through a typical example scenario, how the Content-Based Router EIP can be simulated using the WSO2 ESB.

The example scenario depicts an inventory for stocks and illustrates how the sender sends a request in a different format which will be transformed into a format which will be compatible through the receiver. In the given scenario the sender sends a request which contains the following format,

<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>IBM</ser:Code>
   </soapenv:Body>
</soapenv:Envelope>

 The format which is expected by the receiver is in the following format,

 

Example Scenario

The Axis2 server accepts request being in the following format,

 

Here the client will send a request which is structure in the following manner,

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <m:CheckPriceResponse xmlns:m="http://services.samples/xsd">
         <m:Code>IBM</m:Code>
         <m:Price>70.0783006713743</m:Price>
      </m:CheckPriceResponse>
   </soapenv:Body>
</soapenv:Envelope>

Using the WSO2 ESB payloadFactory the request will be transformed to the structure which is accepted by the Axis2 Server. Then again when the response arrives it will be transformed back to the structure which is required by the client.    

 

Implementation Using the WSO2 ESB

Prerequisites

Start the Axis2 server and deploy the SimpleStockQuoteService if not already deployed

Start the ESB using the following configuration 

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
   <sequence name="fault">
      <log level="full">
         <property name="MESSAGE" value="Executing default &#34;fault&#34; sequence"/>
         <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
         <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
      </log>
      <drop/>
   </sequence>
   <sequence name="main">
      <in>
         <payloadFactory>
            <format>
               <m:getQuote xmlns:m="http://services.samples">
                  <m:request>
                     <m:symbol>$1</m:symbol>
                  </m:request>
               </m:getQuote>
            </format>
            <args>
               <arg xmlns:m0="http://services.samples" expression="//m0:Code"/>
            </args>
         </payloadFactory>
         <send>
            <endpoint>
               <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
         </send>
      </in>
      <out>
         <payloadFactory>
            <format>
               <m:CheckPriceResponse xmlns:m="http://services.samples/xsd">
                  <m:Code>$1</m:Code>
                  <m:Price>$2</m:Price>
               </m:CheckPriceResponse>
            </format>
            <args>
               <arg xmlns:m0="http://services.samples/xsd" expression="//m0:symbol"/>
               <arg xmlns:m0="http://services.samples/xsd" expression="//m0:last"/>
            </args>
         </payloadFactory>
      </out>
      <send/>
   </sequence>
</definitions>

 

 

 

 

 

 

 

 

 

 

 

  • No labels