Wso2esb Transaction for local Database - wso2

I am really worrying about this future.If your developing some product like middleware you should aware of all the future like transaction,sec,.etc
security is good in wso2 where as transactions are really poor
i am using wso2esb4.8.0 and wso2dss3.0.1 .I wish to insert the data into my 2 tables simple logic if my 2nd table went wrong my first table also roll backed.For this i used wso2dss Box-carring future and its perfectly fine while i am doing from wso2dss try-it .BUt same future i wish to incorporate with wso2esb .i call 4 operation like beginboxcarring,insertintot1,insertintot2,endboxcarring but its not working in this then i got sloution with get JSESSIONID which will create when call a beginboxcarring but there is no use i tried with this properties to get JSESSIONID
and my proxy is
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TransactionProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full">
<property name="M1" value="*************HITTING Transaction PROXY*************"/>
</log>
<property name="OUT_ONLY" value="true"/>
<property name="companycode" expression="//companycode/text()"/>
<property name="companyname" expression="//companyname/text()"/>
<property name="clientcode" expression="//clientcode/text()"/>
<property name="clientname" expression="//clientname/text()"/>
<property name="session type"
value="JSESSIONID"
scope="default"
type="STRING"/>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body/>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<log level="full">
<property name="M2" value="*************HITTING Transaction PROXY*************"/>
</log>
<header name="Action" value="urn:begin_boxcar"/>
<property name="setCookieHeader"
expression="$trp:Set-Cookie"
scope="default"
type="STRING"/>
<callout serviceURL="http://localhosttt:9764/services/Transaction/begin_boxcar"
action="urn:begin_boxcar">
<source type="envelope"/>
<target xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
</callout>
<property name="setCookieHeader"
expression="$trp:Set-Cookie"
scope="default"
type="STRING"/>
<log level="full">
<property name="JSESSIONID" expression="get-property('setCookieHeader')"/>
</log>
<payloadFactory media-type="xml">
<format>
<p:insertinto_mclient_OP xmlns:p="http://ws.wso2.org/dataservice">
<xs:clientcode xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:clientcode>
<xs:clientname xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:clientname>
<xs:createdbyid xmlns:xs="http://ws.wso2.org/dataservice">-1</xs:createdbyid>
<xs:modifiedbyid xmlns:xs="http://ws.wso2.org/dataservice">-1</xs:modifiedbyid>
</p:insertinto_mclient_OP>
</format>
<args>
<arg evaluator="xml" expression="get-property('clientcode')"/>
<arg evaluator="xml" expression="get-property('clientname')"/>
</args>
</payloadFactory>
<header name="Action" value="urn:insertinto_mclient_OP"/>
<callout serviceURL="http://localhosttt:9764/services/Transaction/"
action="urn:insertinto_mclient_OP">
<source xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
<target xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
</callout>
<payloadFactory media-type="xml">
<format>
<p:insertinto_mcompany_OP xmlns:p="http://ws.wso2.org/dataservice">
<xs:companycode xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:companycode>
<xs:comapnyname xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:comapnyname>
<xs:createdbyid xmlns:xs="http://ws.wso2.org/dataservice">-1</xs:createdbyid>
<xs:modifiedbyid xmlns:xs="http://ws.wso2.org/dataservice">-1</xs:modifiedbyid>
<xs:clientid xmlns:xs="http://ws.wso2.org/dataservice">-1</xs:clientid>
</p:insertinto_mcompany_OP>
</format>
<args>
<arg evaluator="xml" expression="get-property('companycode')"/>
<arg evaluator="xml" expression="get-property('companyname')"/>
</args>
</payloadFactory>
<log level="full">
<property name="M5" value="**************hitting2nd dss*****"/>
</log>
<header name="Action" value="urn:insertinto_mcompany_OP"/>
<callout serviceURL="http://localhosttt:9764/services/Transaction/"
action="urn:insertinto_mcompany_OP">
<source xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
<target xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
</callout>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body/>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<log level="full">
<property name="M3" value="*************HITTING Transaction PROXY*************"/>
</log>
<header name="Action" value="urn:end_boxcar"/>
<callout serviceURL="http://localhosttt:9764/services/Transaction/end_boxcar"
action="urn:end_boxcar">
<source type="envelope"/>
<target xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
</callout>
<log level="full">
<property name="M4" value="*************HITTING Transaction PROXY*************"/>
</log>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<description/>
</proxy>
but log is showing JSESSIONID=null
and even i tried this properties also no change in log
<property name="setCookieHeader"
expression="get-property('transport','Set-Cookie')"
scope="default"
type="STRING"/>
<property name="setCookieHeader5"
expression="get-property('transport','JSESSIONID')"
scope="default"
type="STRING"/>
how would i get if i call from CURL the dss operation begin_boxcarring end point giving like this in header
Set-Cookie: JSESSIONID=6776AC50E31EBFC456CDA1895ACDE0B8; Path=/; HttpOnly
but unable to get into synapse how would i get .is there any option for transaction really worried about this future in wso2

Related

WSO2 ESB does not sent a clinicId param to WSO2 DSS

