wso2esb how to respond message in iso8583 inbound endpoint - wso2

I'm send ISO8583 message from testclient to my inbound,
i have the log console :
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ISOMessage xmlns="http://ws.apache.org/ns/synapse">
<data>
<field id="0">0200</field>
<field id="3">568893</field>
<field id="4">000000020000</field>
<field id="7">0110563280</field>
<field id="11">456893</field>
<field id="44">DFGHT</field>
<field id="105">ABCDEFGHIJ 1234567890</field>
</data>
</ISOMessage>
</soapenv:Body>
</soapenv:Envelope>
Response From Server :ISOMessage from pool-28-thread-1 is consumed :
0210B220000002100000000000000080000056892300000010050001105632804568930005KAMAL021ABCDEFGHIJ 1234567890
how to change response from server, for example i want to change field id 105 from <field id="105">ABCDEFGHIJ 1234567890</field> to <field id="105">xxxxxxxxxx 000000000</field>
I don't know how to alter data and send it back to client.
I search on wso2 documentation, how to respond message in inbound, but I can't find anything.
how to handle incoming ISOMessage, alter it, and send it back to client?
Do we need create connector or just simply modify data in sequence?
thanks

You can simply modify the XML within the sequence. Once you received the message you can modify it using the Enrich Mediator as follows (You need to specify the proper XPath to identity the element to change).
Once the response is modified, you can use Send mediator to send it to a
<!-- todo: receive the message -->
<property name="newValue" value="xxxxxxxxxx 000000000"/>
<enrich>
<source type="property" clone="true" property="newValue"/>
<target xpath="$body/*[1]/*[1]/*[7]"/>
</enrich>
<log>
<property name="message" expression="$body"/>
</log>
<!-- todo: send the message -->

Related

WSO2 EI 6.5.0 enable MTOM in SOAP service response

