WSO2 Micro集成器在内容类型为应用程序/LD+ JSON时会引发错误

发布于 2025-02-12 03:02:00 字数 1872 浏览 1 评论 0原文

我想致电我与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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜血染红嫁衣 2025-02-19 03:02:00

您需要将正确的自定义内容类型映射到适当的消息构建器。例如,如果您的响应内容类型为application/ld+json,则需要添加消息构建器。

[[custom_message_builders]]
content_type = "application/ld+json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文