簡體   English   中英

WSO2 Micro Integrator 在內容類型為 application/ld+json 時拋出錯誤

[英]WSO2 Micro Integrator throws an error when content type is application/ld+json

我想調用我使用 Integration Studio 創建的 API。 此 API 使用了一些標頭。 API 返回 ld+json 數據。當我向通過 Postman 創建的 API 發出請求時,出現以下錯誤。

Unexpected character in preface '{' (code 123); expected '<' in [row,col

我使用屬性調解器將 TRANSPORT_HEADERS 添加為刪除。 但是這一次,API 不起作用,因為 Headers 信息被刪除了。 我在 deployment.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>

預先感謝您的回答

您需要將正確的自定義內容類型映射到適當的message builder 例如,如果您的響應內容類型是application/ld+json ,您需要添加消息構建器,如下所示。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM