Friday, July 12, 2013

How to test the Force HTTP 1.0 outgoing messages via WSO2 ESB and a REST request



There are few HTTP transport-specific properties in ESB.

Properties use in ESB access various types of information regarding a message that passes through the ESB. Also properties can be used to control the behavior of the ESB on a given message.
WSO2 ESB support HTTP 1.1 outgoing messages by default. To make it HTTP 1.0, there is a property that would help to perform it.
 
      <property name="FORCE_HTTP_1.0" value="true" scope="axis2"/>  



By the following steps I will be explaining how to test this behavior if WSO2 ESB.


To Setup :
----------------
  1. Go to <ESB_Home>/samples/axis2Server/src/SimpleStockQuoteService and build it, ant

  2. Start the Go to <ESB_Home>/samples/axis2Server and start the axis2Server by the following command, sh axis2server.sh.

  3. Start the ESB Server, <ESB_Home>/bin by providing, sh wso2server.sh.

  4. Run a tcpMon to view the outgoing messages.

  5. Start the tcpmon in the <ESB_Home>/bin - sh tcpmon.sh
    Create 2 listeners as below. 

    1. Listen Port 8281, Target host – localhost, Target port – 8280 – Before hits the ESB
    2. Listen Port 9001, Target host – localhost, target port – 9000 – After passing through ESB and Before hits the backend
  1. Log in to the ESB and provide the following synapse 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">  
        <header name="Action" value="urn:getQuote"/>  
        <filter source="get-property('To')" regex=".*/StockQuote.*">  
         <property name="FORCE_HTTP_1.0" value="true" scope="axis2"/>  
          <send>  
           <endpoint>  
             <address uri="http://localhost:9001/services/SimpleStockQuoteService"  
                 format="soap11"/>  
           </endpoint>  
          </send>  
          <drop/>  
        </filter>  
        <send/>  
       </sequence>  
     </definitions>  
    

To Send the Rest request :
---------------------------------------------

  1. Go to axis2Client, <ESB_Home>/samples/axis2Client and send the following REST request.
 ant stockquote -Dtrpurl=http://localhost:8281/services/StockQuote -Drest=true  


Observations :
-------------------------
  1. On the server side, Standard :: Stock price = $157.06490695255485 will be generated.
  2. Observe the tcpMon.

Rest request sent to ESB can be seen in port 8281,


POST /services/StockQuote HTTP/1.1



Outgoing message from ESB can be seen in port 9001,


POST /services/SimpleStockQuoteService HTTP/1.0