Hi Jyoti,
I'm assuming your request.body is a JSON payload and by sending a duplicate field element you're saying the body looks something like the following?
{
"account_no": "1234",
"account_no": "5678",
... more fields
}
Which gateway are you using, a v5 compatible gateway or a v10 API Gateway?
For a v5 compatible gateway, the INPUT context to DataPower is parsed and placed into request.body. The parsing in DataPower only allows one key of the same name at each level of the object hierarchy, and I believe the last key will win, so request.body will only show you only the last of the duplicate keys. The INPUT context of DataPower will remain a string, so the only advice I can provide would be use a GatewayScript policy to do a session.INPUT.readAsBuffer to read the INPUT context, convert that buffer to a string using the toString() function, and then use string manipulation to see if you have duplicates. If a duplicate is found you should do an apim.error function to stop the assembly and start error processing.
For the v10 API Gateway, request.body is immutable but unlike v5c it is also streamed, meaning that you cannot see request.body in the API Gateway context unless and until you
1. Do an initial parse policy where the parsing will read everything off the stream to place the parsed JSON object into message.body. You can then in a GatewayScript do a context.get('request.body') which would have the now buffered request. Note that the parsed object in message.body would have eliminated the duplicate key just as v5c would have, again the last key would be the one you'd see there.
2. A GatewayScript policy that will do a context.getMessage('request').body.readAsBuffer which will also read from the stream and provide the buffer to the asynchronous function once the data is read.
In either case, once you have the buffer, again convert the buffer to a string and use string manipulation to see if you have duplicates and you would do a context.reject if you find a duplicate to stop the assembly.
Best Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
------------------------------