In WSO2 configured proxy service, does not send the clinicId param to DSS. In logs from DSS gives exception :
Default Namespace: https://bur.test.ru/dss/services/tfoms
Current Request Name: get_single_inserted_branch_by_id
Current Params: {clinicID=}
Nested Exception:-
java.lang.NumberFormatException: For input string: ""
In logs from ESB:
Nested Exception:-
javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processPreNormalQuery': For input string: ""
DS Code: DATABASE_ERROR
Source Data Service:-
Name: TEST
Location: \TEST.dbs
Description: Service generates hospitalisation&
Default Namespace: https://bur.TEST.ru/dss/services/tfoms
Current Request Name: get_single_inserted_branch_by_id
Current Params: {clinicID=}
Nested Exception:-
java.lang.NumberFormatException: For input string: ""
On WSO2 DSS it works good and it takes info from postgres.
Here is a code of proxy servise from WSO2 ESB:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="BurProxy"
transports="http,https"
statistics="disable"
trace="enable"
startOnLoad="true">
<target>
<inSequence>
<property name="CLINIC_ID"
expression="//clinicID/text()"
scope="axis2"
type="STRING"/>
<log level="full">
<property name="CLINIC_ID" expression="clinicID"/>
</log>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tfom="https://bur.cdmarf.ru/dss/services/tfoms">
<soapenv:Header/>
<soapenv:Body>
<tfom:get_single_inserted_branch_by_id>
<tfom:clinicID>$1</tfom:clinicID>
</tfom:get_single_inserted_branch_by_id>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$axis2:CLINIC_ID"/>
</args>
</payloadFactory>
<log>
<property name="PAYLOAD" expression="$body"/>
</log>
<call blocking="true">
<endpoint key="dss"/>
</call>
<xslt key="xslt-remove-namespace"/>
<property name="messageType" value="text/xml" scope="axis2"/>
<property name="contentType" value="text/xml" scope="axis2"/>
<property name="rabbitmq.attributes.app.id"
value="RMIS"
scope="axis2"
type="STRING"/>
<property name="rabbitmq.attributes.type"
value="BRANCH"
scope="axis2"
type="STRING"/>
<property name="rabbitmq.attributes.user.id"
value="rmis"
scope="axis2"
type="STRING"/>
<property name="MESSAGE_ID" expression="get-property('MessageID')"/>
<script language="js">var messageID = mc.getProperty('MESSAGE_ID').substring(9,45);
mc.setProperty("RABBIT_MESSAGE_ID", messageID);</script>
<property name="rabbitmq.attributes.custom.message.id"
expression="get-property('RABBIT_MESSAGE_ID')"
scope="axis2"/>
<clone continueParent="true">
<target sequence="writeToFile"/>
</clone>
<send>
<endpoint key="rabbit"/>
</send>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tfom="https://bur.cdmarf.ru/dss/services/tfoms">
<soapenv:Header/>
<soapenv:Body>
<tfom:get_inserted_divisions_of_clinic>
<tfom:clinicID>$1</tfom:clinicID>
</tfom:get_inserted_divisions_of_clinic>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$axis2:CLINIC_ID"/>
</args>
</payloadFactory>
<call blocking="true">
<endpoint key="dss"/>
</call>
<iterate xmlns:tfoms="https://bur.cdmarf.ru/dss/services/tfoms"
continueParent="true"
expression="//tfoms:DIVISION"
sequential="true">
<target>
<sequence>
<property name="rabbitmq.attributes.type"
value="DIVISION"
scope="axis2"
type="STRING"/>
<property name="messageType" value="xml" scope="axis2"/>
<property name="contentType" value="xml" scope="axis2"/>
<property name="MESSAGE_ID" expression="get-property('MessageID')"/>
<script language="js">var messageID = mc.getProperty('MESSAGE_ID').substring(9,45);
mc.setProperty("RABBIT_MESSAGE_ID", messageID);</script>
<property name="rabbitmq.attributes.custom.message.id"
expression="get-property('RABBIT_MESSAGE_ID')"
scope="axis2"/>
<xslt key="xslt-remove-namespace"/>
<clone continueParent="true">
<target sequence="writeToFile"/>
</clone>
<send>
<endpoint key="rabbit"/>
</send>
</sequence>
</target>
</iterate>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tfom="https://bur.cdmarf.ru/dss/services/tfoms">
<soapenv:Body>
<tfom:get_inserted_liks_division_to_bed>
<tfom:clinicID>$1</tfom:clinicID>
</tfom:get_inserted_liks_division_to_bed>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$axis2:CLINIC_ID"/>
</args>
</payloadFactory>
<call blocking="true">
<endpoint key="dss"/>
</call>
<iterate xmlns:tfoms="https://bur.cdmarf.ru/dss/services/tfoms"
continueParent="true"
expression="//tfoms:DIVISION_LINK_STRUCTURE_BED"
sequential="true">
<target>
<sequence>
<property name="rabbitmq.attributes.type"
value="DIVISION_LINK_STRUCTURE_BED"
scope="axis2"
type="STRING"/>
<property name="messageType" value="xml" scope="axis2"/>
<property name="contentType" value="xml" scope="axis2"/>
<property name="MESSAGE_ID" expression="get-property('MessageID')"/>
<script language="js">var messageID = mc.getProperty('MESSAGE_ID').substring(9,45);
mc.setProperty("RABBIT_MESSAGE_ID", messageID);</script>
<property name="rabbitmq.attributes.custom.message.id"
expression="get-property('RABBIT_MESSAGE_ID')"
scope="axis2"/>
<xslt key="xslt-remove-namespace"/>
<clone continueParent="true">
<target sequence="writeToFile"/>
</clone>
<send>
<endpoint key="rabbit"/>
</send>
</sequence>
</target>
</iterate>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tfom="https://bur.cdmarf.ru/dss/services/tfoms">
<soapenv:Body>
<tfom:get_inserted_amound_bed>
<tfom:clinicID>$1</tfom:clinicID>
</tfom:get_inserted_amound_bed>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$axis2:CLINIC_ID"/>
</args>
</payloadFactory>
<call blocking="true">
<endpoint key="dss"/>
</call>
<iterate xmlns:tfoms="https://bur.cdmarf.ru/dss/services/tfoms"
continueParent="true"
expression="//tfoms:AMOUNT_BED"
sequential="true">
<target>
<sequence>
<property name="rabbitmq.attributes.type"
value="AMOUNT_BED"
scope="axis2"
type="STRING"/>
<property name="messageType" value="xml" scope="axis2"/>
<property name="contentType" value="xml" scope="axis2"/>
<property name="MESSAGE_ID" expression="get-property('MessageID')"/>
<script language="js">var messageID = mc.getProperty('MESSAGE_ID').substring(9,45);
mc.setProperty("RABBIT_MESSAGE_ID", messageID);</script>
<property name="rabbitmq.attributes.custom.message.id"
expression="get-property('RABBIT_MESSAGE_ID')"
scope="axis2"/>
<xslt key="xslt-remove-namespace"/>
<clone continueParent="true">
<target sequence="writeToFile"/>
</clone>
<send>
<endpoint key="rabbit"/>
</send>
</sequence>
</target>
</iterate>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
For a request like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tfom="bur.cdmarf.ru/dss/services/tfoms">
<soapenv:Header/>
<soapenv:Body>
<tfom:get_inserted_amound_bed>
<tfom:clinicID>6048820</tfom:clinicID>
</tfom:get_inserted_amound_bed>
</soapenv:Body>
</soapenv:Envelope>
Yo can use this mediators to capture and log the clinic_id value:
<property name="CLINIC_ID" xmlns:tfom="bur.cdmarf.ru/dss/services/tfoms"
expression="//tfom:get_inserted_amound_bed/tfom:clinicID"
scope="default"
type="STRING"/>
<log level="custom">
<property name="CLINIC_ID_PROPERTY_VALUE" expression="get-property('CLINIC_ID')"/>
</log>
<log>
<property name="PAYLOAD" expression="$body"/>
</log>
In the payload factory mediator use the same expression to capture the clinic id value:
<args>
<arg evaluator="xml" expression="get-property('CLINIC_ID')"/>
</args>

