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 5 Next »

The objective of this example is to introduce Message Translator Enterprise Integration Pattern (EIP) can be implemented using WSO2 ESB.  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. 

Start an instances of 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>

Request Structure

The following describes a sample structure of a request which will be sent to the ESB from the client end. 

<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 structure of the message will be translated into a structure which will be compatible with the back end Axis2 Server instance through the ESB. Then the response will again be translated by the ESB and will be sent back to the Client. The response will look smiler to the following.

<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>

 

 

 

 

 

 

 

 

 

 

  • No labels