Pages

Wednesday 21 May 2014

Set Json payload in WSO2 ESB 4.8 and 4.8.1


Here i would like to share that how to set dynamic json payload in WSO2 ESB 4.8 and 4.8.1

We can use  'json' media-type property of 'payloadFactory' mediator to do that.

SAMPLE API 

In this API  accepts post request including user and pwd body parameters

 <api xmlns="http://ws.apache.org/ns/synapse" name="test-API" context="/api/test.json">
   <resource methods="POST">
      <inSequence>
         <payloadFactory media-type="json">
            <format>
{"username":"$1","pwd":"$2"}
</format>
            <args>
               <arg evaluator="json" expression="$.user"></arg>
               <arg evaluator="json" expression="$.pwd"></arg>            
            </args>
         </payloadFactory>
         <log level="full"></log>
         <send>
            <endpoint>
               <http method="POST" uri-template="http://example.com/test/enpoint"></http>
            </endpoint>
         </send>
      </inSequence>
   </resource>
</api>

No comments:

Post a Comment