How to respond with status 500 (server error) when proxy fails?

In our test environment we build a one-way proxy service that uses callout to get data from several other services. Now when one of those services fails wso2 proxy sends 202 accepted anyway. Is it possible to "catch exceptions" and return a different status?
I know that in this case it would be better to use a request-response proxy, but even if we would create a proxy that only stores the payload in a messagestore there could be issues regarding database where the payload would be stored (database is down, etc) and we don't want status 202 to be returned if the message was not stored in db.
edit:
Here is my proxy after changes suggested in first answer to my question:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="notifyOfClaimChangeOut" serviceGroup="" startOnLoad="true"
trace="disable" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property description="OUT_ONLY" name="OUT_ONLY" scope="default"
type="BOOLEAN" value="true"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" scope="default"
type="STRING" value="true"/>
<property description="OriginalPayload" expression="$body"
name="OriginalPayload" scope="default" type="STRING"/>
<iterate description=""
expression="$body//InsClaimData/PartnerList/PartnerEntry" id="" sequential="true">
<target>
<sequence>
<payloadFactory description="" media-type="xml">
<format>
<plat:FindCustomerSync xmlns:plat="http://platform.###.pl/">
<plat:request>
<plat:FirstName>$1</plat:FirstName>
<plat:LastName>$2</plat:LastName>
<plat:Pesel>$3</plat:Pesel>
</plat:request>
</plat:FindCustomerSync>
</format>
<args>
<arg evaluator="xml" expression="$body/PartnerEntry/BusinessPartner/personData/firstName"/>
<arg evaluator="xml" expression="$body/PartnerEntry/BusinessPartner/personData/lastName"/>
<arg evaluator="xml" expression="$body/PartnerEntry/BusinessPartner/personData/PESEL"/>
</args>
</payloadFactory>
<log level="custom">
<property expression="$body" name="property_name"/>
</log>
<callout action="http://platform.###.pl/FindCustomerSync"
description="QueryCustomersOut"
endpointKey="gov:###/endpoints/###/QueryCustomersOut.xml" initAxis2ClientOptions="false">
<source type="envelope"/>
<target key="QueryCustomersOutResponse"/>
</callout>
<log description="" level="custom" separator=",">
<property expression="$ctx:QueryCustomersOutResponse"
name="QueryCustomersOut"
xmlns:cla="http://###.###.io/service/internal/ClaimService" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>
</log>
</sequence>
</target>
</iterate>
<!--
<callout description="ClaimService"
endpointKey="gov:###/endpoints/###/ClaimService.xml" initAxis2ClientOptions="false">
<source type="envelope"/>
<target key="ClaimServiceResponse"/>
</callout>
<log description="ClaimService Response" level="custom">
<property expression="$ctx:ClaimServiceResponse" name="ClaimServiceResponse"/>
</log>
-->
<drop/>
</inSequence>
<outSequence/>
<faultSequence>
<property name="HTTP_SC" scope="axis2" type="STRING" value="500"/>
<log>
<property name="Error" value="Fault :("/>
</log>
</faultSequence>
</target>
<publishWSDL key="gov:###/schemas/###/ClaimService.wsdl"/>
</proxy>
You can use the HTTP_SC property to send status 500. You'll also need the makefault mediator to construct the fault message.
<property name="HTTP_SC" value="500" scope="axis2"/>
<makefault version="soap11">
You can refer this jira to get an idea.
In addition, in the inSequence, you may need to set FORCE_ERROR_ON_SOAP_FAULT property to move to the fault sequence when a soap fault occurs. Some explanation available here.
<inSequence>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
</inSequence>

