I am unable to figure out how can I decode and encoded response. I am getting when I hit and endpoint in wso2.
This is the response I am getting:
{"binary":"eyJSZXNwb25zZUluZm8iOiB7CiAgICAgICAgIlJlc3VsdENvZGUiOiAyMDAsCiAgICAgICAgIlJlc3VsdERlc2MiOiAic3VjY2VzcyIKICAgICAgfQp9"}
This is the response I should get
{"ResponseInfo": {
"ResultCode": 200,
"ResultDesc": "success"
}
}
When I decode the code starting from "eyJSZXN" I get the correct payload. So only issue is that I am unable to convert it to json when I am fetching it.
<call>
<endpoint key="Endpoint"/>
</call>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<property expression="json-eval($)" name="ResponseJSON" scope="default" type="STRING"/>
The above code gives me the binary response in ResponseJSON. Hence, I would request if anyone can help me with this issue please.
You can use the base64Decode
function for this. Check the following example.
<property name="encodedBody" expression="json-eval($.binary)"/>
<payloadFactory media-type="json">
<format>$1</format>
<args>
<arg evaluator="xml" expression="base64Decode($ctx:encodedBody)"/>
</args>
</payloadFactory>