0
votes

we're facing an issue when trying to use a Response Mediator on a AWS Lambda. The AWS Lambda is using an official AWS API Gateway library and has a response with this format. Where body contains encoded JSON.

{
  "statusCode": 201,
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "body": "{\"key\":\"value\" [MORE ENCODED JSON] }"
  "isBase64Encoded": false
}

We're using a script Response Message Mediator like this (this is just a PoC):

<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="ApiGatewayProxyResponseV2" trace="enabled" statistics="enable">
   <log/>
   <property name="messageType" value="application/json" type="STRING" scope="axis2"/>   
   <script language="js">
      var payload = mc.getPayloadJSON();     
      var keys = Object.keys(payload);
      
      mc.setPayloadJSON({         
         keys: keys,
         myStatusCode:payload['statusCode'],
         myBody:payload['body'],
         myHeaders:payload['headers']
      });
      // todo set HTTP status code
   </script>      
</sequence>

Reading and writing of statusCode and headers, works. Reading body works, but when we're trying to return it we're getting:

<am:fault xmlns:am="http://wso2.org/apimanager">
  <am:code>601000</am:code>
  <am:type>Status report</am:type>
  <am:message>Runtime Error</am:message>
  <am:description>javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,273]</am:description>
</am:fault>

Why are we getting an XMLStreamException while we're trying to parse JSON? Is this some configuration error somewhere?

1

1 Answers

0
votes

i have had similar problem with [ENCODED JSON] in script mediator, but in WSO2 EI product. But, they both are built on apache-synapse, so maybe changing the script language from js to nashornJs. The NashornJs, treat in a different way encoded jsons.