WSO2 API PayloadFactory mediator XML array to JSON array
<p>I am trying to build a Proxy between a client and a server using WSO2-AM. The ultimate goal is changing the content of the response the server sends to a format that the client understands. Therefore I wrote a custom mediator using a PayloadFactory. This works OK when the server sends just 1 element, but it can be possible that the servers sends multiple elements. I am trying to use an iterator to iterate all the elements and aplying a payloadfactory to each element, but this only returns the first element, or (when the response of the server is enclosed with a root element) the last element.</p>

<p>The server output looks something like this:</p>

<pre><code>&lt;Monitoring&gt;
    &lt;Line&gt;
        &lt;Id&gt;1&lt;/Id&gt;
    &lt;/Line&gt;
    &lt;LocationPoint&gt;
        &lt;Direction&gt;
            &lt;Id&gt;11&lt;/Id&gt;

        &lt;/Direction&gt;
        &lt;DistanceFromPoint&gt;1111&lt;/DistanceFromPoint&gt;
        &lt;Point&gt;
            &lt;Id&gt;11111&lt;/Id&gt;
        &lt;/Point&gt;
    &lt;/LocationPoint&gt;
&lt;/Monitoring&gt;
&lt;!-- Repeated 0 ... x times --&gt;
</code></pre>

<p>I apply my mediotor which looks like this:</p>

<pre><code>&lt;sequence xmlns="http://ws.apache.org/ns/synapse" name="NAME"&gt;
    &lt;iterate
         preservePayload="true"
         expression="//Monitoring"
         id="MONITORING_ITERATOR"&gt;  
         &lt;target&gt;
            &lt;sequence&gt;
            &lt;payloadFactory media-type="json"&gt;
                &lt;format&gt;
                    {
                        "LineId":"$1",
                        "DirectionId":"$2",
                        "DistanceFromPoint":"$3",
                        "PointId":"$4"
                    }
                &lt;/format&gt;
                &lt;args&gt;
                    &lt;arg expression="//Line/Id"/&gt;
                    &lt;arg evaluator="xml" expression="//Direction/Id"/&gt;
                    &lt;arg evaluator="xml" expression="//DistanceFromPoint"/&gt;
                    &lt;arg evaluator="xml" expression="//Point/Id"/&gt;
                &lt;/args&gt;
            &lt;/payloadFactory&gt;
            &lt;send /&gt;
            &lt;/sequence&gt;
            &lt;/target&gt;
    &lt;/iterate&gt;
    &lt;property name="messageType" expression="get-property('default', 'WSO2_AM_API_ACCEPT_MESSAGE_TYPE')" scope="axis2"/&gt;
&lt;/sequence&gt;
</code></pre>

<p>So my expected output would be an array of the json objects declared between the format tags. However only 1 element is outputed. What am I missing?</p>

<p>EDIT: I also want to dynamicly get a json or xml response based on the ACCEPT header. Normally this is possible by saving the header at the IN flow and then use</p>

<pre><code>&lt;property name="messageType" expression="get-property('default', 'WSO2_AM_API_ACCEPT_MESSAGE_TYPE')" scope="axis2"/&gt;
</code></pre>

<p>But this doesn't seem to work here either.</p>