在 WSO2 Micro 集成器中将文本/HTML 解析为 JSON

问题描述 投票:0回答:1
wso2 wso2-enterprise-integrator wso2-micro-integrator
1个回答
0
投票

同样的方法也适用于 Micro Integrator。我可以通过将以下配置添加到

deployment.toml
文件来使其工作。我尝试使用 Mocky 端点,它返回带有
text/html
ContentType 标头的 JSON 负载。

[[custom_message_formatters]]
class = "org.apache.synapse.commons.json.JsonStreamFormatter"
content_type = "text/html"

[[custom_message_builders]]
class = "org.apache.synapse.commons.json.JsonStreamBuilder"
content_type = "text/html"

API

<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="MockyAPI" context="/mocky">
    <resource methods="GET" uri-template="/getResponse">
        <inSequence>
            <log level="full">
                <property name="message" value="Calling Mocky endpoint"/>
            </log>
            <send>
                <endpoint>
                    <http method="GET" uri-template="https://run.mocky.io/v3/073c9d3d-4ab0-448e-af60-20f8880253c8"/>
                </endpoint>
            </send>
        </inSequence>
        <outSequence>
            <log level="full">
                <property name="message" value="Received response from Mocky endpoint"/>
            </log>
            <send/>
        </outSequence>
        <faultSequence>
            <log level="full">
                <property name="message" value="Error occurred while calling Mocky endpoint"/>
            </log>
            <send/>
        </faultSequence>
    </resource>
</api>
© www.soinside.com 2019 - 2024. All rights reserved.