Why Payload Factory Mediator builds XML with default name space? - wso2

I want to generate XML through Payload Mediator in WSO2 sequence without a name space. Example:
<payloadFactory media-type="xml">
<format>
<XmlRoot>
<a>$1</a>
<b>$2</b>
<c>$3</c>
<d>$4</d>
</XmlRoot>
</format>
<args>
<arg evaluator="json" expression="$.a"/>
<arg evaluator="json" expression="$.b"/>
<arg evaluator="json" expression="$.c"/>
<arg evaluator="json" expression="$.d"/>
</args>
</payloadFactory>
Above one generates xml like below:
<XmlRoot xmlns="http://ws.apache.org/ns/synapse">
<a>Paper</a>
<b>en-US</b>
<c>en-US</c>
<d>USD</d>
</XmlRoot>
Instead of (that is my goal)
<XmlRoot>
<a>Paper</a>
<b>en-US</b>
<c>en-US</c>
<d>USD</d>
</XmlRoot>
I know this namespace is gets from sequence root element. how to avoid or eliminate this auto generated name space ?

You can avoid the default name space by adding empty namespace ( xmlns="") in payload factory mediator
e.g <XmlRoot xmlns="">
<payloadFactory media-type="xml">
<format>
<XmlRoot xmlns="">
<a>$1</a>
<b>$2</b>
<c>$3</c>
<d>$4</d>
</XmlRoot>
</format>
<args>
<arg evaluator="json" expression="$.a"/>
<arg evaluator="json" expression="$.b"/>
<arg evaluator="json" expression="$.c"/>
<arg evaluator="json" expression="$.d"/>
</args>
</payloadFactory>

Related

In wso2 ei how create multipart request using application/octet-stream response

In wso2 ei 6.6 I am calling first api and getting the response application/octet-stream using this response how to create multipart request.
<payloadFactory media-type="xml">
<format>
<root>
<file
xmlns="http://org.apache.axis2/xsd/form-data">$1
</file>
</root>
</format>
<args>
<arg evaluator="xml" expression="$body/">
</args>
</payloadFactory>
If I set like the above payload factory I am getting empty response or encoded binary response. How can I fetch the media type and set multipart in wso2 ei.
Your question is not entirely clear to me whether the problem is with the response of the request but since you mention "How to set multipart"
With the below payload factory you should be able to create a multi part payload including a filename based on the incoming file content.
<payloadFactory media-type="xml">
<format>
<root
xmlns="">
<file xmlns="http://org.apache.axis2/xsd/form-data" filename="$2">$1</file>
</root>
</format>
<args>
<arg evaluator="xml" expression="$body/mediate/fileContent"/>
<arg evaluator="xml" expression="$body/mediate/fileContent/#filename"/>
</args>
Source: I hope this blog might help you:
https://www.yenlo.com/blogs/multipart-form-data-uploads-wso2-ei-esb/

How to handle multiple data for a single node in WSO2 EI?

