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>
Related
I'm retrieving some data's from DSS by using select query and then some transformation by payload factory after that I'm passing it to an endpoint, but when I do that the empty fields are being passed as null and not as empty strings ""
"department":"{department":null}",
"Selling_dealer__c":"{Selling_dealer__c":null}"
I wish it really showed like this:
"department":"",
"Selling_dealer__c":""
Note: Also tried the synapse properties file method but not working as excepted refer link 1 refer link 2
<sequence name="LaravelConnectorSequence" xmlns="http://ws.apache.org/ns/synapse">
<payloadFactory media-type="json">
<format>
{
"screen_type": "opportunity",
"vehicle_type__c": "",
"description": "",
"audio_file_name__c": "$1",
"lead_type__c": "Phone",
"request_type__c": "",
"mobile__c": "$2",
"leadsource": "Novum",
"company__c": "N/A",
"location__c": "$3",
"department__c": "$4",
"selling_dealer__c":"$5"
}
</format>
<args>
<arg evaluator="xml"
expression="get-property('audioFileName')"
literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="get-property('mobile')"
literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="get-property('location')"
literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="get-property('department')"
literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml"
expression="get-property('selling_dealer__c')"
literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
<log level="custom">
<property expression="json-eval($)"
name="=======Laravel Request====" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<property expression="get-property('Novum-configs')" name="config"
scope="axis2" type="OM" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="$axis2:config//*[local-name()='laravelToken']"
name="Authorization" scope="transport" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="$axis2:config//*[local-name()='laravelURL']"
name="uri.var.laravelapi" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<call>
<endpoint>
<http method="POST" uri-template="{uri.var.laravelapi}"/>
</endpoint>
</call>
<log level="custom">
<property expression="json-eval($)"
name="=======Laravel Response====" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
Since you want to convert your null values into "" strings, one workaround would be to convert the JSON to XML and then extract the elements from that and add them to your final JSON payload. In WSO2 there are different options you can set when converting JSON payloads. You can read about different options and how to work with JSON messages from here.
Since you want null to be "". You need to set the following property. If you are on MI this needs to go into deployment.toml, if on EI this goes into synapse.properties
'synapse.commons.enableXmlNullForEmptyElement'=false
Note: In MI (Surround the property name with single quotes)
When you are extracting data from the DSS response make sure to use Xpath expressions instead of JSON path expressions. Following is a simplified version of your configurations. Note I have hardcoded the DSS response.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/api" name="RESTApi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" url-mapping="/sample">
<inSequence>
<payloadFactory media-type="json">
<format>{"Selling_dealer__c": null}</format>
<args/>
</payloadFactory>
<property expression="//Selling_dealer__c" name="logInJson" scope="default" type="STRING"/>
<payloadFactory media-type="json">
<format>
{
"screen_type": "opportunity",
"selling_dealer__c": "$1"
}
</format>
<args>
<arg evaluator="xml" expression="$ctx:logInJson"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Above will produce the following response.
{
"screen_type": "opportunity",
"selling_dealer__c": "{"Selling_dealer__c":""}"
}
I used the script mediator to overcome this issue.
<script language="js"><![CDATA[var log=mc.getServiceLog();
var dep = mc.getProperty('department').toString();
var sell = mc.getProperty('selling_dealer__c').toString();
//log.info("===DepartmentValue===: "+dep);
var deps = mc.getProperty('department').startsWith("<Department");
//log.info("++++++++++++++++++++TRUE VALUE++++++++++++++++++"+deps);
if(dep.startsWith("<Department"))
{
dep ="";
mc.setProperty('department',dep);
}
//log.info("===DepartmentValueAfter===: "+dep)
//log.info("===SellingDealerValue===: "+sell);
var sells = mc.getProperty('selling_dealer__c').startsWith("<selling_dealer__c");
//log.info("++++++++++++++++++++TRUE VALUE++++++++++++++++++"+sells);
if(sell.startsWith("<selling_dealer__c"))
{
sell ="";
mc.setProperty('selling_dealer__c',sell);
}
//log.info("===selling_dealer__cValueAfter===: "+sell)
]]></script>
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.
I Use this document but this is Don't work:
https://apim.docs.wso2.com/en/3.2.0/learn/tutorials/expose-a-soap-service-as-a-rest-api/
for example automatic create this mediator for input and it's not work :
<header description="SOAPAction" name="SOAPAction" scope="transport" value="http://tempuri.org/ILivePublisher/Candles"/>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<property expression="json-eval($.Candles.instrumentIsin)" name="req.var.Candles.instrumentIsin"/>
<property expression="json-eval($.Candles.interval.Interval)" name="req.var.Candles.interval.Interval"/>
<property expression="json-eval($.Candles.since)" name="req.var.Candles.since"/>
<property expression="json-eval($.Candles.to)" name="req.var.Candles.to"/>
<payloadFactory description="transform" media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<web:Candles xmlns:web="http://tempuri.org/">
<web:instrumentIsin>$1</web:instrumentIsin>
<web:interval>
<web:Interval>$2</web:Interval>
</web:interval>
<web:since>$3</web:since>
<web:to>$4</web:to>
</web:Candles>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="get-property('req.var.Candles.instrumentIsin')"/>
<arg evaluator="xml" expression="get-property('req.var.Candles.interval.Interval')"/>
<arg evaluator="xml" expression="get-property('req.var.Candles.since')"/>
<arg evaluator="xml" expression="get-property('req.var.Candles.to')"/>
</args>
</payloadFactory>
<property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
Im trying to convert 24 hour to 12 hour in wso2 4.9.0 payload.
Is there any way to convert it using payload.
Original Time is 22:45:16
Need to convert to 10:45:16 PM
I don't know why you have to do that only using payloadFactory or under payloadfactory. There you can use only xpath to 'convert', at as you see below, it is very nasty and not perfect. If i remember in wso2esb 4.9.0, there already is ScriptMediator, which will be more better for that. I tested that on wso2ei 6.
<sequence name="time" xmlns="http://ws.apache.org/ns/synapse">
<property expression="//time/text()" name="time" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<script language="js"><![CDATA[
var timeIn = mc.getProperty('time');
var displayFormat = new java.text.SimpleDateFormat("hh:mm:ss a");
var parseFormat = new java.text.SimpleDateFormat("HH:mm:ss");
mc.setProperty('scriptTime', displayFormat.format(parseFormat.parse(timeIn)));
]]></script>
<payloadFactory media-type="json">
<format>{"inputTime":"$1", "scriptTime":"$2", "xpathTime":"$3"}</format>
<args>
<arg evaluator="xml" expression="$ctx:time" literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="$ctx:scriptTime" literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml"
expression="concat(concat(substring(number(substring-before($ctx:time,':'))+12, 1 div (number(substring-before($ctx:time,':')) = 0)),substring(number(substring-before($ctx:time,':'))-12, 1 div (number(substring-before($ctx:time,':')) > 12)),substring(number(substring-before($ctx:time,':')), 1 div (number(substring-before($ctx:time,':')) <= 12 and number(substring-before($ctx:time,':')) > 0 )),),':',substring-after($ctx:time,':') , concat(substring(' PM', 1, number(number(substring-before($ctx:time,':')) > 11) * string-length(' PM')),substring(' AM', 1, number(not(number(substring-before($ctx:time,':')) > 11)) * string-length(' AM'))))"
literal="false" xmlns:ns="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
<log level="custom">
<property expression="$ctx:time" name="time" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="$ctx:scriptTime" name="scriptTime" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="//xpathTime" name="xpathTime" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<respond/>
</sequence>
You can use something like this:
<payloadFactory media-type="json">
<format>
{"time":"$1"}
</format>
<args>
<arg evaluator="xml" expression="get-property('SYSTEM_DATE', 'hh:mm a')"/>
</args>
</payloadFactory>
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>