I want to call an API that I created with Integration Studio. There are headers that this API uses. API returns ld+json data.When I make a request to the API I created via Postman,gives the following error.
Unexpected character in preface '{' (code 123); expected '<' in [row,col
I added TRANSPORT_HEADERS as remove using Property Mediator. But this time, the API does not work because the Headers information is deleted. I added the following lines to the deployment.toml and axis2.xml files. But it still didn't work.
[[custom_message_builders]]
content_type = "application/json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"
Below is the xml file I used.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/x" name="x" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET">
<inSequence>
<call>
<endpoint>
<http method="get" uri-template="https://json-ld.org/contexts/person.jsonld">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<script language="js"><![CDATA[var x = mc.getPayloadJSON();
if (x.id == "urn:ngsi-ld:AirQualitySensor:012")
mc.setPayloadJSON('{"s":"success"}');
else
mc.setPayloadJSON('{"s":"fail"}');]]></script>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Thank you in advance for your answers
You need to map the correct custom content type to the appropriate message builder
. For example if your response content type is application/ld+json
you need to add the message builder like the below.
[[custom_message_builders]]
content_type = "application/ld+json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"