I am currently trying to create a REST API from a SOAP Endpoint using WSO2 EI.
Source system sends data in JSON format and internally we convert it to xml and send it to the destination system.
The issue we are facing here is when there is multiple data(array) which has to be sent to a single node, we are unable to achieve it. Please let us know which mediator in EI should be used along with an example if possible.
Sample SOAP Message
<fcub:Detbs-Jrnl-Txn-Detail>
<fcub:SERIAL_NO>1</fcub:SERIAL_NO>
<fcub:DR_CR>D</fcub:DR_CR>
<fcub:BRANCH_CODE>001</fcub:BRANCH_CODE>
<fcub:CCY>EUR</fcub:CCY>
<fcub:AMOUNT>20</fcub:AMOUNT>
<fcub:TXN_CODE>TOP</fcub:TXN_CODE>
<fcub:LCY_AMOUNT>20</fcub:LCY_AMOUNT>
<fcub:ADDL_TEXT>test Mjrnl</fcub:ADDL_TEXT>
<fcub:ACCOUNT>001000032027</fcub:ACCOUNT>
</fcub:Detbs-Jrnl-Txn-Detail>
<fcub:Detbs-Jrnl-Txn-Detail>
<fcub:SERIAL_NO>2</fcub:SERIAL_NO>
<fcub:DR_CR>C</fcub:DR_CR>
<fcub:BRANCH_CODE>001</fcub:BRANCH_CODE>
<fcub:CCY>EUR</fcub:CCY>
<fcub:AMOUNT>20</fcub:AMOUNT>
<fcub:TXN_CODE>TOP</fcub:TXN_CODE>
<fcub:INSTRUMENT_NO></fcub:INSTRUMENT_NO>
<fcub:LCY_AMOUNT>20</fcub:LCY_AMOUNT>
<fcub:ADDL_TEXT>test Mjrnl</fcub:ADDL_TEXT>
<fcub:ACCOUNT>110000100</fcub:ACCOUNT>
</fcub:Detbs-Jrnl-Txn-Detail>
In the above case, for <fcub:Detbs-Jrnl-Txn-Detail>, we have two sets of data with serial number 1 and serial number 2.
The corresponding JSON message will be
{
"CREATEMJRNLBOOK_IOPK_REQ": {
"FCUBS_HEADER": {
"SOURCE": "SAP_CONCUR",
"UBSCOMP": "FCUBS",
"MSGID": "TEST1234",
"USERID": "PARAMUSER3",
"ENTITY": "ENTITY_ID2",
"BRANCH": "001",
"SERVICE": "FCUBSDEService",
"OPERATION": "CreateMjrnlbook"
},
"FCUBS_BODY": {
"Detbs-Jrnl-Txn-Master-Full": {
"VALUE_DATE": "2021-07-28",
"BRANCH_CODE": "001",
"Detbs-Jrnl-Txn-Detail": [
{
"SERIAL_NO": 1,
"DR_CR": "D",
"BRANCH_CODE": "001",
"CCY": "EUR",
"AMOUNT": 20,
"TXN_CODE": "TOP",
"INSTRUMENT_NO": 0,
"LCY_AMOUNT": 20,
"ADDL_TEXT": "test Mjrnl",
"ACCOUNT": "001000032027"
},
{
"SERIAL_NO": 2,
"DR_CR": "C",
"BRANCH_CODE": "001",
"CCY": "EUR",
"AMOUNT": 20,
"TXN_CODE": "TOP",
"INSTRUMENT_NO": 0,
"LCY_AMOUNT": 20,
"ADDL_TEXT": "test Mjrnl",
"ACCOUNT": "001000032027"
}
],
"Devws-Batch-Master": {
"BALANCING": "Y"
}
}
}
}
}
Proxy.xml from EI
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="DEService" startOnLoad="true" transports="http https"
xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log description="Logger to Check JSON Message from Proxy" level="full"/>
<header description="SOAPAction" name="SOAPAction" scope="transport" value=""/>
<property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
<payloadFactory description="Build Request Payload" media-type="xml">
<format>
<soapenv:Envelope
xmlns:fcub="http://fcubs.ofss.com/service/FCUBSDEService"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<fcub:CREATEMJRNLBOOK_IOPK_REQ>
<fcub:FCUBS_HEADER>
<fcub:MODULEID>$1</fcub:MODULEID>
<fcub:USERID>$2</fcub:USERID>
<fcub:ACTION>$3</fcub:ACTION>
<fcub:SOURCE_OPERATION>$4</fcub:SOURCE_OPERATION>
<fcub:MSGID>$5</fcub:MSGID>
<fcub:FUNCTIONID>$6</fcub:FUNCTIONID>
<fcub:MSGSTAT>$7</fcub:MSGSTAT>
<fcub:ENTITY>$8</fcub:ENTITY>
<fcub:UBSCOMP>$9</fcub:UBSCOMP>
<fcub:OPERATION>$10</fcub:OPERATION>
<fcub:BRANCH>$11</fcub:BRANCH>
<fcub:MULTITRIPID>$12</fcub:MULTITRIPID>
<fcub:SNAPSHOTID>$13</fcub:SNAPSHOTID>
<fcub:SERVICE>$14</fcub:SERVICE>
<fcub:SOURCE>$15</fcub:SOURCE>
<fcub:PASSWORD>$16</fcub:PASSWORD>
<fcub:CORRELID>$17</fcub:CORRELID>
<fcub:DESTINATION>$18</fcub:DESTINATION>
<fcub:SOURCE_USERID>$19</fcub:SOURCE_USERID>
</fcub:FCUBS_HEADER>
<fcub:FCUBS_BODY>
<fcub:Detbs-Jrnl-Txn-Master-Full>
<fcub:VALUE_DATE>$20</fcub:VALUE_DATE>
<fcub:BRANCH_CODE>$21</fcub:BRANCH_CODE>
<fcub:Detbs-Jrnl-Txn-Detail>
<fcub:SERIAL_NO>$22</fcub:SERIAL_NO>
<fcub:DR_CR>$23</fcub:DR_CR>
<fcub:BRANCH_CODE>$24</fcub:BRANCH_CODE>
<fcub:CCY>$25</fcub:CCY>
<fcub:AMOUNT>$26</fcub:AMOUNT>
<fcub:TXN_CODE>$27</fcub:TXN_CODE>
<fcub:LCY_AMOUNT>$28</fcub:LCY_AMOUNT>
<fcub:ADDL_TEXT>$29</fcub:ADDL_TEXT>
<fcub:ACCOUNT>$30</fcub:ACCOUNT>
</fcub:Detbs-Jrnl-Txn-Detail>
<fcub:Devws-Batch-Master>
<fcub:BALANCING>$31</fcub:BALANCING>
</fcub:Devws-Batch-Master>
</fcub:Detbs-Jrnl-Txn-Master-Full>
</fcub:FCUBS_BODY>
</fcub:CREATEMJRNLBOOK_IOPK_REQ>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.MODULEID"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.USERID"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.ACTION"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.SOURCE_OPERATION"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.MSGID"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.FUNCTIONID"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.MSGSTAT"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.ENTITY"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.UBSCOMP"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.OPERATION"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.BRANCH"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.MULTITRIPID"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.SNAPSHOTID"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.SERVICE"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.SOURCE"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.PASSWORD"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.CORRELID"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.DESTINATION"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_HEADER.SOURCE_USERID"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_BODY.Detbs-Jrnl-Txn-Master-Full.VALUE_DATE"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_BODY.Detbs-Jrnl-Txn-Master-Full.BRANCH_CODE"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_BODY.Detbs-Jrnl-Txn-Master-Full.Detbs-Jrnl-Txn-Detail.SERIAL_NO"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_BODY.Detbs-Jrnl-Txn-Master-Full.Detbs-Jrnl-Txn-Detail.DR_CR"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_BODY.Detbs-Jrnl-Txn-Master-Full.Detbs-Jrnl-Txn-Detail.BRANCH_CODE"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_BODY.Detbs-Jrnl-Txn-Master-Full.Detbs-Jrnl-Txn-Detail.CCY"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_BODY.Detbs-Jrnl-Txn-Master-Full.Detbs-Jrnl-Txn-Detail.AMOUNT"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_BODY.Detbs-Jrnl-Txn-Master-Full.Detbs-Jrnl-Txn-Detail.TXN_CODE"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_BODY.Detbs-Jrnl-Txn-Master-Full.Detbs-Jrnl-Txn-Detail.LCY_AMOUNT"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_BODY.Detbs-Jrnl-Txn-Master-Full.Detbs-Jrnl-Txn-Detail.ADDL_TEXT"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_BODY.Detbs-Jrnl-Txn-Master-Full.Detbs-Jrnl-Txn-Detail.ACCOUNT"/>
<arg evaluator="json" expression="$.CREATEMJRNLBOOK_IOPK_REQ.FCUBS_BODY.Detbs-Jrnl-Txn-Master-Full.Devws-Batch-Master.BALANCING"/>
</args>
</payloadFactory>
<property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
<property description="ContentType" name="ContentType" scope="axis2" type="STRING" value="text/xml"/>
<log description="Logger to check XML Message" level="full"/>
<send>
<endpoint key="FCUBSDEService_ADDRESS_EP"/>
</send>
</inSequence>
<outSequence>
<property description="Convert XML to Payload" name="messageType" scope="axis2" type="STRING" value="application/json"/>
<log description="Logger to Check Payload Response" level="full"/>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
Please let us know how to achieve this using EI.
Thanks
Tandon
For that You should use Iterate mediator, described in this documentation. Look at this XPath example.
But described by you JSON example, is not valid, because it should contain Array as Detbs-Jrnl-Txn-Detail. Its would be easier if i can see more msg context.

How to retrieve and use the setted value of a property in WSO2 ESB?

I am pretty new in WSO2 ESB and I have the following problem trying to retrieve the value of a property and put into an XML document that I am generating.
So, I have the following situation, in my ESB flow I have defined this property named TRANSACTION and having register as value:
<property name="TRANSACTION" scope="default" type="STRING" value="register"/>
Then in my flow I am generating an XML document (it works fine), using a payloadFactory mediator, in this way:
<payloadFactory media-type="xml">
<format>
<register password="$14" username="$13" xmlns="http://ws.wso2.org/dataservice">
<location>
<wiews>$1</wiews>
<pid>$2</pid>
<name>$3</name>
<address>$4</address>
<country>$5</country>
<lat>$6</lat>
<lon>$7</lon>
</location>
<sampledoi>$8</sampledoi>
<sampleid>$9</sampleid>
<date>$10</date>
<method>$11</method>
<genus>$12</genus>
</register>
</format>
<args>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_wiews/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_pid/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_name/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_address/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_country/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_lat/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_lon/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:sample_doi/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:sample_id/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:date/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:method/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:genus/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:username/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:password/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
</args>
</payloadFactory>
That genetes an XML document like this:
<?xml version="1.0" encoding="UTF-8" ?>
<register username="myUserName" password="myPswd">
<sampleid>CGN00001</sampleid>
<genus>Hordeum2</genus>
...................................
...................................
...................................
I want use the value of my TRANSACTION property to create the name of the first tag of my XML document, in this:
<register password="$14" username="$13" xmlns="http://ws.wso2.org
the register name have to be a $15 variable that use the TRANSACTION property value. I think that I can define it in some way into the ... list but I don't know how. At this time in this list I only have value retrieved from a DSS service output, in this case I think that I have to put the value of my TRANSACTION property, but how?
So, is it possible to something like this:
<$15 password="$14" username="$13" xmlns="http://ws.wso2.org
to dinamically insert the tag name?
As far as I know, you can't do that with payloadFactory but you can use a default name for your root node and just after payloadFactory mediator, add this javascript :
<script language="js"><![CDATA[
mc.getEnvelope().getBody().getFirstElement().setLocalName(mc.getProperty("TRANSACTION"));
]]></script>
An other solution would be to use XSLT

