...
Before digging into implementation details, let's take a look at the relationship between the example scenario and the Message Translator EIP, by comparing their core components.
Message Translator EIP (Figure 1) | Message Translator Example Scenario (Figure 2) |
---|---|
Incoming Message | Stock Quote Request |
Translator | The Payload Factory Mediator in the ESB is used to carry out the translation. |
...
Code Block |
---|
<definitions xmlns="http://ws.apache.org/ns/synapse"> <sequence name="fault"> <log level="full"> <!-- Will trigger when a request is sent to the ESB profile of WSO2 EI --> <property<proxy name="MESSAGEmessage-translator-proxy" valuestartOnLoad="Executing default "fault" sequence"/> <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>true" transports="http https"> <target> <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/> <inSequence> </log> <drop/> </sequence> <!-- Will triggertransform whenthe aincoming requestmessage is sent to the ESBformat profile of WSO2 EIspecified below --> <sequence name="main"> <in><payloadFactory> <!-- Will transform the incoming message to the format specified below --> <payloadFactory> <format> <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>inSequence> <outSequence> <out> <send<respond/> </outSequence> </out>target> <</sequence>proxy> </definitions> |
The configuration elements
...
- Download the
Messsage-Translator.zip
file, which includes the ESB configuration described above. See Setting up the Environment for instructions on setting up the ESB and the back-end service.
Info When you set up the environment, note that you only need to start one instance of the back-end service (Stock Quote Service) to simulate this example.
Executing the sample
Send the following request to the ESB, by using a SOAP client. When you send the request, you will need the wsdl URL of the proxy service defined in the ESB configuration. The default wsdl URL for this proxy service is http://localhost:8280/services/message-translator-proxy?wsdl.
Code Block |
---|
<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> |
...
When you send the request, the ESB first receives the message and then routes it to the back-end service (StockQuoteService). The following output will be printed on the Axis2 server's console, confirming that the request is successfully received by the back-end service.
Code Block |
---|
samples.services.SimpleStockQuoteService :: Generating quote for : foo |
The generated stock quote will then be sent to the client application (SOAP UI). You can view the response in the SOAP UI as follows.: