DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Nested Iterator with WSO2 ESB

Nested Iterator with WSO2 ESB

Achala Chathuranga Aponso user avatar by
Achala Chathuranga Aponso
·
Feb. 23, 13 · Interview
Like (0)
Save
Tweet
Share
6.34K Views

Join the DZone community and get the full member experience.

Join For Free
Please find the following sample which demonstrates the Nested iterator.

The following is the source of the configuration.

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
    <registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">
        <parameter name="cachableDuration">15000</parameter>
    </registry>
    <sequence name="IterateMediatorSequence">
        <iterate xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" xmlns:m0="http://services.samples" id="iterate1" preservePayload="true" attachPath="//m0:getQuotes" expression="//m0:getQuotes/m0:getQuote">
            <target>
                <sequence>
                    <log level="full">
                        <property name="target1" value="************After 1st Iterate before 2nd Iterate*************"/>
                    </log>
                    <iterate id="iterate2" preservePayload="true" attachPath="//m0:getQuote" expression="//m0:getQuotes/m0:getQuote/m0:request">
                        <target>
                            <sequence>
                                <log level="full">
                                    <property name="target2333" value="************After 2nd Iterate and before payload factory*************"/>
                                </log>
                                <payloadFactory>
                                    <format>
                                        <m0:getQuote>
                                            <m0:request>
                                                <m0:symbol>$1</m0:symbol>
                                            </m0:request>
                                        </m0:getQuote>
                                    </format>
                                    <args>
                                        <arg expression="//m0:getQuote/m0:request/m0:symbol"/>
                                    </args>
                                </payloadFactory>
                                <log level="full">
                                    <property name="target1" value="************after payload factory*************"/>
                                </log>
                                <send>
                                    <endpoint>
                                        <address uri="http://localhost:9001/services/SimpleStockQuoteService"/>
                                    </endpoint>
                                </send>
                            </sequence>
                        </target>
                    </iterate>
                </sequence>
            </target>
        </iterate>
    </sequence>
    <sequence name="aggregateMessages">
        <aggregate id="iterate2">
            <completeCondition>
                <messageCount min="-1" max="-1"/>
            </completeCondition>
            <onComplete xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" xmlns:m0="http://services.samples" expression="//m0:getQuoteResponse">
                <log level="full"/>
                <aggregate id="iterate1">
                    <completeCondition>
                        <messageCount min="-1" max="-1"/>
                    </completeCondition>
                    <onComplete expression="//m0:getQuoteResponse">
                        <send/>
                    </onComplete>
                </aggregate>
            </onComplete>
        </aggregate>
    </sequence>
    <sequence name="fault">
        <log level="full">
            <property name="MESSAGE" value="Executing default 'fault' sequence"/>
            <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
            <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
        </log>
        <drop/>
    </sequence>
    <sequence name="main">
        <in>
            <sequence key="IterateMediatorSequence"/>
        </in>
        <out>
            <sequence key="aggregateMessages"/>
        </out>
    </sequence>
</definitions> 

Use the following request with soapui in order to test the above sample.

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
 <m0:getQuotes xmlns:m0="http://services.samples">
<m0:getQuote>
<m0:request>
<m0:symbol>SUN9</m0:symbol>
</m0:request>
<m0:request>
<m0:symbol>SUN10</m0:symbol>
</m0:request>
</m0:getQuote>
</m0:getQuotes>
</soapenv:Body>
</soapenv:Envelope>
From the second iterate mediator, messages retrieved from the first iterator are again iterated into smaller messages as below

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<m0:getQuote xmlns:m0="http://services.samples">
<m0:request>
<m0:symbol>SUN10</m0:symbol>
</m0:request>
</m0:getQuote>
</soapenv:Body>
</soapenv:Envelope> 

Enterprise service bus

Published at DZone with permission of Achala Chathuranga Aponso, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Top Five Tools for AI-based Test Automation
  • Visual Network Mapping Your K8s Clusters To Assess Performance
  • PostgreSQL: Bulk Loading Data With Node.js and Sequelize
  • How Do the Docker Client and Docker Servers Work?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: