ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

Different behaviour when different types of xml is returned from ballerina function used in the MI connector #7374

Open poorna2152 opened 3 days ago

poorna2152 commented 3 days ago

Description

Consider the following ballerina functions,

import ballerinax/mi;

@mi:ConnectorInfo {}
public function f1() returns xml {
    return xml `<o>4</o>`;
}

@mi:ConnectorInfo {}
public function f2() returns xml {
    return xml `<merge>
                    <o>4</o>
                </merge>`;
}

@mi:ConnectorInfo {}
public function f3() returns xml {
    return xml `<merge>
                    <o>4</o>
                </merge>
                <merge>
                    <o>5</o>
                </merge>`;
}

When these functions are used within the MI sequence different kinds of results are given.

Consider an MI resource definition like following,

<?xml version="1.0" encoding="UTF-8"?>
<api
    xmlns="http://ws.apache.org/ns/synapse" name="test" context="/test">
    <resource methods="GET" uri-template="/f1">
        <inSequence>
            <log category="INFO" level="custom"  >
                <property name="a" value="abc" />
            </log>
            <bal_mi.f1>
                <Result>res</Result>
            </bal_mi.f1>
            <log category="INFO" level="custom">
                <property name="b" value="abc" />
            </log>
            <payloadFactory media-type="xml" template-type="default">
                <format>
                    <res>$1</res>
                </format>
                <args>
                    <arg expression="$ctx:res" evaluator="xml" />
                </args>
            </payloadFactory>
            <respond />
        </inSequence>
        <faultSequence></faultSequence>
    </resource>
    <resource methods="GET" uri-template="/f2">
        <inSequence>
            <log category="INFO" level="custom"  >
                <property name="a" value="abc" />
            </log>
            <bal_mi.f2>
                <Result>res</Result>
            </bal_mi.f2>
            <log category="INFO" level="custom">
                <property name="b" value="abc" />
            </log>
            <payloadFactory media-type="xml" template-type="default">
                <format>
                    <res>$1</res>
                </format>
                <args>
                    <arg expression="$ctx:res" evaluator="xml" />
                </args>
            </payloadFactory>
            <respond />
        </inSequence>
        <faultSequence></faultSequence>
    </resource>
    <resource methods="GET" uri-template="/f3">
        <inSequence>
            <log category="INFO" level="custom"  >
                <property name="a" value="abc" />
            </log>
            <bal_mi.f3>
                <Result>res</Result>
            </bal_mi.f3>
            <log category="INFO" level="custom">
                <property name="b" value="abc" />
            </log>
            <payloadFactory media-type="xml" template-type="default">
                <format>
                    <res>$1</res>
                </format>
                <args>
                    <arg expression="$ctx:res" evaluator="xml" />
                </args>
            </payloadFactory>
            <respond />
        </inSequence>
        <faultSequence></faultSequence>
    </resource>
</api>

The output for the functions are in the following way,

  1. <res xmlns="http://ws.apache.org/ns/synapse">4</res>
  2. <res xmlns="http://ws.apache.org/ns/synapse">
    <merge>
        <o>4</o>
    </merge>
    </res>
  3. <res xmlns="http://ws.apache.org/ns/synapse"/> In the first case the outermost xml tags are removed and in the second case these tags are not removed. For the third case there is not output.

Steps to Reproduce

Use the ballerina code given here and create an ballerina connector for MI. After that use the MI API given here to create a API. Then invoke the resources in the API to observe the outputs.

Version

v0.1.2

Environment Details (with versions)

No response