问题
In my case, the response from the first back-end call is in Array of Objects format as below:
Response:
"Entity": {
"related-List": [
{
"fname": "abc",
"lname": "xyz",
"bdate": "2013-01-25",
"accType": "Cur",
"accNum": "54736",
"bal": 901,
"address": "USA"
},
{
"fname": "def",
"lname": "pqr",
"bdate": "2013-01-25",
"accType": "Sav",
"accNum": "12345",
"bal": 901,
"address": "USA"
},
{
"fname": "ghi",
"lname": "stu",
"bdate": "2013-01-25",
"accType": "Dep",
"accNum": "87654",
"bal": 901,
"address": "USA"
}
]
}
*************/
So in the second call, I want to use the "accType" and "accNum" from the response and make the back-end call for the number of objects present in the response array. For this, I need to use Iterate or ForEach like:
<foreach>
<call>
<endpoint>
<http method="POST" uri-template="http://localhost:6754/v2/{accType}/{accNum}"/>
</endpoint>
</call>
</foreach>
OR
<iterate>
<call>
<endpoint>
<http method="POST" uri-template="http://localhost:6754/v2/{accType}/{accNum}"/>
</endpoint>
</call>
</iterate>
What is the correct way to implement it?
回答1:
You cannot use Send or Call mediators inside Foreach mediator. Hence you have to use Iterate mediator. You can use Iterate mediator expression as json-eval($. Entity.related-List) and iterate through the array.
来源:https://stackoverflow.com/questions/61653131/sequential-back-end-calls-in-wso2-ei-esb