user666
user666

Reputation: 2013

Parse text/HTML as JSON in WSO2 Micro integrator

When I use EI, I add the following to enable text/HTML to be parsed as JSON under axis2.xml:

    <messageFormatter contentType="text/html" 
class="org.apache.synapse.commons.json.JsonStreamFormatter"/>

   <messageBuilder contentType="text/html" 
  class="org.apache.synapse.commons.json.JsonStreamBuilder"/>

However this did not work on the micro integrator latest version. I tried to add it to the deployment.toml under [[custom_message_builders]] and [[custom_message_formatters]], but it did not work as well.

Under https://ei.docs.wso2.com/en/latest/micro-integrator/setup/message_builders_formatters/message-builders-and-formatters/ they explained that we can add the text/html as custom and write our own class, but it was supported on EI before, why won't it work under the latest version?

Upvotes: 0

Views: 206

Answers (1)

Arunan
Arunan

Reputation: 3459

The same approach works in Micro Integrator as well. I was able to make it work by adding the following configs to the deployment.toml file. I tried with a Mocky endpoint, which returns a JSON payload with text/html ContentType header.

[[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>

Upvotes: 1

Related Questions