WSO2 Micro集成器在内容类型为应用程序/LD+ JSON时会引发错误
我想致电我与Integration Studio创建的API。有此API使用的标题。 API返回LD+JSON数据。当我向我通过Postman创建的API请求时,会出现以下错误。
Unexpected character in preface '{' (code 123); expected '<' in [row,col
我添加了使用属性调解员删除Transport_headers。但是这次,由于删除了标题信息,因此API无法正常工作。我将以下行添加到exployment.toml和axis2.xml文件中。但这仍然没有用。
[[custom_message_builders]]
content_type = "application/json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"
以下是我使用的XML文件。
<?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>
预先感谢您的回答
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将正确的自定义内容类型映射到适当的
消息构建器
。例如,如果您的响应内容类型为application/ld+json
,则需要添加消息构建器。You need to map the correct custom content type to the appropriate
message builder
. For example if your response content type isapplication/ld+json
you need to add the message builder like the below.