wso2wso2-enterprise-integratorwso2-micro-integrator

How can I preserve square brackets in JSON response when using WSO2 EI proxy service?


How to undo removal square brackets in json when responding to service proxy in WSO2 EI 6.6.0

I create a secure proxy service in WSO2 Integration Studio 8.0

<?xml version="1.0" encoding="UTF-8"?>
<proxy name="test_proxy" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <endpoint key="conf:/test.bs"/>
        <inSequence>
            <log level="full"/>
            <header action="remove" description="Delete Header Security" name="wsse:Security" scope="default" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"/>
            <property name="messageType" scope="default" type="STRING" value="application/json"/>
        </inSequence>
        <outSequence>
            <log level="full"/>
            <send/>
        </outSequence>
        <faultSequence/>
    </target>
    <policy key="conf:policy/test_wspolicy.xml"/>
    <enableSec/>
</proxy>

When I request directly to my service the response is correct.

Request: http://1.2.3.4/json?list=[{nm_1:4,nm_2:9}]

Responce: {"success":true,"total":1,"data":[{"nm_1":4,"nm_2":9,"id_1":5,"nm_num":"12345","id_2":13,"err":0}]

When I request via wso2 the response is not correct. Removal square brackets in json when responding.

Request: http://wso2/json?list=[{nm_1:4,nm_2:9}]

Responce: {"success":true,"total":1,"data":{"nm_1":4,"nm_2":9,"id_1":5,"nm_num":"12345","id_2":13,"err":0}

Is there a proxy service setting that doesn't change my service's response?

upd: checked according to the recommendations with JsonTransformer

<?xml version="1.0" encoding="UTF-8"?>
<proxy name="test_proxy" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <endpoint key="conf:/test.bs"/>
        <inSequence>
            <header action="remove" description="Delete Header Security" name="wsse:Security" scope="default" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"/>
            <property name="messageType" scope="default" type="STRING" value="application/json"/>
            <jsontransform schema="JsonSchema"/>
        </inSequence>
        <outSequence>
            <send/>
        </outSequence>
        <faultSequence/>
    </target>
    <policy key="conf:policy/test_wspolicy.xml"/>
    <enableSec/>
</proxy>

Create localEntry:

<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="JsonSchema" xmlns="http://ws.apache.org/ns/synapse"><![CDATA[
{
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "type": "object",
    "properties": {
    "data": {
        "type": "array",
                "items":[
                    {
                        "type": "object",
                            "properties": {
                                "nm_1": {
                                    "type": "integer"
                                    }
                                },
                                "required": [
                                    "nm_kng"
                                ]
                    },
                    {
                        "type": "object",
                            "properties": {
                                "nm_2": {
                                    "type": "integer"
                                    }
                                }
                    }
                                
                    
                    ]
            },
    "required": [
        "nm_1",
        "nm_2"
    ]
}
}
]]></localEntry>

Response without square brackets :(

upd2:

Else Request:

http://wso2/json?list=[{nm_1:4,nm_2:9},{nm_1:5,nm_2:10}]

Response:

{"success":true,"total":1,"data":[{"nm_1":4,"nm_2":9,"id_1":5,"nm_num":"12345","id_2":13,"err":0},{"nm_1":5,"nm_2":10,"id_1":12,"nm_num":null,"id_2":null,"err":0}]

So WSO2 does not understand an array with one group of parameters?

upd3:

Found a post: https://lahirumadushankablog.wordpress.com/2019/12/29/json-transform-mediator-ei-6-6-0/

All recommendations did not help in solving the problem


Solution

  • The problem is solved. I had to fix the RampartSender class from the rampart-core_1.6.1.wso2v40 library.