How to make an additional http call inside api and process response?

I'm trying to create Message Mediation Policies, with which I can make an additional http call, process the response and enrich the current message. How can i do this? I use call Mediator, but I don’t understand how to handle the response.

<?xml version="1.0" encoding="UTF-8"?> <sequence name="call_out_handler" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<call blocking="true">
    <endpoint>
        <http method="get" uri-template="http://192.168.99.100:8888/stubFORAPIMan/ServletWithTimeout"/>
    </endpoint>
</call> </sequence>

Upvotes: 0

Views: 57

Answers (1)

npamudika
npamudika

Reputation: 153

You can use the PayloadFactory Mediator [1] to handle/format the response you received by calling an endpoint inside the Call mediator.

An example would be like this. Say you want to provide a json object by populating the values from the response you received; you can define the json object format in the "format" section and populate the values by providing the arguments in the "args" section in the PayloadFactory mediator as below.


    <payloadFactory media-type="json">
       <format>
          {
          "Data": {
          "PaymentSubmissionId": "$1",
          "PaymentId": "$2",
          "Status": "$3",
          "CreationDateTime": "$4"
          }
          } 
       </format>
       <args>
          <arg evaluator="xml" expression="$body//PaymentSubId"/>
          <arg evaluator="xml" expression="$body//PaymentId"/>
          <arg evaluator="xml" value="AcceptedSettlementInProcess"/>
          <arg value="2019-06-05T15:15:22+00:00"/>
       </args>
    </payloadFactory>
    <property name="messageType" value="application/json" scope="axis2" type="STRING"/>

[1] https://docs.wso2.com/display/EI640/PayloadFactory+Mediator

Upvotes: 1

Related Questions