How to combine two queries in wso2 esb - wso2

I am new with wso2 and probably my problem is very easy, but I've been fighting this for a week. The problem is that I have to combine two payloads in ESB 4.9.0.
I've tried enriching, making new payloadFactory with parameters from previous queries, but it all didn't make it in the way I want. The problem is that I have to get student data from DS and generate password from API (based on student id). All has to be combined in one payload and forwarded to xslt transformation. From DS I'm getting for example this:
<student>
<try>
<st_id>123456</st_id>
<name>Michael</name>
<surname>Smith</surname>
<email>email#email.com</email>
<ssn>123456789</ssn>
<faculty name="IT">
<field>Programming</field>
<f_code>IT-1234-19</f_code>
</faculty>
</try>
</student>
Sometimes student can do only one faculty on one field of study, but some of them do two different faculties:
<student>
<try>
<st_id>121234</st_id>
<name>John</name>
<surname>Doe</surname>
<email>jd#email.com</email>
<ssn>764896536</ssn>
<faculty name="Management">
<field>Production engineering</field>
<f_code>MN-1234-19</f_code>
</faculty>
</try>
<try>
<st_id>121234</st_id>
<name>John</name>
<surname>Doe</surname>
<email>jd#email.com</email>
<ssn>764896536</ssn>
<faculty name="IT">
<field>Electronics</field>
<f_code>IT-4321-19</f_code>
</faculty>
</try>
</student>
API gives me that:
{"HASH":"{SSHA}PTFOuvF/20MrSGbTkQTkeBUC8A/0mfKF"}
Expected result:
To add a HASH anywhere inside the student node f ex:
<student>
<try>
<st_id>123456</st_id>
<name>Michael</name>
<surname>Smith</surname>
<email>email#email.com</email>
<ssn>123456789</ssn>
<faculty name="IT">
<field>Programming</field>
<f_code>IT-1234-19</f_code>
</faculty>
</try>
<hash>{SSHA}PTFOuvF/20MrSGbTkQTkeBUC8A/0mfKF</hash>
</student>
My code is:
<inSequence>
<property expression="json-eval($.Numb)" name="Numb" scope="default" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<v1:getStudentRequest xmlns:v1="http://localhost/contract/ldap/v1">
<v1:Numb>$1</v1:Numb>
</v1:getStudentRequest>
</format>
<args>
<arg evaluator="xml" expression="get-property('uri.var.Numb')"/>
</args>
</payloadFactory>
<header name="Action" scope="default" value="urn:getStudentRequest"/>
<call>
<endpoint>
<address uri="http://localhost:9769/services/LdapDS.SOAP11Endpoint" format="soap11"/>
</endpoint>
</call>
<enrich>
<source type="body" clone="true"/>
<target type="property" property="Student"/>
</enrich>
<property name="DISABLE_CHUNKING" value="true" scope="axis2"/>
<call xmlns:v1="http://localhost/contract/ldap/v1">
<endpoint xmlns:v1="http://localhost/contract/ldap/v1">
<http uri-template="http://localhost:39080/ldap/passgen/{uri.var.Numb}" method="GET" format="pox"></http>
</endpoint>
</call>
<property evaluator="json" name="password" scope="default" expression="json-eval($.HASH)"/>
<filter source="get-property('password')" regex="^$">
<then>
<log level="custom">
<property expression="get-property('Numb')" name="Numb"/>
</log>
</then>
<else>
<property evaluator="json" name="pass" scope="default" expression="json-eval($.HASH)"/>
</else>
</filter>
<!--
<payloadFactory media-type="xml">
<format>
<m0:password xmlns:m0="http://localhost/contract/ldap/v1">$1</m0:password>
</format>
<args>
<arg evaluator="xml" expression="get-property('pass')"/>
</args>
</payloadFactory>
-->
<enrich>
<source xpath="$body" clone="true"/>
<target action="child" type="custom" xpath="$Student//student/try"/>
</enrich>
<enrich>
<source type="property" clone="true" property="Student"/>
<target action="replace" type="body"/>
</enrich>
<xslt key="ldapXSL"/>
<respond/>
</inSequence>
As a result I got just only get a HASH :(

The following contains a sample mediation that meets your requirements. Please refer to the following and develop your mediation. Analyzing the provided configurations it seems there are misconfigurations in the synapse artifacts (ex:-xpath="$Student//student/try") but the logic you have implemented is correct.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="testProxy"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<log level="full"/>
<call>
<endpoint>
<http uri-template="http://www.mocky.io/v2/5dc6d3963800001c35cdec56"/>
</endpoint>
</call>
<enrich>
<source clone="true" type="body"/>
<target property="property1" type="property"/>
</enrich>
<call>
<endpoint>
<http uri-template="http://www.mocky.io/v2/5dc6d4723800004a00cdec59"/>
</endpoint>
</call>
<property name="messageType" scope="axis2" value="application/xml"/>
<enrich>
<source clone="true" xpath="$body//HASH"/>
<target action="child" xpath="$ctx:property1"/>
</enrich>
<enrich>
<source clone="true" property="property1" type="property"/>
<target type="body"/>
</enrich>
<log level="custom">
<property expression="$ctx:property1" name="**-----**"/>
</log>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
The above proxy consists of the mock backends responses similar to that you have mentioned. Hope this helps

Related

Iteration through Parent-child with endpoint call

Scenario: Request consist of multiple orders with details. Send order details to back-end service and get a new Row number that after I should used like one of param with create details
Request looks:
<OrderList>
<Order>
<target>MySQL</target>
<Sales>
<email>p#gmail.com</email>
</Sales>
<Details>
<Item><qty>1</qty><code>PR9</code></Item>
<Item><qty>2</qty><code>PR8</code></Item>
<Item><qty>3</qty><code>PR7</code></Item>
</Details>
</Order>
<Order>
<target>MySQL</target>
<Sales>
<email>j#gmail.com</email>
</Sales>
<Details>
<Item><qty>4</qty><code>PR6</code></Item>
<Item><qty>5</qty><code>PR5</code></Item>
<Item><qty>6</qty><code>PR4</code></Item>
</Details>
</Order>
.......
</OrderList>
sequence:
<inSequence>
<!-- get source target data -->
<iterate expression="//Order" preservePayload="true">
<target>
<enrich>
<source clone="true" xpath="//Order"/>
<target property="OrderBackup" type="property"/>
</enrich>
<sequence>
<property expression="//target" name="SalesTarget" scope="default" type="STRING"/>
<property expression="//Sales/email" name="email" scope="default" type="STRING"/>
<filter regex="MySQL" source="$ctx:SalesTarget">
<then>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:dat="http://ws.wso2.org/dataservice" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<dat:addSalesOrder>
<dat:email>$1</dat:email>
</dat:addSalesOrder>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$ctx:email"/>
</args>
</payloadFactory>
<call blocking="true">
<endpoint key="SalesOrderEP"/>
</call>
**<enrich>
<source clone="true" type="body"/>
<target property="newRowID" type="property"/>
</enrich>**
<property expression="$ctx:newRowID > 0 " name="isCorrectResponse" scope="default" type="BOOLEAN"/>
<filter regex="true" source="$ctx:isCorrectResponse">
<then>
<enrich>
<source clone="true" property="OrderBackup" type="property"/>
<target type="body"/>
</enrich>
<iterate expression="//Details">
<target>
<sequence>
<property expression="//qty" name="qty" scope="default" type="STRING"/>
<property expression="//code" name="code" scope="default" type="STRING"/>
<log level="custom">
<property expression="fn:concat('params:Code: ' ,$ctx:code, ' ;Qty: ',$ctx:qty)" name="info"/>
</log>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:dat="http://ws.wso2.org/dataservice" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<dat:addSalesDetails>
<dat:salesId>$1</dat:salesId>
<dat:qty>$2</dat:qty>
<dat:code>$3</dat:code>
</dat:addSalesDetails>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$ctx:newRowID"/>
<arg evaluator="xml" expression="$ctx:qty"/>
<arg evaluator="xml" expression="$ctx:code"/>
</args>
</payloadFactory>
<call blocking="true">
<endpoint key="SalesDetailsEP"/>
</call>
<!-- get response and log it -->
<aggregate>
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete expression="//m0:UpdatedRowCount/Value" xmlns:m0="http://ws.wso2.org/dataservice">
<log level="full"/>
<drop/>
</onComplete>
</aggregate>
</sequence>
</target>
</iterate>
</then>
<else/>
</filter>
</then>
<else/>
</filter>
</sequence>
</target>
</iterate>
</inSequence>
I have a problem with first call response ... I used
<enrich>
<source clone="true" type="body"/>
<target property="newRowID" type="property"/>
</enrich>
to save newly created row Id in property and I'm getting it correctly in line
> <log level="custom">
> <property expression="fn:concat('NewRowID = ' ,$ctx:newRowID)" name="info"/>
> </log>
BUT when I want to use it in second payload it looks it cannot resolve it ?!!?
error:
DS Fault Message: Error in 'CallQuery.extractParams', cannot find
parameter with type:query-param name:salesId DS Code:
INCOMPATIBLE_PARAMETERS_ERROR
I figure out that in payload the $ctx:newRowID is reolved as
<GeneratedKeys> xmlns="http://ws.wso2.org/dataservice"><Entry><ID>93</ID></Entry></GeneratedKeys>
and not simply as 93
I'm guessing this is because in enrich I used source as "body" .. but when I tried to get xpath of response like xpath = "//Entry/ID" I got nothing
what is wrong?
Problem was that enrich mediator need namespace so
<enrich>
<source clone="true" xmlns:n0="http://ws.wso2.org/dataservice" xpath="$body/n0:GeneratedKeys/n0:Entry/n0:ID"/>
<target property="newRowID" type="property"/>
</enrich>
did the magic ... So ALWAYS put a namespace lesson learned

WS02 Enrich mediator after end point call

I'm trying to use enrichment mediator to populate custom response from End point
my sequence
<sequence name="GetMySqlData" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<enrich description="AddProductData">
<source clone="true" type="inline">
<ProductDataMySqlDB xmlns="">
<code/>
<name/>
<description/>
<qty/>
</ProductDataMySqlDB>
</source>
<target action="child" xpath="//mediate"/>
</enrich>
<property expression="$ctx:ProductCode" name="code" scope="default" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:dat="http://ws.wso2.org/dataservice" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<dat:getInventoryByCode>
<dat:code>$1</dat:code>
</dat:getInventoryByCode>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="get-property('code')"/>
</args>
</payloadFactory>
<property name="HTTP_METHOD" scope="axis2" type="STRING" value="POST"/>
<property name="SOAPAction" scope="transport" type="STRING" value="getInventoryByCode"/>
<call>
<endpoint key="getInventoryByCode"/>
</call>
--PROBLEMS STARTS ---
<enrich description="code">
<source clone="true" xpath="//Entry/code"/>
<target xpath="//mediate/ProductDataMySqlDB/code"/>
</enrich>
<enrich description="name">
<source clone="true" xpath="//Body/Entries/Entry/name"/>
<target xpath="//mediate/ProductDataMySqlDB/name"/>
</enrich>
<enrich description="description">
<source clone="true" xpath="//Entries/Entry/description" />
<target xpath="//mediate/ProductDataMySqlDB/description"/>
</enrich>
<enrich description="qty">
<source clone="true" xpath="//m0:Entries/m0:Entry/m0:qty" xmlns:m0="http://ws.wso2.org/dataservice" />
<target xpath="//mediate/ProductDataMySqlDB/qty"/>
</enrich>
<log level="full">
<property expression="$body" name="MySQLResponse"/>
</log>
<loopback/>
</sequence>
response that I getting form endpoint is like
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<Entries xmlns="http://ws.wso2.org/dataservice">
<Entry>
<code>PR2</code>
<name>Product2</name>
<description>Product stored in MySQL</description>
<qty>-2</qty>
</Entry>
</Entries>
</soapenv:Body>
</soapenv:Envelope>
and the error in log are :
Specified node by xpath cannot be found. {org.apache.synapse.mediators.elementary.EnrichMediator}
Cannot Enrich message from an empty source. {org.apache.synapse.mediators.elementary.EnrichMediator}
so it looks like the xpath for my source is wrong
<enrich description="code">
<source clone="true" xpath="WHAT WOULD BE THE CORRECT PATH?"/>
<target xpath="//mediate/ProductDataMySqlDB/code"/>
</enrich>
thnks
In your message, 'Entry' and 'code' nodes belongs to a namespace "http://ws.wso2.org/dataservice" (look at the 'Entries' root node) : you should declare and use this namespace in your source xpath :
<source xmlns:ds="http://ws.wso2.org/dataservice" clone="true" xpath="//ds:Entry/ds:code"/>

Enriching the response array with the corresponding elements in the request array

Input request :
[
{
"id" : "1",
"make" : "NAHB"
},
{
"id" : "2",
"make" : "Honda"
},
{
"id" : "3",
"make" : "Samsung"
}
]
I am using iterate, to send each element of above array as request to a backend service( In myactual project this is not so simple service i.e. its reponse is very complex with lots of arrays and sub-arrays(child arrays)in it . for better understanding of issue I kept it like this ).
The responses of the backend service are aggregated in one soap xml by AggregateMediator.
Below is response from AggregateMediator
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<Information>
<jsonObject>
<id>3</id>
<name>Mobile</name>
<model>S8</model>
</jsonObject>
<jsonObject>
<id>2</id>
<name>Car</name>
<model>Amaze</model>
</jsonObject>
<jsonObject>
<id>1</id>
<name>Home</name>
<area>5000sqft</area>
</jsonObject>
</Information>
</soapenv:Body>
</soapenv:Envelope>
I want to enrich above response from AggregateMediator like below using input request.
i.e. I want to merge input request and output of backend service.(id is common between them.)
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<Information>
<jsonObject>
<id>3</id>
<name>Mobile</name>
<model>S8</model>
<make>Samsung</make>
</jsonObject>
<jsonObject>
<id>2</id>
<name>Car</name>
<model>Amaze</model>
<make>Honda</make>
</jsonObject>
<jsonObject>
<id>1</id>
<name>Home</name>
<area>5000sqft</area>
<make>NAHB</make>
</jsonObject>
</Information>
</soapenv:Body>
</soapenv:Envelope>
I kept input request array in a property before calling backend services and was able to access it in response flow.
but the problem is "both request and response are arrays". How could I run two foreach on two different arrays simultaneously and also match their id before updating each array element of response.
foreachTest.xml :
<?xml version="1.0" encoding="UTF-8"?>
<api context="/foreschTest" name="foreachTest" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET" uri-template="/hi">
<inSequence>
<log level="full"/>
<log level="custom">
<property expression="//jsonArray" name="message"/>
</log>
<property expression="//jsonArray" name="req" scope="default" type="STRING"/>
<foreach expression="//jsonArray/jsonElement" id="Loop">
<sequence>
<property expression="get-property('Loop_FOREACH_COUNTER')" name="countid" scope="default" type="STRING"/>
<!-- <enrich>
<source clone="true" property="INCOMING_REQUEST" type="property"/>
<target type="body"/>
</enrich>
<enrich>
<source clone="true" type="inline">
<id xmlns="">Y</id>
</source>
<target action="sibling" xpath="//jsonElement"/>
</enrich> -->
<!--<enrich>
<source clone="true" type="property" property="INCOMING_REQUEST"></source>
<target action="replace" type="body"></target>
</enrich> -->
<!-- Temporily commented <enrich>
<source clone="true" type="inline">
<uniqueId xmlns="">Y</uniqueId>
</source>
<target action="child" xpath="//jsonElement/data[2]"/>
</enrich>
<enrich>
<source clone="true" property="countid" type="property"/>
<target xpath="//jsonElement/data[2]/uniqueId"/>
</enrich> -->
<log level="custom">
<property expression="get-property('countid')" name="mgs7"/>
</log>
<log description="" level="custom">
<property expression="get-property('Loop_FOREACH_ORIGINAL_MESSAGE')" name="mgs5"/>
<property expression="get-property('Loop_FOREACH_COUNTER')" name="mgs6"/>
<property expression="//jsonElement" name="msg8"/>
</log>
<log description="" level="custom">
<property expression="//jsonElement/data[0]" name="msg9"/>
<property expression="//jsonElement/data[1]" name="msg10"/>
<property expression="//jsonElement/data[2]" name="msg11"/>
</log>
</sequence>
</foreach>
<iterate expression="//jsonArray/jsonElement" id="1">
<target>
<sequence>
<log level="custom">
<property name="msg2" value=""Inside iterate""/>
</log>
<log level="full"/>
<send>
<endpoint key="modifyAgrRespEP"/>
</send>
</sequence>
</target>
</iterate>
</inSequence>
<outSequence>
<property name="info" scope="default">
<Information xmlns=""/>
</property>
<aggregate id="1">
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete enclosingElementProperty="info" expression="//jsonObject">
<log level="custom">
<property name="msg3" value=""Inside Aggr""/>
</log>
<log level="full"/>
<foreach expression="//Information/jsonObject">
<sequence>
<log level="custom">
<property name="msg4" value=""Inside Foreach""/>
</log>
<property expression="$body" name="agr" scope="default" type="STRING"/>
<log level="custom">
<property expression="get-property('agr')" name="agr"/>
</log>
<!-- <log level="full"/> -->
</sequence>
</foreach>
</onComplete>
</aggregate>
</outSequence>
<faultSequence/>
</resource>
</api>
modifyAgrRes.xml :
<?xml version="1.0" encoding="UTF-8"?>
<api context="/mod" name="modifyAgrRes" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET" uri-template="/aggr">
<inSequence>
<log level="custom">
<property name="message" value=""Inside Modify Service *************************""/>
</log>
<log level="custom">
<property expression="//jsonObject" name="location"/>
</log>
<switch source="//jsonObject/id">
<case regex="1">
<enrich>
<source clone="true" type="inline">
<name xmlns="">Home</name>
</source>
<target action="child" xpath="//jsonObject"/>
</enrich>
<enrich>
<source clone="true" type="inline">
<area xmlns="">5000sqft</area>
</source>
<target action="child" xpath="//jsonObject"/>
</enrich>
</case>
<case regex="2">
<enrich>
<source clone="true" type="inline">
<name xmlns="">Car</name>
</source>
<target action="child" xpath="//jsonObject"/>
</enrich>
<enrich>
<source clone="true" type="inline">
<model xmlns="">Amaze</model>
</source>
<target action="child" xpath="//jsonObject"/>
</enrich>
</case>
<case regex="3">
<enrich>
<source clone="true" type="inline">
<name xmlns="">Mobile</name>
</source>
<target action="child" xpath="//jsonObject"/>
</enrich>
<enrich>
<source clone="true" type="inline">
<model xmlns="">S8</model>
</source>
<target action="child" xpath="//jsonObject"/>
</enrich>
</case>
<default/>
</switch>
<log level="custom">
<property expression="//jsonObject" name="msg20"/>
</log>
<enrich>
<source clone="true" xpath="//jsonObject"/>
<target type="body"/>
</enrich>
<log level="full"/>
<respond/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
Here is a high-level answer; I guess you can work the details out for yourself:
Copy the input ($body) to a new property (inputBody) at the
beginning
Transform $ctx:inputBody to XML - see this URL for an example:
https://docs.wso2.com/display/ESB481/Sample+440%3A+Converting+JSON+to+XML+Using+XSLT
Do all intermediate processing steps
Loop through the $ctx:inputBody property, and for each row,
Get the /id (currentId) and /make (currentMake) into new properties
Use the Enrich mediator to add a child
/Information/jsonObject[id=$ctx:currentId]/make with value set to
$ctx:currentMake
Convert back to JSON if necessary.
I hope that helps.

Preserve the original payload when calling a web service

I am struggling to figure out how to preserve a payload so that it is available after calling a web service within a sequence.
For example in the following sequence, after the “call” mediator fires the payload changes to what has been returned by the web service.
What I am looking to do is to enrich the original payload with the data that has been returned from the web service call.
All help is very much appreciated.
<log level="full"/>
<payloadFactory media-type="xml">
<format>
<Flight xmlns="">
<location_id>$1</location_id>
<FlightDistance/>
<Aircraft>
<AircraftAbbr/>
<LandingDistance/>
<TakeoffDistance/>
<AircraftRange/>
<AirframeHours/>
</Aircraft>
<Runways>
<Airport/>
</Runways>
</Flight>
</format>
<args>
<arg evaluator="xml" expression="get-property('OriginAirport')"/>
</args>
</payloadFactory>
<log level="full">
<property expression="get-property('OriginalPayload')" name="OriginalPayload"/>
</log>
<call blocking="true" description="">
<endpoint key="GetRunways"/>
</call>
<foreach expression="//d:Entries/d:Entry" id="feid" xmlns:d="http://ws.wso2.org/dataservice">
<sequence>
<log description="" level="full">
<property name="marker" value="marker"/>
</log>
<property expression="$body/Entry/runway_length" name="RunwayLength" scope="default" type="STRING"/>
<enrich>
<source clone="true" property="RunwayLength" type="property"/>
<target action="child" property="RunwayLength" type="property"/>
</enrich>
<log>
<property expression="get-property('RunwayLength')" name="PropertyValue"/>
</log>
</sequence>
</foreach>
use enrich mediator and store the payload in to property
<enrich>
<source type="body"/>
<target type="property" property="REQUEST_PAYLOAD"/>
</enrich>
https://docs.wso2.com/display/ESB481/Enrich+Mediator
To complete #Jenananthan answer:
Store original payload in a property
Call the webservice
Restore the original payload to body:
<enrich>
<source clone="false" type="property" property="ORIGINAL_PAYLOAD"/>
<target action="replace" type="body"/>
</enrich>

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>