Hi Dimuthu,

AFAIK we can't iterate values inside payloadFactory mediator yet. But as a
workaround you can get the job done using the script mediator instead of
payloadFactory as follows.

*<script language="js"><![CDATA[*

*            var attributes = mc.getPayloadJSON().attributes;*
*            var array = "";*
*            for(var i in attributes)*
* {*
* var attribute = attributes[i];*
* array = array+"<attribute>"+attribute+"</attribute>";*
* }*
* mc.setPayloadXML(<attributes>{array}</attributes>);*

* ]]></script>*


You may have to set the messageType property as well in order to get XML as
the output.

*<property name="messageType" value="application/xml" scope="axis2"/>*

Above configuration will transform incoming json

*{"attributes":["attr1","attr2","attr2"]}*

To outgoing xml

*<attributes>*

*<attribute>attr1</attribute>*

*<attribute>attr2</attribute>*

*<attribute>attr2</attribute>*

*</attributes>*


Hope this helps.

Thanks.






On Sun, May 18, 2014 at 10:38 PM, Dimuthu Upeksha <[email protected]> wrote:

> Hi all,
>
> I'm sending a JSON like following to ESB
> {
> attributes:[attr1,attr2,attr2]
> }
>
> At my proxy service I need to create a payload factory like following
> using above given input.
>
> <payloadFactory>
>      <format>
>          <attributes>
>              <attribute>attr1</attribute>
>              <attribute>attr2</attribute>
>  <attribute>attr3/attribute>
>           </attributes >
>       </format>
>       <args/>
>   </payloadFactory>
>
> But I couldn't figure out a way to iterate over that array and generate
> above PayloadFactory mediator. Can someone please suggest me a way to do
> this?
>
> Thanks
> Dimuthu
> --
> Dimuthu Upeksha
> Engineering Intern
> WSO2 inc.
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
Nalin Chamara
Software Engineer
071-56-147-56
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to