WSO2 ESB iterate mediator joining - iterator

i'm facing some problems with this process.. let me explain:
i want to call two services and join the responses in this order:
i have the first service's response:
<locations xmlns="http://ssocial.com/traceit/services/location">
<location>
<latitude>-33.45209980</latitude>
<longitude>-70.66241990</longitude>
<altitude>0.0</altitude>
<creation>2016-09-04T14:59:48.000-03:00</creation>
<updated>2016-09-04T14:59:48.000-03:00</updated>
<deviceId>25</deviceId>
</location>
<location>
<latitude>-33.45149521</latitude>
<longitude>-70.66146224</longitude>
<altitude>817.0</altitude>
<creation>2016-09-04T13:18:43.000-03:00</creation>
<updated>2016-09-04T13:18:43.000-03:00</updated>
<deviceId>25</deviceId>
</location>
</locations>
then i have the secon service's response :
<device xmlns="http://ssocial.com/traceit/services/device">
<id>25</id>
<code>mobile_02</code>
<type>
<id>1</id>
<name>MOBILE</name>
</type>
And then, the final response that i would like to have is :
<locations xmlns="http://ssocial.com/traceit/services/location">
<location>
<latitude>-33.45209980</latitude>
<longitude>-70.66241990</longitude>
<altitude>0.0</altitude>
<creation>2016-09-04T14:59:48.000-03:00</creation>
<updated>2016-09-04T14:59:48.000-03:00</updated>
<deviceId>25</deviceId>
<device xmlns="http://ssocial.com/traceit/services/device">
<id>25</id>
<code>mobile_02</code>
<type>
<id>1</id>
<name>MOBILE</name>
</type>
</device>
</location>
<location>
<latitude>-33.45149521</latitude>
<longitude>-70.66146224</longitude>
<altitude>817.0</altitude>
<creation>2016-09-04T13:18:43.000-03:00</creation>
<updated>2016-09-04T13:18:43.000-03:00</updated>
<deviceId>25</deviceId>
<device xmlns="http://ssocial.com/traceit/services/device">
<id>25</id>
<code>mobile_02</code>
<type>
<id>1</id>
<name>MOBILE</name>
</type>
</device>
</location>
</locations>
i'm really having lot of troubles trying to join both responses like that, and this is my sequence in wso2:
<sequence name="getDeviceInfoByLocationProcess" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="count(//ns1:locations/ns1:location)" name="LOCATIONS_COUNT" scope="default" type="STRING" xmlns:ns1="http://ssocial.com/traceit/services/location"/>
<iterate description="" expression="//ns1:locations/ns1:location/ns1:deviceId" id="LOCATIONS_ITERATOR" xmlns:ns1="http://ssocial.com/traceit/services/location">
<target>
<sequence>
<property description="device_id" expression="//ns1:deviceId" name="device_id" scope="default" type="STRING"/>
<sequence key="getDeviceInfoProcess"/>
</sequence>
</target>
</iterate>
<log level="custom">
<property expression="//ns1:locations" name="LOCATIONS" xmlns:ns1="http://ssocial.com/traceit/services/location"/>
<property expression="//ns2:device" name="DEVICE_INFO" xmlns:ns2="http://ssocial.com/traceit/services/device"/>
</log>
<property name="ECNCLOSING_ELEMENT" scope="default">
<wrapper xmlns=""/>
</property>
<aggregate id="AGG_01">
<completeCondition>
<messageCount max="-1" min="{get-property('LOCATIONS_COUNT')}"/>
</completeCondition>
<onComplete expression="//ns2:device" xmlns:ns2="http://ssocial.com/traceit/services/device">
<log level="full">
<property expression="$ctx:LOCATIONS_COUNT" name="COUNTER"/>
<property expression="$ctx:ECNCLOSING_ELEMENT" name="ENCLOSING"/>
</log>
<call/>
</onComplete>
</aggregate>
and actually with this sequence, i'm just getting this:
<device xmlns="http://ssocial.com/traceit/services/device">
<id>25</id>
<code>mobile_02</code>
<type>
<id>1</id>
<name>MOBILE</name>
</type>
In advance , thank you very much for the help

