0
votes

I want to write next target sequence of actions: 1. call DSS to receive a list of customers 2. enrich each customer's by separate call another DSS service.

So, I thought I should call callout mediator and then iterate it's result using iterator. But I can't understand what should I write in the iterator.

And another question - am I right, that the result of each iteration will be attached under the 'customer' tag?

Details:

XML which returned from DSS is next:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <customers xmlns="crm.crm.crm">
         <customer>
            <customerId>1</customerId>
            <name>Customer #1</name>
            <birthdate>2017-01-15T14:54:12.000+03:00</birthdate>
         </customer>
      </customers>
   </soapenv:Body>
</soapenv:Envelope>

Sequence:

    <?xml version="1.0" encoding="UTF-8"?>
<sequence name="BatchSequence" statistics="enable" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <log description="">
        <property name="text" value="Start batch seq"/>
    </log>
    <payloadFactory description="create dss request" media-type="xml">
        <format>
            <soapenv:Envelope xmlns:crm="crm.crm.crm" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                <soapenv:Header/>
                <soapenv:Body>
                    <crm:getCustomers>
                        <crm:batchSize>3</crm:batchSize>
                    </crm:getCustomers>
                </soapenv:Body>
            </soapenv:Envelope>
        </format>
        <args/>
    </payloadFactory>
    <callout action="urn:getCustomers" description="dss: main object" initAxis2ClientOptions="false" serviceURL="http://192.168.3.32:9765/services/CrmDataService?wsdl">
        <source type="envelope"/>
        <target key="customers"/>
    </callout>
    <log description="">
        <property expression="get-property('customers')" name="text"/>
    </log>
    <iterate description="Enrich customers" expression="/soapenv:Envelope/soapenv:Body/customers/customer" id="iterateId" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <target>
            <sequence>
                <property description="customerId" expression="/customerId" name="customerID" scope="default" type="STRING"/>
                <log description="">
                    <property expression="get-property('customerID')" name="text"/>
                </log>
            </sequence>
        </target>
    </iterate>
    <log description="">
        <property name="text" value="End batch seq"/>
    </log>
</sequence>

output:

[2017-01-27 10:17:17,371] INFO - LogMediator To: , MessageID: urn:uuid:d628e361-beb8-4c26-b06d-3901227ad76a, Direction: request, text = Start batch seq [2017-01-27 10:17:18,558] INFO - LogMediator To: , MessageID: urn:uuid:d628e361-beb8-4c26-b06d-3901227ad76a, Direction: request, text = 1Customer #12017-01-15T14:54:12.000+03:002Customer #22016-12-16T14:54:20.000+03:003Customer #32016-10-27T14:54:21.000+03:00 [2017-01-27 10:17:18,559] WARN - RuntimeStatisticCollector Events occur after event collection is finished, event - urn_uuid_d628e361-beb8-4c26-b06d-3901227ad7 6a231160071781262

Update 1 Some working code. Not sure that this is correct, because I'm a little bit confusing for a PayloadFactory here..

<payloadFactory description="" media-type="xml">
    <format>
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
            <soapenv:Body>$1</soapenv:Body>
        </soapenv:Envelope>
    </format>
    <args>
        <arg evaluator="xml" expression="get-property('customers')"/>
    </args>
</payloadFactory> 
<iterate continueParent="true" description="" expression="$body/crm:customers/crm:customer" sequential="true" xmlns:crm="crm.crm.crm">
    <target>
        <sequence>
            <property expression="//crm:customerId" name="customerID" scope="default" type="STRING"/>
            <log>
                <property expression="get-property('customerID')" name="text"/>
            </log>
        </sequence>
    </target>
</iterate>

Update 2 I figured a main problem - callout mediator doesnt' put response to the envelope context(if I understand right). So, we can't use just property to link it with iterator, so, in this case we should link them using smth like Payload factory. Not very usifull If smbdy knows how to do it more simple(dirrect passing property to the iterator) - pls write to me. Solution - to use Call medator. Works fine.

thanks to all!

1
If both DSS services are located in the same DSS server, I think the best approach would be to do the enrichment directly there, using the ESB just to any eventual final transformation and/or to add QoS features. Doing the enrichment at the ESB implies that there will be a big overhead related to the multiple calls. Doing this at the DSS, there is also overhead, but it will be smaller since there is no round-trip for each customer.Philippe Sevestre
Of course your are right! but this is just for education purpose, I'm exploring WSO - is it possible to use in our integration projects)PVN
You can use nested queries. Please check this post docs.wso2.com/display/DSS351/Nested+Query+SampleErnesto

1 Answers

0
votes

xml nodes in the dss response belongs to a namespace "crm.crm.crm" and you must refer it in your xpath

with iterate mediatior, if you want to preserve source payload, you must use an attribute named preservePayload="true" and tell where the xml framents must be attached with the attribute attachPath ortherwise, inside interate's sequence, you will only have your xml fragment in the soap body

This is a sample that works without preserving source payload :

    <iterate xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:crm="crm.crm.crm" expression="$body/crm:customers/crm:customer" id="iterateId">
        <target>
            <sequence>
                <property expression="$body/crm:customer/crm:customerId" name="customerID" scope="default" type="STRING"/>
                <log>
                    <property expression="get-property('customerID')" name="text"/>
                </log>
            </sequence>
        </target>
    </iterate>

By default, mediators after iterate will not be executed. If you want to continue the mediation, use attribute continueParent="true"