WSO2ESB: Property setting not accepting empty value

Actually I'm trying to get an empty value when I set a Property in a sequence in WSO2 ESB with an empty string. I have tried many things but always get the result "null" or "\"\"" instead of "" when I get the property, here is my code:
<property value=""""
name="arq.general.DestinationSystem" scope="default"
type="STRING" xmlns:ns="http://org.apache.synapse/xsd"
xmlns:ns2="http://org.apache.synapse/xsd"/>
<property name="arq.general.ParentInstanceID" scope="default"
type="STRING" value=""/>
<property expression="get-property('NonExistentProperty')"
name="arq.functional.User"
scope="default" type="STRING"
xmlns:ns="http://org.apache.synapse/xsd"
xmlns:ns2="http://org.apache.synapse/xsd"/>
Please could you help?
Cheers,
Tony
++ the payload Factory:
<payloadFactory media-type="xml">
<format>
<MensajeAuditoria xmlns="">
<Timestamp>$1</Timestamp>
<TrackingID>$2</TrackingID>
<SourceApplication>$3</SourceApplication>
<OperationName>$4</OperationName>
<ParentInstanceID>$5</ParentInstanceID>
<InstanceID>$6</InstanceID>
<ServiceID>$7</ServiceID>
<FunctionalID>$8</FunctionalID>
<AdapterType>$9</AdapterType>
<AdapterPoint>$10</AdapterPoint>
<HostName>$11</HostName>
<User>$12</User>
</MensajeAuditoria>
</format>
<args>
<arg evaluator="xml" expression="get-property('SYSTEM_TIME')"/>
<arg evaluator="xml" expression="get-property('arq.general.TrackingID')"/>
<arg evaluator="xml" expression="get-property('arq.general.SourceApplication')"/>
<arg evaluator="xml" expression="get-property('arq.functional.OperationName')"/>
<arg evaluator="xml" expression="get-property('arq.general.ParentInstanceID')"/>
<arg evaluator="xml" expression="get-property('arq.general.InstanceID')"/>
<arg evaluator="xml" expression="get-property('arq.general.ServiceID')"/>
<arg evaluator="xml" expression="get-property('arq.functional.FunctionalID')"/>
<arg evaluator="xml" expression="get-property('arq.general.AdapterType')"/>
<arg evaluator="xml" expression="$func:AdapterPoint"/>
<arg evaluator="xml" expression="get-property('SERVER_IP')"/>
<arg evaluator="xml" expression="get-property('arq.functional.User')"/>
</args>
</payloadFactory>
</else>
</filter>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
Adding the factory result:
{
"MensajeAuditoria": {
"Timestamp": 1492777451830,
"TrackingID": "76b9858d-8421-4d7e-d2af-e8e411382e2e",
"SourceApplication": "API Manager",
"OperationName": null,
"ParentInstanceID": null,
"InstanceID": "76b9858d-8421-4d7e-d2af-e8e411382e2e",
"ServiceID": "PRX_PROY1_AEX_AltaCliente",
"FunctionalID": null,
"AdapterType": "AEXP",
"AdapterPoint": "PreActRequest",
"HostName": "172.16.3.97",
"User": null,
}}
I have achieved a work-around using JavaScript but it should be possible to set it in the property mediator, or may be with enrich.
<script language="js"><![CDATA[var payload = mc.getPayloadJSON();
if(payload.MensajeAuditoria.ParentInstanceID== null){
payload.MensajeAuditoria.ParentInstanceID="";
}
mc.setPayloadJSON(payload);
mc.setProperty("MyProperty","");]]></script>
If you get an XML solution, please let me know.
Thanks.
An other solution is to use "string" xpath function :
<property name="arq.general.ParentInstanceID" expression="string('')"/>
I have tried your payloadFactory and it turns out it works like a charm on 4.8.1 but it fails on 5.0.0. This is most likely a change in the JSON message builder that they use in the ESB. The problem is not on your empty property but in the automatic translation from XML to JSON that happens when you set the messageType property.
What you can do to solve this though is the make the payload mediator create json straight away as follows:
<payloadFactory media-type="json">
<format>
{"MensajeAuditoria":{
"Timestamp":$1,
"TrackingID":"$2"
...
}
}
</format>
<args>
<arg evaluator="xml" expression="get-property('SYSTEM_TIME')"/>
<arg evaluator="xml" expression="get-property('arq.general.TrackingID')"/>
...
</args>
</payloadFactory>
</else>
</filter>
This way you are in control of the quotes, and it will never put null there unless you actually want it there.
Hope this helps solve your problem
Good thing would be to use enrich mediator to map the json field to xml field if there is a vale for the incoming field.
Sample
<filter regex="true" source="boolean(get-property('START_DATE'))">
<then>
<enrich description="Add startDate tag">
<source clone="true" type="inline">
<org:startDate xmlns:org="urn:example.com/service/org"/>
</source>
<target action="child" xpath="//*[local-name()=get-property('RequestType')]"/>
</enrich>
<enrich description="populate startDate">
<source clone="true" property="START_DATE" type="property"/>
<target
xmlns:org="urn:example.com/servi`enter code here`ce/org" xpath="//org:startDate"/>
</enrich>
</then>
<else/>
</filter>

WSO2ESB for each mediator, FOR EACH RESPONSE having /n/t extra with each element

I have this below mentioned soap request, I am using WSO2ESB 4.9.
Soap request :
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><jsonArray><jsonElement><a><s>as</s></a><b>Type1</b><c>C1</c><d><t>A1</t></d><e>e1</e></jsonElement><jsonElement><a><s>as</s></a><b>Type2</b><c>C2</c><d><t>A1</t></d><e>e1</e></jsonElement></jsonArray></soapenv:Body></soapenv:Envelope>
I want to iterator over jsonElement/b and get json list : ["Type1", "Type2"].But I am getting below list :
[
"\n\t\t\t\t\t\t\t\t\t\t\tType1\n\t\t\t\t\t\t\t\t\t",
"\n\t\t\t\t\t\t\t\t\t\t\tType2\n\t\t\t\t\t\t\t\t\t"
]
Please any way to get the required list.For each mediator :
<foreach expression="//jsonArray/jsonElement">
<sequence>
<payloadFactory media-type="xml">
<format>
<jsonElement>
$1
</jsonElement>
</format>
<args>
<arg expression="//b" evaluator="xml" />
</args>
</payloadFactory>
</sequence>
</foreach>
Got it working, there is space and newline in foreach <jsonElement>.
Working code:
<foreach expression="//jsonArray/jsonElement">
<sequence>
<payloadFactory media-type="xml">
<format>
<jsonElement xmlns="">$1</jsonElement>
</format>
<args>
<arg expression="//b" evaluator="xml" />
</args>
</payloadFactory>
</sequence>
</foreach>