I can't see the content of "getDeviceInfoProcess" sequence, but I guess your are using call mediator. So, as a result of those requests (multiple requests because of iterate mediator), you receive some responses and that what you have to deal with in the rest of the initial mediation : aggregate offers you a way to wait for all the responses, but the initial message is lost : you should save it in a property (type OM) and use something like payloadMediator inside aggregate/onComplete to compose the final message.

Related

Unable to get pass iterate mediator in wso2

I am writing an iterate mediator, the code is going in the sequence written in that iterate mediator, it is completing too (read through logs) however, it is not going to next step. Please help me with what wrong am I doing.
<iterate expression="//mpesa/prov">
<target>
<sequence>
<sequence key="ProvMapperQueue"/>
</sequence>
</target>
</iterate>
<log level="custom">
<property name="After" value="Sequence"/>
</log>
It is now printing the logs neither is API getting a response, its stuck after sequence last line is logged.
For further information copying the sequence below too:
<sequence name="ProvMapperQueue" onError="ProvMapperQueue_Error" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="custom">
<property expression="$ctx:uri.var.msisdn" name="Msisdn"/>
<property name="ProvMapperQueue Sequence" value="Started"/>
</log>
<property name="messageType" scope="axis2" type="STRING" value="text/xml"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<call>
<endpoint key="OBD_EP"/>
</call>
<log level="custom">
<property expression="$ctx:uri.var.msisdn" name="Msisdn"/>
<property name="After Calling" value=" ProvMapperQueue EP"/>
<property name="ProvMapperQueue Sequence" value="Ended"/>
</log>
<respond/>
</sequence>
Logs printing are below :
[2023-01-24 00:14:07,883] INFO {LogMediator} - {api:OBD} Msisdn = 110000171, ProvMapperQueue Sequence = Started
[2023-01-24 00:14:07,893] INFO {TimeoutHandler} - This engine will expire all callbacks after GLOBAL_TIMEOUT: 120 seconds, irrespective of the timeout action, after the specified or optional timeout
[2023-01-24 00:14:08,181] INFO {LogMediator} - {api:OBD} Msisdn = 110000171, After Calling = ProvMapperQueue EP, ProvMapperQueue Sequence = Ended
[2023-01-24 00:17:06,839] INFO {SourceHandler} - Writer null when calling informWriterError
[2023-01-24 00:17:06,841] WARN {SourceHandler} - STATE_DESCRIPTION = Socket Timeout occurred after accepting the request headers and the request body, INTERNAL_STATE = REQUEST_DONE, DIRECTION = REQUEST, CAUSE_OF_ERROR = Connection between the client and the EI timeouts, HTTP_URL = /obd/prov/msisdn/110000171, HTTP_METHOD = GET, SOCKET_TIMEOUT = 180000, CLIENT_ADDRESS = /127.0.0.1:59198, CONNECTION http-incoming-4
Any help would mean a lot.
I think the problem is with the <respond/> mediator that you have added towards the end of the ProvMapperQueue sequence. This will stop further processing of a message and send the message back to the client[1]. That means, after it, the rest of the sequence logic will not be executed including the log mediator outside the iterate mediator.
[1] - https://docs.wso2.com/display/EI611/Respond+Mediator
Few issues with your integration. You need to remove the respond mediator from the Iterate sequence, as responding per iteration doesn't make sense. So, I believe what you need is to iterate over the entries and once done, respond back to the client. In order to wait for all the Iterations to finish you need to couple the iterate mediator with an aggregate mediator. Hence update the sequences like below.
<sequence name="ProvMapperQueue" onError="ProvMapperQueue_Error" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="custom">
<property expression="$ctx:uri.var.msisdn" name="Msisdn"/>
<property name="ProvMapperQueue Sequence" value="Started"/>
</log>
<property name="messageType" scope="axis2" type="STRING" value="text/xml"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<call>
<endpoint key="OBD_EP"/>
</call>
<log level="custom">
<property expression="$ctx:uri.var.msisdn" name="Msisdn"/>
<property name="After Calling" value=" ProvMapperQueue EP"/>
<property name="ProvMapperQueue Sequence" value="Ended"/>
</log>
</sequence>
<iterate expression="//mpesa/prov" id="iterateid">
<target>
<sequence>
<sequence key="ProvMapperQueue"/>
</sequence>
</target>
</iterate>
<aggregate id="iterateid">
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete expression="$body/*[1]">
<payloadFactory media-type="xml">
<format>
<payload xmlns="">
<response>Done</response>
</payload>
</format>
<args/>
</payloadFactory>
<respond/>
</onComplete>
</aggregate>
Update
The issue is you have set the OUT_ONLY property in your sequence hence the aggregate is never completed since callbacks are not registered. Instead of Iterate Mediator use the Foreach Mediator for your usecase. Check the example below.
<foreach expression="//mpesa/prov">
<sequence>
<sequence key="ProvMapperQueue"/>
</sequence>
</foreach>
<log level="custom">
<property name="After" value="Sequence"/>
</log>
<payloadFactory media-type="xml">
<format>
<payload xmlns="">
<response>Done</response>
</payload>
</format>
<args/>
</payloadFactory>
<respond/>

