I have taken the request payload from the frontend in the wso2 apim custom sequence using the below property.
<property name="RequestPayload" expression="json-eval($)" />
Let the request payload be
{
"token": "jhghjgjhghjg",
"parameters": {
"Name": "alice",
"appName": "app",
"Id": "Id"
},
"date": {
"min": "this.startOrMin",
"max": "this.endOrMax",
"formats": [
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd HH:mm:ss"
]
},
"limit": "this.apiService.noOfRecords"
}
Consider I want to remove the Id field in the request payload before sending to the backend.
I have used a java class mediator in the sequence where I process this request payload taken from the property.
String ReqPayload = synapsecontext.getProperty("RequestPayload").toString();
log.info("ReqPayload: " + ReqPayload);
Suggest a way to modify/remove the payload field either in the class mediator or in the custom sequence before sending to the backend.
The easiest way for your payload is to use script mediator, like below:
<script language="js"><![CDATA[
var message = mc.getPayloadJSON();
delete message.parameters.Id;
mc.setPayloadJSON(message);
]]></script>
It is safe, if the parameters.Id
doesn't exist in payload, but be aware, that parameters
should exist. If not, you must check it before trying remove parameters.Id
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.