Sometimes receiving:" Error while performing the callout operation" when using callout mediator in a proxy

Sometimes when I am using Callout mediator I am receiving this message specially if I have made previous calls/callouts before in the sequence.
This is the message I receive: ERROR_CODE = 0, ERROR_MESSAGE = Error while performing the callout operation.
This specially occurs when using chaining within proxies.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="InsChildCustomer"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full" separator=", ***********Incoming###########"/>
<property name="originalMessage"
expression="$body"
scope="default"
type="OM"/>
<property xmlns:cus="http://www.example.org/customerWSO2/"
name="SNIPPMessage"
expression="$body/cus:insertChildCustToNSRequest"
scope="default"
type="OM"/>
<sequence key="conf:/resources/sequences/InsChildCustomerHeaderSeq.xml"/>
<filter xmlns:cus="http://www.example.org/customerWSO2/"
source="boolean(//cus:insertChildCustToNSRequest/cus:childCustData/cus:customerContacts/cus:customerContact[1]/cus:email)"
regex="true">
<then>
<property name="customerContacts"
expression="//cus:insertChildCustToNSRequest/cus:childCustData/cus:customerContacts"
scope="default"
type="OM"/>
</then>
<else>
<property name="noContacts" value="1" scope="default" type="INTEGER"/>
</else>
</filter>
<header name="Action" scope="default" value="addList"/>
<payloadFactory media-type="xml">
<format>
<addressbook xmlns=""
xmlns:platformCommon="urn:common_2015_1.platform.webservices.NS.com"
xmlns:listRel="urn:relationships_2015_1.lists.webservices.NS.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:platformCore="urn:core_2015_1.platform.webservices.NS.com"
xsi:type="listRel:CustomerAddressbook">
<defaultBilling>$1</defaultBilling>
<defaultShipping>$2</defaultShipping>
<addressbookAddress xsi:type="platformCommon:Address">
<addr1>$3</addr1>
<addr2>$4</addr2>
<addr3>$5</addr3>
<customFieldList>
<customField scriptId="custrecord_addr_4"
xsi:type="platformCore:StringCustomFieldRef">
<value>$6</value>
</customField>
</customFieldList>
<city>$7</city>
<state>$8</state>
<zip>$9</zip>
<country>$10</country>
</addressbookAddress>
</addressbook>
</format>
<args>
<arg evaluator="xml" expression="//cus:billingaddressindicator/text()"/>
<arg evaluator="xml" expression="//cus:shippingaddressindicator/text()"/>
<arg evaluator="xml" expression="//cus:addr1/text()"/>
<arg evaluator="xml" expression="//cus:addr2/text()"/>
<arg evaluator="xml" expression="//cus:addr3/text()"/>
<arg evaluator="xml" expression="//cus:custrecord_addr_4/text()"/>
<arg evaluator="xml" expression="//cus:city/text()"/>
<arg evaluator="xml" expression="//cus:state/text()"/>
<arg evaluator="xml" expression="//cus:zip/text()"/>
<arg evaluator="xml" expression="//cus:country/text()"/>
</args>
</payloadFactory>
<send>
<endpoint key="conf:/resources/endpoints/NSEndpoint.xml"/>
</send>
</inSequence>
<outSequence>
<header xmlns:platformMsgs="urn:messages_2015_1.platform.webservices.NS.com"
name="platformMsgs:documentInfo"
scope="default"
action="remove"/>
<property xmlns:platformMsgs="urn:messages_2015_1.platform.webservices.NS.com"
xmlns:platformCore="urn:core_2015_1.platform.webservices.NS.com"
name="isSuccess"
expression="//addListResponse/platformMsgs:writeResponseList/platformMsgs:writeResponse/platformCore:status/#isSuccess"
scope="default"
type="STRING"/>
<filter xmlns:platformMsgs="urn:messages_2015_1.platform.webservices.NS.com"
xmlns:platformCore="urn:core_2015_1.platform.webservices.NS.com"
source="//addListResponse/platformMsgs:writeResponseList/platformMsgs:writeResponse/platformCore:status/#isSuccess"
regex="true">
<then>
<log level="full" separator=", *******before_iterator********"/>
<property name="customerInternalId"
expression="//addListResponse/platformMsgs:writeResponseList/platformMsgs:writeResponse/platformMsgs:baseRef/#internalId"
scope="default"
type="STRING"/>
<header name="platformMsgs:platformMsgs:documentInfo"
scope="default"
action="remove"/>
<property name="type"
expression="//addListResponse/platformMsgs:writeResponseList/platformMsgs:writeResponse/platformMsgs:baseRef/#type"
scope="default"
type="STRING"/>
<payloadFactory media-type="xml">
<format>
<urn:get xmlns:urn="urn:messages_2015_1.platform.webservices.NS.com"
xmlns:urn1="urn:core_2015_1.platform.webservices.NS.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<urn:baseRef internalId="$1" type="customer" xsi:type="urn1:RecordRef">
<urn1:name/>
</urn:baseRef>
</urn:get>
</format>
<args>
<arg evaluator="xml" expression="get-property('customerInternalId')"/>
</args>
</payloadFactory>
<header name="Action" scope="default" value="get"/>
<sequence key="conf:resources/sequences/customerAddPassport.xml"/>
<sequence key="conf:resources/sequences/customerAddPreferences.xml"/>
<callout endpointKey="conf:/resources/endpoints/NSEndpoint.xml">
<endpoint name="NSEndpoint">
<address uri="https://webservices.sandbox.NS.com/services/NSPort_2015_1"/>
</endpoint>
<source type="envelope"/>
<target xpath="$body/*"/>
</callout>
<property xmlns:ns="urn:messages_2015_1.platform.webservices.NS.com"
xmlns:listRel="urn:relationships_2015_1.lists.webservices.NS.com"
name="customerEntityId"
expression="//ns:getResponse/ns:readResponse/ns:record/listRel:entityId"
scope="default"
type="STRING"/>
<log level="full" separator=", After_Get"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<cus:insertChildCustToNSRequest xmlns:cus="http://www.example.org/customerWSO2/">$1
<cus:transactionid>$2</cus:transactionid>
<InternalID xmlns="">$3</InternalID>
</cus:insertChildCustToNSRequest>
</format>
<args>
<arg xmlns:cus="http://www.example.org/customerWSO2/"
evaluator="xml"
expression="$ctx:SNIPPMessage//cus:childCustData"/>
<arg xmlns:cus="http://www.example.org/customerWSO2/"
evaluator="xml"
expression="$ctx:SNIPPMessage//cus:transactionid"/>
<arg evaluator="xml" expression="get-property('customerInternalId')"/>
</args>
</payloadFactory>
<header xmlns:urn="urn:messages_2015_1.platform.webservices.NS.com"
name="urn:passport"
scope="default"
action="remove"/>
<header xmlns:urn="urn:messages_2015_1.platform.webservices.NS.com"
name="urn:preferences"
scope="default"
action="remove"/>
<log level="full" separator=", before SNIPP CALL"/>
<call>
<endpoint key="conf:/resources/endpoints/Teacher.QEndpoint.xml"/>
</call>
<property name="OUT_ONLY" value="false" scope="default" type="STRING"/>
<property name="DISABLE_CHUNKING"
value="false"
scope="axis2"
type="STRING"/>
<property name="messageType" value="text/xml" scope="axis2" type="STRING"/>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<filter source="get-property('noContacts')" regex="1">
<then>
<log level="full" separator=", *******without_contacts********"/>
<enrich>
<source type="inline" clone="true">
<insertChildCustToNSResponse xmlns="">
<Type/>
<Status/>
<CustomerInternalId/>
<CustomerEntityId/>
<ContactInternalId>N.A.</ContactInternalId>
</insertChildCustToNSResponse>
</source>
<target type="body"/>
</enrich>
<enrich>
<source type="property" clone="true" property="type"/>
<target xpath="//insertChildCustToNSResponse/Type"/>
</enrich>
<enrich>
<source type="property" clone="true" property="isSuccess"/>
<target xpath="//insertChildCustToNSResponse/Status"/>
</enrich>
<enrich>
<source type="property" clone="true" property="customerInternalId"/>
<target xpath="//insertChildCustToNSResponse/CustomerInternalId"/>
</enrich>
<enrich>
<source type="property" clone="true" property="customerEntityId"/>
<target xpath="//insertChildCustToNSResponse/CustomerEntityId"/>
</enrich>
</then>
<else>
<log level="full" separator=", *******with_contacts********"/>
<drop/>
</else>
</filter>
</then>
<else>
<log level="full" separator=", From false###########"/>
<property name="errorCode"
expression="//addListResponse/platformMsgs:writeResponseList/platformMsgs:writeResponse/platformCore:status/platformCore:statusDetail/platformCore:code"
scope="default"
type="STRING"/>
<property name="errorMessage"
expression="//addListResponse/platformMsgs:writeResponseList/platformMsgs:writeResponse/platformCore:status/platformCore:statusDetail/platformCore:message"
scope="default"
type="STRING"/>
<enrich>
<source type="inline" clone="true">
<insertChildCustToNSResponse xmlns="">
<Status/>
<ErrorCode/>
<ErrorMessage/>
</insertChildCustToNSResponse>
</source>
<target type="body"/>
</enrich>
<enrich>
<source type="property" clone="true" property="isSuccess"/>
<target xpath="//insertChildCustToNSResponse/Status"/>
</enrich>
<enrich>
<source type="property" clone="true" property="errorCode"/>
<target xpath="//insertChildCustToNSResponse/ErrorCode"/>
</enrich>
<enrich>
<source type="property" clone="true" property="errorMessage"/>
<target xpath="//insertChildCustToNSResponse/ErrorMessage"/>
</enrich>
</else>
</filter>
<send/>
</outSequence>
</target>
<publishWSDL key="conf:/resources/wsdls/Customer.wsdl"/>
<parameter name="serviceType">proxy</parameter>
<description/>
</proxy>
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="ChildCustomerToSnipp"
transports="jms"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="customerInternalId"
expression="//InternalID"/>
<log level="full" separator="**Consumed from IN MQ before Seq**"/>
<sequence key="ConvertCustomerSoapToJSONSeq"/>
</inSequence>
<outSequence>
<log level="full" separator="**Consumed from OUT Seq**"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="snippMemberId"
expression="json-eval($.Data)"/>
<log level="custom" separator="**From Out Seq before Update**">
<property xmlns:ns="http://org.apache.synapse/xsd"
name="DataProperty"
expression="get-property('snippMemberId')"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="customerInternalId"
expression="get-property('customerInternalId')"/>
</log>
<sequence key="UpdateSnippMemeber"/>
</outSequence>
</target>
<parameter name="transport.jms.ContentType">text/xml</parameter>
<parameter name="transport.jms.Destination">Teacher.Q</parameter>
<description/>
</proxy>