I need to create Soap Operation GetFile to respond with file content and additional tags using MTOM (reponse Content-Type multipart/related):
<Response>
<file>
<id>1</id>
<name>Filename.pdf</name>
<content>
<xop:Include href="cid:test" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
</content>
</file>
</Response>
I have proxy which calls external service to get file content and then I generate payload using PayloadFactory mediator ($body/* in this case is file binary content from external service, id and name are hardcoded for simplicity):
<payloadFactory media-type="xml">
<format>
<Response>
<file>
<id>$1</id>
<name>$2</name>
<content>$3</content>
</file>
</Response>
</format>
<args>
<arg value="1"/>
<arg value="fileName.pdf"/>
<arg evaluator="xml"
expression="$body/*"/>
</args>
</payloadFactory>
<property name="enableMTOM" scope="axis2" type="STRING" value="true"/>
<respond/>
In response I get:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<Response xmlns="http://ws.apache.org/ns/synapse">
<file>
<id>1</id>
<name>fileName.pdf</name>
<content>base64content</content>
</file>
</Response>
</soapenv:Body>
</soapenv:Envelope>
If I remove that payloadFactory then I get correct multipart/related response, so enableMTOM property works (but I need additional custom tags):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">
<xop:Include href="cid:1" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
</ns:binary>
</soapenv:Body>
</soapenv:Envelope>
Is custom mediator with messageContext.addAttachment only solution in this case? And whats best practice in such case - save received file content locally on server and then use it as attachment?
If you are constructing the message payload using a Payload factory mediator, and expecting to send the response as "multipart/form-data", you need to set the message type of the response after the Payload factory mediator. You can use the following property to set the message type of the response.
<property name="messageType" value="multipart/form-data" scope="axis2"/>
Furthermore, when we manipulate the file content using the Payload factory mediator, the message context gets built inside the Payload factory mediator and returned as a base64 encoded value. In order to decode the content, you need to add the following property to your proxy configuration.
<property name="DECODE_MULTIPART_DATA" value="true" scope="axis2" action="set" type="BOOLEAN"/>
Please refer to the latest WSO2 documentation on MTOM and SwA Optimizations and Request/Response Correlation for more details on this.
In a content-aware mediation scenario (where the message gets built), you can use the following property to decode the multipart message that is being sent to the backend. Otherwise, the outgoing message will be in encoded form.

How exactly work this iterate mediator in this WSO2 ESB project?

I am absolutly new in WSO2 and I have the following doubt about an ESB project on which I am working on.
I have to iterate on each <Sample>...</Sample> element of the following XML document (coming from a DSS service):
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<Samples xmlns="http://ws.wso2.org/dataservice">
<Sample>
<sample_id>XXX00001</sample_id>
<processed>n</processed><sample_doi>sampleid001</sample_doi><date>2000-01-01</date><hold_wiews>hold_wiews-0001</hold_wiews><hold_pid>hold_pid-001</hold_pid><hold_name>hold_name-001</hold_name><hold_address>hold_address-001</hold_address><hold_country>001</hold_country><hold_lat>hold_lat-1</hold_lat><hold_lon>hold_lon-1</hold_lon><method>acqu</method><genus>genus-001</genus><species>species-001</species><sp_auth>sp_auth-001</sp_auth><subtaxa>subtaxa-001</subtaxa><st_auth>st_auth-001</st_auth><bio_status>001</bio_status><mls_status>01</mls_status><prov_sid>prov_sid-001</prov_sid><provenance>pr1</provenance><coll_sid>coll_sid-001</coll_sid><coll_miss_id>coll_miss_id-001</coll_miss_id><coll_site>coll_site-001</coll_site><coll_lat>coll_lat-1</coll_lat><coll_lon>coll_lon-1</coll_lon><coll_uncert>coll_uncert-001</coll_uncert><coll_datum>coll_datum-001</coll_datum><coll_georef>coll_georef-001</coll_georef><coll_elevation>1</coll_elevation><coll_date>2001-01-01</coll_date><coll_source>s1</coll_source><ancestry>ancestry-001</ancestry>
</Sample>
<Sample>
<sample_id>XXX00002</sample_id>
<processed>n</processed><sample_doi>sampleid002</sample_doi><date>2000-01-02</date><hold_wiews>hold_wiews-0002</hold_wiews><hold_pid>hold_pid-002</hold_pid><hold_name>hold_name-002</hold_name><hold_address>hold_address-002</hold_address><hold_country>002</hold_country><hold_lat>hold_lat-2</hold_lat><hold_lon>hold_lon-2</hold_lon><method>acqu</method><genus>genus-002</genus><species>species-002</species><sp_auth>sp_auth-002</sp_auth><subtaxa>subtaxa-002</subtaxa><st_auth>st_auth-002</st_auth><bio_status>002</bio_status><mls_status>02</mls_status><prov_sid>prov_sid-002</prov_sid><provenance>pr2</provenance><coll_sid>coll_sid-002</coll_sid><coll_miss_id>coll_miss_id-002</coll_miss_id><coll_site>coll_site-002</coll_site><coll_lat>coll_lat-2</coll_lat><coll_lon>coll_lon-2</coll_lon><coll_uncert>coll_uncert-002</coll_uncert><coll_datum>coll_datum-002</coll_datum><coll_georef>coll_georef-002</coll_georef><coll_elevation>2</coll_elevation><coll_date>2001-01-02</coll_date><coll_source>s2</coll_source><ancestry>ancestry-002</ancestry>
</Sample>
<Sample>
<sample_id>XXX00003</sample_id>
<processed>n</processed><sample_doi>sampleid003</sample_doi><date>2000-01-03</date><hold_wiews>hold_wiews-0003</hold_wiews><hold_pid>hold_pid-003</hold_pid><hold_name>hold_name-003</hold_name><hold_address>hold_address-003</hold_address><hold_country>003</hold_country><hold_lat>hold_lat-3</hold_lat><hold_lon>hold_lon-3</hold_lon><method>acqu</method><genus>genus-003</genus><species>species-003</species><sp_auth>sp_auth-003</sp_auth><subtaxa>subtaxa-003</subtaxa><st_auth>st_auth-003</st_auth><bio_status>003</bio_status><mls_status>03</mls_status><prov_sid>prov_sid-003</prov_sid><provenance>pr3</provenance><coll_sid>coll_sid-003</coll_sid><coll_miss_id>coll_miss_id-003</coll_miss_id><coll_site>coll_site-003</coll_site><coll_lat>coll_lat-3</coll_lat><coll_lon>coll_lon-3</coll_lon><coll_uncert>coll_uncert-003</coll_uncert><coll_datum>coll_datum-003</coll_datum><coll_georef>coll_georef-003</coll_georef><coll_elevation>3</coll_elevation><coll_date>2001-01-03</coll_date><coll_source>s3</coll_source><ancestry>ancestry-003</ancestry>
</Sample>
</Samples>
</soapenv:Body>
</soapenv:Envelope>
To do it I am using the iterate mediator (it is working pretty fine), something like this:
<iterate expression="$body//ds:Sample" id="ITR_AGG" xmlns:ds="http://ws.wso2.org/dataservice">
<target>
<sequence>
<enrich>
<source clone="true" type="envelope"/>
<target property="sampleData" type="property"/>
</enrich>
<!-- Log Sample Data -->
<log level="custom">
<property expression="$ctx:sampleData" name="sample data"/>
</log>
...........................................................
...........................................................
DO SOME OTHER STUFF
...........................................................
...........................................................
</sequence>
</target>
</iterate>
It works fine but I have some doubts, I try to explain these doubts.
The iterate mediator implements the Splitter enterprise integration pattern **, it is used to splits the message into a number of different messages derived from the parent message**.
Ok, so I am splitting the original message that basically is contained into the <soapenv:Body>---</soapenv:Body> container into the 3 <Sample>...</Sample> separated message.
It works but why the iterate expression defined into the iterator mediator:
<iterate expression="$body//ds:Sample" id="ITR_AGG" xmlns:ds="http://ws.wso2.org/dataservice">
is $body//ds:Sample?
Ok so I think that I have to use the ds: prefix because it is coming from a data service (tell me if I am doing wronga assertion). But what exactly represent the $body "variable"? (is it something like a variable?)
Is it representing the <soapenv:Body> element in which have to be searched the <Sample> element that have to be iterated? Or what? In case my assumption is correct how the <soapenv:Body> is associated to the $body "variable"?
The second doubt is related to the use of the enrich mediator contained at the begining of the iterate mediator:
<enrich>
<source clone="true" type="envelope"/>
<target property="sampleData" type="property"/>
</enrich>
What exactly does? It seems to me that it is copying the current element on which is iterating into a new property named sampleData, infact after this mediator the sampleData property is logged by a logger and it is printed something like this:
sample data =
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<Sample xmlns="http://ws.wso2.org/dataservice">
<sample_id>XXX00001</sample_id>
<processed>n</processed><sample_doi>sampleid001</sample_doi><date>2000-01-01</date><hold_wiews>hold_wiews-0001</hold_wiews><hold_pid>hold_pid-001</hold_pid><hold_name>hold_name-001</hold_name><hold_address>hold_address-001</hold_address><hold_country>001</hold_country><hold_lat>hold_lat-1</hold_lat><hold_lon>hold_lon-1</hold_lon><method>acqu</method><genus>genus-001</genus><species>species-001</species><sp_auth>sp_auth-001</sp_auth><subtaxa>subtaxa-001</subtaxa><st_auth>st_auth-001</st_auth><bio_status>001</bio_status><mls_status>01</mls_status><prov_sid>prov_sid-001</prov_sid><provenance>pr1</provenance><coll_sid>coll_sid-001</coll_sid><coll_miss_id>coll_miss_id-001</coll_miss_id><coll_site>coll_site-001</coll_site><coll_lat>coll_lat-1</coll_lat><coll_lon>coll_lon-1</coll_lon><coll_uncert>coll_uncert-001</coll_uncert><coll_datum>coll_datum-001</coll_datum><coll_georef>coll_georef-001</coll_georef><coll_elevation>1</coll_elevation><coll_date>2001-01-01</coll_date><coll_source>s1</coll_source><ancestry>ancestry-001</ancestry>
</Sample>
</soapenv:Body>
</soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
that represents the current element on which I am iterating. Is it my reasoning correct?
You can use any string for the prefix, just be sure to use the same string after xmlns:
xmlns:ds="http://ws.wso2.org/dataservice"
Ex:
<iterate expression="$body//mypref:Sample" id="ITR_AGG" xmlns:mypref="http://ws.wso2.org/dataservice">
$body is a predefined xpath expression for synapse that represent the body message:
https://docs.wso2.com/display/ESB500/Synapse+XPath+Variables#SynapseXPathVariables-$body
The enrich mediator:
<enrich>
<source clone="true" type="envelope"/>
<target property="sampleData" type="property"/>
</enrich>
Just copy the content of the incoming message, the entire payload including the soapevelop inside a property called sampleData.

WSO2 ESB How to deliver the message of the Custom Mediator in EndPoint

Good day!
I only recently began to study the ESB bus. I need to convert the incoming SOAP message in the HTTP request with Content-Type: application/x-www-form-urlencoded.
I have created a Proxy Service, Custom Mediator 1 in Java, transformed message, how do I pass it to the endpoint and get the answer in Custom Mediator 2?
In the picture I have drawn an example of how to transform the message.
You don't need to write custom mediators, you can transform SOAP to rest calls, sample with a rest service waiting for 2 parameters like
param1=value1&param2=value2
<!-- prepare data for org.apache.axis2.transport.http.XFormURLEncodedFormatter message formatter -->
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<root>
<param1>$1</param1>
<param2>$2</param2>
</root>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$body/node1/node11/text()"/>
<arg evaluator="xml" expression="$body/node1/node12/text()"/>
</args>
</payloadFactory>
<!-- set output format -->
<property name="messageType" value="application/x-www-form-urlencoded" scope="axis2" type="STRING"/>
<property name="DISABLE_CHUNKING" value="true" scope="axis2" type="STRING"/>
<!-- call the REST endpoint with synch call : response is received in this sequence -->
<call>
<endpoint key="conf:endpoints/MyServiceEndpoint.xml"/>
</call>
<!-- the response is here, transform it has needed -->
<xslt key="myxsl"/>
<!-- send this response to the client -->
<property name="messageType" value="application/soap+xml" scope="axis2" type="STRING"/>
<!-- or test/xml and in this case, don't forget to specify a SOAP Action, below, a sample to specify a blank soapAction : -->
<header name="Action" value=""""/>
<send/>
Sample endpoint conf (with this sample, you need to define a property uri.var.ServiceURL in your sequence) :
<endpoint>
<http method="POST" uri-template="{uri.var.ServiceURL}/Path/2011-10-01"/>
</endpoint>
But if you really need your custom mediators, just replace payloadFactory and xslt mediators with them
Thanks for the reply, I still have to write custom mediator, just a very complex transformation messages
I will give an example how should I transform the message
SOAP message in my Proxy Service, send in custrom mediator
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AddPay xmlns="http://MyTestService">
<!--input dynamic data-->
<fields>
<Items>
<Data>
<Name>Field1</Name>
<Value>11</Value>
</Data>
<Data>
<Name>Field2</Name>
<Value>22</Value>
</Data>
</Items>
</fields>
</AddPay>
</soap:Body>
</soap:Envelope>
The result of the transformation of the mediator
0000035401SM000000970000009700000121
api99 00000990
00000000
BEGIN // <!--input dynamic data-->
FIELD1=11 // Soap data
FIELD2=22 // Soap data
END
BEGIN SIGNATURE
iQBRAwkBAAAD3j2r2NwBAeevAf4nvAG4rGAyAePHkyVKTt7wffzURhOckd3ctgmG
yQkKWkXh3CLpsbrExsllVUBlO6ih8qHozk2uttXApzHXQXoO
=+pch
END SIGNATURE
Request to the HTTP Server
POST /cgi-bin/es/es_pay_check.cgi HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 498
inputmessage=0000035401SM000000970000009700000121%0D%0Aapi99+
+++++++++++00000990%0D%0A++++++++++++++++++++00000000%0ABEGIN%0D%
0FIELD1%11%0FIELD2%220AEND%0D%0ABEGIN+SIGNATURE%0AiQBRAwkBAABCiUs
00dQBATG5AgDHdZ6RYHykL46QBaAvnHYaY4p0pDjgjO4K1Iyj%0D%0AfSBSvCRpS%2
F0EYO9NspuyLeANEQQkkGE%2F37gUxiPqzAgStXjpsAHH%0D%0A%3DvSgb%0AEND+
SIGNATURE
The response from the HTTP Server, pass in custrom mediator to transform into SOAP
0000030301SM000000460000004600000121
0J0005 00064182
00000000
BEGIN
DATE=04.10.2014 12:34:12
ERROR=0
ERRMSG=
FIELD3=33
FIELD4=44
FIELD5=55
END
BEGIN SIGNATURE
iQBRAwkBAAD6tj1BJ10BAYKxAfsHlQsEFnO2k6ry++W8O8AiJuv4gT+ZVCfZHsKk
c0CbZpP/W3vkljG3xNzMLiqjbwkNuIdwR9Dq7gHmH+ZQMhbT
=LOnP
END SIGNATURE
The result in the Proxy service
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<AddPayResponse xmlns="http://MyTestService">
<AddPayResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Data>
<Items>
<!--output dynamic data-->
<Data>
<Name>Field3</Name>
<Value>33</Value>
</Data>
<Data>
<Name>Field4</Name>
<Value>44</Value>
</Data>
<Data>
<Name>Field5</Name>
<Value>55</Value>
</Data>
</Items>
</Data>
<ErrCode>0</ErrCode>
<ErrMsg>Ok</ErrMsg>
</AddPayResult>
</AddPayResponse>
</s:Body>
</s:Envelope>

How to insert soap:Body content as a child to another tag

I have the following soap:body
<soapenv:Body>
<Message>
<Context>
<id>10</id>
<subject>sub10</subject>
<body>body10</body>
</Context>
</Message>
</soapenv:Body>
But I need to insert the content inside <SendMessageRequest> tag before sending to a request:
<soapenv:Body>
<SendMessageRequest>
<Message>
<Context>
<id>10</id>
<subject>sub10</subject>
<body>body10</body>
</Context>
</Message>
</SendMessageRequest>
</soapenv:Body>
I'm using the Enrich Mediator, but not figured out how to do this...
Here the code I'm trying:
<enrich>
<source type="body"/>
<target action="child" type="custom" xpath="SendMessageRequest"/>
</enrich>
You can't directly add an intermediate element. That is one that wraps your current content. Instead you can store your content-to-be-wrapped in a property. Note the use of the $body xpath variable (courtesy of the SynapseXPath class), which refers to the soap body element regardless of used soap version.
<property name="payload" expression="$body/*[1]" type="OM"/>
Then use the PayloadFactory mediator to construct your new request stub:
<payloadFactory>
<format>
<SendMessageRequest xmlns=""/>
</format>
<args/>
</payloadFactory>
Subsequently you can enrich your former content into the newly created payload.
<enrich>
<source clone="true" property="payload" type="property"/>
<target action="child" type="custom" xpath="$body/SendMessageRequest"/>
</enrich>

WSO2 how to solve scheduled task?

In wso2 esb 4.5.1, i don't have option of direct task scheduling for sequence or proxy service. so, i try to use property name SoapAction and to in task scheduling but iam getting the below error,
ERROR - TaskManagementHelper Invalid XML has been provided for property : message
ERROR - TaskManagementHelper Invalid XML has been provided for property : format
Here is a sample "Scheduled Task" that inject 2 times an XML message
<root>
<node1>value1</node1>
</root>
It works with ESB 4.5.1
<?xml version="1.0" encoding="UTF-8"?>
<task xmlns="http://ws.apache.org/ns/synapse"
name="TestTask"
class="org.apache.synapse.startup.tasks.MessageInjector"
group="synapse.simple.quartz">
<trigger count="2" interval="5"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="format"
value="application/xml"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="to"
value="TestTaskProxy"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
<root xmlns="">
<node1>value1</node1>
</root>
</property>
</task>
format and to properties are literal types
message property is an XML type