wso2 ei 6.5 SOAP Client and REST Service The parameter received is XML Rest need to json

<proxy xmlns="http://ws.apache.org/ns/synapse"
name="ctc"
startOnLoad="true"
statistics="enable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<log>
<property name="******" value="---ctc---"/>
</log>
<property xmlns:saop="http://j2ee.netbeans.org/wsdl/EsbJyBpel/src/saopWSDL"
expression="$body//saop:upload/xml"
name="request_msg"/>
<log>
<property expression="json-eval($)" name="request_msg"/>
</log>
<property name="messageType"
scope="axis2"
type="STRING"
value="application/json"/>
<script language="js">mc.setPayloadJSON(
{
"Code" : "10",
"Price" : "11"
});</script>
<property name="HTTP_METHOD" scope="axis2" value="POST"/>
<property name="messageType"
scope="axis2"
type="STRING"
value="application/json"/>
<property name="Content-Type"
value="application/json"
scope="transport"
type="STRING"/>
<send>
<endpoint>
<address format="pox" uri="http://192.16.110.142:8081/dqcsweb/ES/test"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log>
<property expression="json-eval($)" name="res_msg"/>
</log>
<send/>
</outSequence>
</target>
</proxy>
The XML structure that the restful service log prints;
How do You convert an XML structure to JSON?
I used script and payloadFactory, output the JSON string in the ESB, and the print log in the invoked service is still XML
input:
enter image description here
The message received by the service(http://192.16.110.142:8081/dqcsweb/ES/test):
<jsonObject><Code>10</Code><Price>11</Price></jsonObject>
expectations:
{
"code":"10",
"Price":"11"
}
Can you change the format of the endpoint invoked to rest. Please refer to the follwoing sample configuration.
<send>
<endpoint>
<address format="rest" uri="http://192.16.110.142:8081/dqcsweb/ES/test"/>
</endpoint>
</send>
The used pox format results in the message transformed into plain old XML format. Please refer to the documentation [1] to further clarify this.
[1]-https://docs.wso2.com/display/EI611/Address+Endpoint
Update
Can you enable wire logs by uncommenting the following [2] in log4j.properties file. You need to perform a server restart to enable this. This allows you to see the request sent out of the EI server. Please check if the request going out of the EI contains the necessary payload.
log4j.logger.org.apache.synapse.transport.http.wire=DEBUG
[2]-https://docs.wso2.com/display/ESB500/Debugging+Mediation#DebuggingMediation-Viewingwirelogs

To Fetch elements from enclosingElementProperty of aggregation in WSO2 ESB/EI

I am performing Iterate and Aggregation operation in wso2 EI. i want to fetch element values from aggregation response, OUTSEQUENCE log not printed after aggregation.Can anyone please help me to find this solution?
ProxyCode:
<proxy name="VBReadFromEmailBody" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<iterate expression="//jsonArray/jsonElement" id="LDVid" sequential="true">
<target>
<sequence>
<sequence description="VBEmail_LDVNonQualifiedLead_Sequence" key="VBEmail_LDVNonQualifiedLead_Sequence"/>
</sequence>
</target>
</iterate>
<property name="Aggregated_Responses" scope="default">
<jsonObject/>
</property>
<aggregate id="LDVid">
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete enclosingElementProperty="Aggregated_Responses" expression="$body/*[1]" xmlns:ns="http://org.apache.synapse/xsd">
<log level="full"/>
<loopback/>
</onComplete>
</aggregate>
</case>
<default/>
</switch>
</inSequence>
<outSequence>
<log level="custom">
<property name="======OUTSEQUENCE=======" value="CALLED"/>
</log>
<log level="full"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<foreach expression="//jsonValue" id="foreach_id">
<sequence>
<log level="custom">
<property expression="json-eval($.)" name="====each payload===="/>
</log>
<script language="js"><![CDATA[var log = mc.getServiceLog();
payload = mc.getPayloadJSON().toString();log.info("Logging payload;;;;" + payload); payloadRemoveSlash = payload.replace("\\", ""); mc.setProperty('payloadRemoveSlash',payloadRemoveSlash);]]></script>
</sequence>
</foreach>
<!--
DB Tracing (Response values stored in DB)-->
</outSequence>
</target>
</proxy>
Aggregated Response:
[2020-04-25 14:39:42,741] [] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:516c93bf-fb2d-46af-8cc8-2b3e56a5e
7ef, Direction: response, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><jsonObject><jso
nValue>"{\"transactionId\":null,\"timestamp\":\"2020-04-25 19:09:41\",\"OpportunityId\":\"0065500000FyUJOAA3\",\"message\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"typ
e\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AuBvGEAV\"},\"Company\":\"N/A\",\"Email\":\"jaxonstevens18#gmail.com\",\"Lead_Type__c\":\"Internet\",\"LeadSourc
e\":\"LDV i-Motor - Get a Quote\",\"FirstName\":\"Jaxon\",\"Account__c\":\"0015500000k8ow5AAA\",\"LastName\":\"Stevens\",\"Contact__c\":\"0035500000h2R5yAAE\",\"Id\":\"00Q5500000Au
BvGEAV\",\"MobilePhone\":\"+61 423 927 100\"},\"errorCode\":\"200\",\"appraisalId\":null}"</jsonValue><jsonValue>"{\"transactionId\":null,\"timestamp\":\"2020-04-25 19:09:42\",\"Op
portunityId\":\"0065500000FyUJYAA3\",\"message\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AuBvLE
AV\"},\"Company\":\"N/A\",\"Email\":\"steveross01#bigpond.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV Facebook - Book a Test Drive\",\"FirstName\":\"Stephen\",\"Accoun
t__c\":\"0015500000k8opxAAA\",\"LastName\":\"Ross\",\"Contact__c\":\"0035500000h2R1wAAE\",\"Id\":\"00Q5500000AuBvLEAV\",\"MobilePhone\":\"+61 414 404 774\"},\"errorCode\":\"200\",\
"appraisalId\":null}"</jsonValue><jsonValue>"{\"transactionId\":null,\"timestamp\":\"2020-04-25 19:09:42\",\"OpportunityId\":\"0065500000FyUJTAA3\",\"message\":\"Insert/Update succ
ess\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AuBvQEAV\"},\"Company\":\"N/A\",\"Email\":\"dunleavy2010#hotmail.com\",\"Le
ad_Type__c\":\"Internet\",\"LeadSource\":\"LDV i-Motor - Get a Quote\",\"FirstName\":\"Brendan\",\"Account__c\":\"0015500000k8oVhAAI\",\"LastName\":\"Dunleavy\",\"Contact__c\":\"00
35500000h2Ql6AAE\",\"Id\":\"00Q5500000AuBvQEAV\",\"MobilePhone\":\"+61 449 819 834\"},\"errorCode\":\"200\",\"appraisalId\":null}"</jsonValue></jsonObject></soapenv:Body></soapenv:
Envelope>
Instead of using <send/> inside OnComplete, try using <loopback/>. It might resolve the issue.

Simple WSOESB Proxy doen't response

Very simple example. Request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<T>
<m1>bysy</m1>
<m1>momo</m1>
<m1>gigi</m1>
</T>
</soapenv:Body>
</soapenv:Envelope>
I want to iterate and log every element in tag m1.
Proxy code:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Loopback" transports="https,http"
<target>
<inSequence>
<property name="OUT_ONLY" value="true" scope="axis2"/>
<iterate expression="//T/m1">
<target>
<sequence>
<property name="OUT_ONLY" value="true" scope="axis2"/>
<log level="custom">
<property name="M1" expression="//text()"/>
</log>
<drop/>
</sequence>
</target>
</iterate>
</inSequence>
</target>
</proxy>
It work as expected and logs all values. But WSO2ESB server doesn't close connection, until it falls with timeout. (I use SOAPUI for testing)
I tried to put properties OUT_ONLY RESPOND NO_KEEPALIVE in different part of proxy but it didn't help, as well I tried to use , with same result.
It looks like problem in iterate mediator which doesn't let to inSequence to terminate and send response to client. Once i remove it, proxy disconnect immediately with status code '202' message accepted.
This is because, by default, attribute "continueParent" is set to false with iterate mediator : change to <iterate continueParent="true" expression="//T/m1">
And you should explicitly send a 202 inside your inSequence, set this property : <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>

Read from a file in wso2 esb

I want to read from an xml file in my esb home directory called test.xml whose content is:
<a>Helloo
<b>World</b>
</a>
I have written a proxy to access content of node b as:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ReadFileProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="test" expression="get-property('registry','conf:/test.xml')" scope="default" type="OM"/>
<log level="custom">
<property name="test.b" expression="$ctx:test//b"/>
</log>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<payloadFactory>
<format>
<getCombinedResponse>Succefully read</getCombinedResponse>
</format>
</payloadFactory>
<send/>
</inSequence>
</target>
<description></description>
</proxy>
But it is giving me error as:
[2013-06-18 16:29:09,524] ERROR - NativeWorkerPool Uncaught exception
org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
at [row,col {unknown-source}]: [1,0]
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
at org.apache.axiom.om.impl.llom.OMDocumentImpl.getOMDocumentElement(OMDocumentImpl.java:109)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:570)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:566)
at org.apache.axiom.om.util.AXIOMUtil.stringToOM(AXIOMUtil.java:54)
at org.apache.axiom.om.util.AXIOMUtil.stringToOM(AXIOMUtil.java:39)
at org.apache.synapse.config.SynapseConfigUtils.stringToOM(SynapseConfigUtils.java:766)
at org.apache.synapse.mediators.builtin.PropertyMediator.convertValue(PropertyMediator.java:317)
at org.apache.synapse.mediators.builtin.PropertyMediator.getResultValue(PropertyMediator.java:299)
at org.apache.synapse.mediators.builtin.PropertyMediator.mediate(PropertyMediator.java:95)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:114)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:154)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:434)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:219)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
What am i doing wrong in this. Is there any other method to read from any file(pdf,txt and xml only).
As you have specified in the configuration
<property name="test" expression="get-property('registry','conf:/test.xml')" scope="default" type="OM"/>
you are referring a file which is saved in the registry. This is why you need to save that in the registry.
You can use VFS transport to read from a file. Please reffer the sample [1]. From this sample you can get to know how to read from a file. This sample directly sends the content to an endpoint. For your case you can use an xpath expression to retrieve the element b.
<property name="test.b" expression="//a/b"/>
[1]http://docs.wso2.org/wiki/pages/viewpage.action?pageId=16846489