Iterate Mediator sends duplicate payload almost always

We are trying out a scenario where we want to iterate over a list of nodes and make a POST call to some service with each individual request payload. We are seeing the iterate mediator actually sends two elements in that call and
that causes issues on the API end.
I have a mock service deployed locally that returns response say :
<result>
<row>
<product_id>8351</product_id>
<event_key>17708</event_key>
<event_code>AEONBM</event_code>
<show_title>Some Show</show_title>
<venue_name>Eugene ONeill Theatre</venue_name>
<area>ORCHC</area>
<row>C</row>
<seat_num>103</seat_num>
<seat_increment>1</seat_increment>
<marketing_code>PREMIUM</marketing_code>
<Cost>352.0000</Cost>
</row>
<row>
<product_id>8351</product_id>
<event_key>17708</event_key>
<event_code>AEONBM</event_code>
<show_title>Some Show</show_title>
<venue_name>Eugene ONeill Theatre</venue_name>
<area>ORCHC</area>
<row>C</row>
<seat_num>104</seat_num>
<seat_increment>1</seat_increment>
<marketing_code>PREMIUM</marketing_code>
<Cost>352.0000</Cost>
</row
</result>
Here is how my proxy service looks like:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="CreateListingFromGetLocation"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full">
<property name="text" value="Triggering getLocation API call.."/>
</log>
<send receive="createListingsFromGetLocationResponseSequence">
<endpoint>
<http method="get" uri-template="http://localhost:8989/GetLocation/"/>
</endpoint>
</send>
<property name="OUT_ONLY" value="true"/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
<description/>
</proxy>
Here is my receiving sequence that is using the iterate mediator:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="createListingsFromGetLocationResponseSequence">
<iterate xmlns:tem="http://tempuri.org" xmlns:ns="http://org.apache.synapse/xsd" expression="//result/row">
<target>
<sequence>
<log level="full">
<property name="LocationRow" value="Row element from GetLocationResponse"></property>
</log>
<payloadFactory media-type="xml">
<format>
<listing xmlns="">
<eventId>$1</eventId>
<eventDescription>$2</eventDescription>
<pricePerTicket>
<amount>$3</amount>
<currency>USD</currency>
</pricePerTicket>
<quantity>$4</quantity>
<section>$5</section>
<rows>$6</rows>
<seats>$7</seats>
<splitOption>NONE</splitOption>
</listing>
</format>
<args>
<arg expression="//event_key" evaluator="xml"></arg>
<arg expression="//show_title" evaluator="xml"></arg>
<arg expression="//Cost" evaluator="xml"></arg>
<arg expression="//seat_increment" evaluator="xml"></arg>
<arg expression="//area" evaluator="xml"></arg>
<arg expression="//row/row" evaluator="xml"></arg>
<arg expression="//seat_num" evaluator="xml"></arg>
</args>
</payloadFactory>
<log level="full">
<property name="ListingRequest" value="Listing request xml"></property>
</log>
<property name="Content-Type" value="application/xml" scope="transport" type="STRING"></property>
<property name="messageType" value="application/xml" scope="transport" type="STRING"></property>
<property name="TARGET_HOST" value="srwd30" scope="transport" type="STRING"></property>
<property name="HTTP_METHOD" value="POST" scope="transport" type="STRING"></property>
<send>
<endpoint>
<http format="pox" method="post" uri-template="http://www.srwd30.com/listings/v1/"></http>
</endpoint>
</send>
</sequence>
</target>
</iterate>
</sequence>
Firstly, I see that it is iterating over each xml node properly, here are some logs indicating that:
[2014-04-22 13:29:42,020] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:3bc14a33-3a7a-478e-bdbf-720f1ec855a5, Direction: response, LocationRow = Row element from GetLocationResponse, Envelope: <?xml version="1.0" encoding="utf-8
"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><row>
<product_id>8351</product_id>
<event_key>17708</event_key>
<event_code>AEONBM</event_code>
<show_title>Some Show</show_title>
<venue_name>Eugene ONeill Theatre</venue_name>
<area>ORCHC</area>
<row>D</row>
<seat_num>103</seat_num>
<seat_increment>1</seat_increment>
<marketing_code>PREMIUM</marketing_code>
<Cost>352.0000</Cost>
</row></soapenv:Body></soapenv:Envelope>
[2014-04-22 13:29:42,021] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:0e04ac15-a0bf-41a3-a7d7-80a1401d3efc, Direction: response, ListingRequest = Listing request xml, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:En
velope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><listing><eventId>17708</eventId><eventDescription>Some Show</eventDescription><pricePerTicket><amount>352.0000</amount><currency>USD</currency></pricePerTicket><quantity>1</quantity><section>ORCHC</section><rows
>C</rows><seats>103</seats><splitOption>NONE</splitOption></listing></soapenv:Body></soapenv:Envelope>
But on my API I see that we are receiving duplicate or two root nodes:
Content-Type: application/xml
Headers: {cache-control=[no-cache], connection=[Keep-Alive],
content-type=[application/xml], host=[www.srwd30.com], http_method=[POST], messagetype=[application/xml], target_host=[srwd30], transfer-encoding=
[chunked], user-agent=[Synapse-PT-HttpComponents-NIO]}
Payload: <listing><eventId>17708</eventId><eventDescription>Some Show</eventDescription><pricePerTicket><amount>352.0000</amount><currency>USD</currenc
y></pricePerTicket><quantity>1</quantity><section>ORCHC</section><rows>C</rows><seats>103</seats><splitOption>NONE</splitOption></listing><listing><eventId>1770
8</eventId><eventDescription>Some Show</eventDescription><pricePerTicket><amount>352.0000</amount><currency>USD</currency></pricePerTicket><quantity>1<
/quantity><section>ORCHC</section><rows>D</rows><seats>104</seats><splitOption>NONE</splitOption></listing>
--------------------------------------
2014-04-22 19:01:51,468 [e14f#fbf/http://www.srwd30.com/listings/v1/] priority=WARN app_name=shared-stubhubjobs thread=http-0.0.0.0-
8080-8 location=AbstractJAXBProvider line=112 javax.xml.bind.UnmarshalException
- with linked exception:
[com.ctc.wstx.exc.WstxParsingException: Illegal to have multiple roots (start tag in epilog?).
at [row,col {unknown-source}]: [1,291]]
From the looks of it, iterator is sending two elements when I make that send call. Am i missing something or doing something wrong? How can make each call independent from other?
I got the issue resolved by adding a Action header using urn:test value for that header. I realized that this was causing that duplicate requests to be sent and sometimes only one request being sent even if the iterator has about 10 records.
<proxy name="PushInventory"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<log level="full">
<property name="STATUS"
value="+++++++++++++++++ Inside PushInventory Proxy Service ++++++++++++++++++"/>
</log>
<iterate xmlns:tem="http://tempuri.org"
xmlns:ns="http://org.apache.synapse/xsd"
id="pushInventoryIterator"
expression="//result/row"
sequential="true">
<target>
<sequence>
<payloadFactory media-type="xml">
<format>
<listing xmlns="">
<eventId>$1</eventId>
<eventDescription>$2</eventDescription>
<pricePerTicket>
<amount>$3</amount>
<currency>USD</currency>
</pricePerTicket>
<quantity>$4</quantity>
<section>$5</section>
<rows>$6</rows>
<seats>$7</seats>
<splitOption>NONE</splitOption>
</listing>
</format>
<args>
<arg evaluator="xml" expression="//event_key"/>
<arg evaluator="xml" expression="//show_title"/>
<arg evaluator="xml" expression="//Cost"/>
<arg evaluator="xml" expression="//seat_increment"/>
<arg evaluator="xml" expression="//area"/>
<arg evaluator="xml" expression="//row_desc"/>
<arg evaluator="xml" expression="//seat_num"/>
</args>
</payloadFactory>
<log level="full">
<property name="STATUS"
value="++++++++++++ Invoking Listing EndPoint ++++++++++++++"/>
</log>
<property name="Authorization"
value="Basic dafdsfadsfdsafdsfdsafdsafsdfadsf"
scope="transport"
type="STRING"/>
<property name="Content-Type"
value="application/xml"
scope="transport"
type="STRING"/>
<property name="messageType"
value="application/xml"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="transport" type="STRING"/>
<header name="Action" scope="default" value="urn:test"/>
<send>
<endpoint key="ListingEndPoint"/>
</send>
</sequence>
</target>
</iterate>
</inSequence>
<outSequence>
<log level="full">
<property name="STATUS"
value="+++++++++++++++++ Inside OutSequence of PushInventory ++++++++++++++++++"/>
</log>
<aggregate>
<completeCondition>
<messageCount min="10" max="10"/>
</completeCondition>
<onComplete xmlns:ns2="com.blah.blah" expression="//listing">
<log level="full" separator=",">
<property name="STATUS"
value="+++++++++++++++++ Aggregating responses back ++++++++++++++++++"/>
</log>
<enrich>
<source type="envelope" clone="true"/>
<target type="body"/>
</enrich>
<send/>
</onComplete>
</aggregate>
</outSequence>
</target>
</proxy>
You put your log before the iterator mediator and see what you're receiving from the endpoint. It may contain duplicate entries. Then within iterate you have another log mediator. Check for records are right.

How Can I handle Error sequence in WSO2ESB

i want handle error using fault sequence but i wish to customize it with delete operation
my scenario is while i am inserting in 2 tables if error occurred in 2nd table insertion i need to delete 1 st row insertion also my config is below
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ErrorHandling" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target >
<inSequence onError="fault">
<property name="eno" expression="//eno/text()" scope="default" type="STRING"/>
<property name="ename" expression="//ename/text()" scope="default" type="STRING"/>
<property name="esal" expression="//esal/text()" scope="default" type="STRING"/>
<property name="deptname" expression="//deptname/text()" scope="default" type="STRING"/>
<property name="deptid" expression="//deptid/text()" scope="default" type="STRING"/>
<payloadFactory>
<format>
<p:insert_emp_operation xmlns:p="http://ws.wso2.org/dataservice">
<xs:eno xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:eno>
<xs:ename xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:ename>
<xs:esal xmlns:xs="http://ws.wso2.org/dataservice">$3</xs:esal>
</p:insert_emp_operation>
</format>
<args>
<arg expression="get-property('eno')"/>
<arg expression="get-property('ename')"/>
<arg expression="get-property('esal')"/>
</args>
</payloadFactory>
<send receive="Error_Seq">
<endpoint>
<address uri="http://localhost:9764/services/emp_DataService/" format="soap11"/>
</endpoint>
</send>
<log level="full"/>
</inSequence>
<outSequence onError="fault">
<send/>
<log level="full"/>
</outSequence>
</target>
<description></description>
</proxy>
and sequence is like this
<sequence xmlns="http://ws.apache.org/ns/synapse" name="Error_Seq" onError="fault">
<property xmlns:f="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" name="ID" expression="//f:ID/text()" scope="default" type="STRING"/>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="faisal" expression="get-property('ID')"/>
</log>
<payloadFactory>
<format>
<p:insert_dept_operation xmlns:p="http://ws.wso2.org/dataservice">
<xs:deptno xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:deptno>
<xs:deptname xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:deptname>
<xs:deptid xmlns:xs="http://ws.wso2.org/dataservice">$3</xs:deptid>
</p:insert_dept_operation>
</format>
<args>
<arg xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('ID')"/>
<arg xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('deptname')"/>
<arg xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('deptid')"/>
</args>
</payloadFactory>
<send>
<endpoint>
<address uri="http://localhost:9764/services/dept_DataService/" format="soap11"/>
</endpoint>
</send>
</sequence>
fault sequenceis like this
<sequence xmlns="http://ws.apache.org/ns/synapse" name="fault">
<property xmlns:ns="http://org.apache.synapse/xsd" name="ID" expression="get-property('ID')" scope="default" type="STRING"/>
<log level="full">
<property name="MESSAGE" value="Executing default 'fault' sequence"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Property" expression="get-property('ID')"/>
</log>
<payloadFactory>
<format>
<p:Delete_Op xmlns:p="http://ws.wso2.org/dataservice">
<xs:eno xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:eno>
</p:Delete_Op>
</format>
</payloadFactory>
<send>
<endpoint>
<address uri="http://localhost:9764/services/dept_DataService/" format="soap11"/>
</endpoint>
</send>
</sequence>
but its not working its working while the DSS Is in OFF mode let me know when DSS is In Running mode how to delete the 1st table row
In your scenario when update fails at DSS, it will send back a SOAP fault to the ESB.
Since ESB this is still just another message response, and it will not goto the fault sequence, unless you explicitly check the message and do the necessary actions.
So you have to declare comming message is a SOAP_FAULT so you hace to say it is a SOAP_FAULT and force it to error sequance. This is explained in [1].
[1] http://maharachchi.blogspot.com/2012/09/now-you-can-send-soapfaults-to-fault.html