WSO2 ESB append full body to a POST parameter

When you have to invoke a back end service which can take only on parameter and you need to send your full soap envelop body as single post parameter you can use script mediator and payload factory mediator as following. I have an api which calls to "http://localhost:9000/services/SimpleStockQuoteService"  and response is received by the "second_sequence".
In the second_sequence response is processed and assign it single parameter using script mediator and payload factory.


<api xmlns="" name="StockQuoteAPI2" context="/stockquote_api">
   <resource methods="GET" uri-template="/view/{symbol}">
               <m0:getQuote xmlns:m0="http://services.samples">
               <arg expression="get-property('uri.var.symbol')"/>
         <send receive="second_sequence">
               <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>


<sequence xmlns="" name="second_sequence">
   <property name="DISABLE_CHUNKING" value="true" scope="axis2" type="STRING"/>
   <script language="js">
                     var payload = mc.getEnvelope().getBody().getFirstElement().toString();
                     payload = encodeURI(payload);        
            <arg xmlns:ns="http://org.apache.synapse/xsd" expression="$ctx:test"/>
      <log level="custom">
         <property xmlns:ns="http://org.apache.synapse/xsd" name="xxxxxxx....................." expression="$ctx:test"/>
      <log level="full"/>
            <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="get"/>
      <log level="full" category="DEBUG"/>

You will find that in the sequence it sends the request as follows

GET /services/SimpleStockQuoteService/getSimpleQuote?symbol=%253cns:getQuoteResponse%2520xmlns:ns=%2522http://services.samples%2522%253e%253cns:return%2520xmlns:ax21=%2522http://services.samples/xsd%2522%2520xmlns:xsi=%2522


  1. Hi, thank you for write this helpful post. Now i have a question. Do you have another function that encode the value from < to < instead to %3c. Thanks in advance and regards.


Post a Comment

Popular posts from this blog

WSO2 ESB Removing full soap header using enrich mediator.

WSO2 ESB Script Mediator (Remove body of an soap envelop)