Over a million developers have joined DZone.

WSO2 ESB Cloning and Aggregating With Train Sample

DZone 's Guide to

WSO2 ESB Cloning and Aggregating With Train Sample

· Integration Zone ·
Free Resource

In Europe there are some many places to visit and trains will be best way to move rather than flying if you wish to enjoy surroundings. But when you search for train from one country city to another Europe county city results are not much powerful for guest expectations. Lot of time it give result as

" Sorry, but we couldn’t find any results for your search" in red letters.

But fine for master cities. But in here I am not going talk about Trains or Europe.

Let go to technical (IT) world or SOA perspective. Each Train Services provider will have and interface where they expose their services . Such as when user request destination with particular start point he/she will get trains on that path with price and duration in hours. (Plus Leaving time from starting location)


Here I have service for demo with wso2 Data services with MySQL. Here is services from Thalys.

Here is data Services for TVG

<data name="TGV">

<config id="mysql1">

<property name="driverClassName">com.mysql.jdbc.Driver</property>

<property name="url">jdbc:mysql://localhost:3306/trains</property>

<property name="username">root</property>

<property name="password">root</property>


<query id="getTVGTrains" useConfig="mysql1">

<sql>SELECT StartingLocation, EndingLocation, TourDuration, TicketPrice, TrainsName, LeavingTime FROM `trains` WHERE `TrainsName` LIKE '%TVG%' AND StartingLocation = :StartingLocation AND EndingLocation = :EndingLocation</sql>

<result element="Entries" rowName="Entry">

<element column="StartingLocation" name="StartingLocation" xsdType="string"/>

<element column="EndingLocation" name="EndingLocation" xsdType="string"/>

<element column="TourDuration" name="TourDuration" xsdType="string"/>

<element column="TicketPrice" name="TicketPrice" xsdType="string"/>

<element column="TrainsName" name="TrainsName" xsdType="string"/>

<element column="LeavingTime" name="LeavingTime" xsdType="string"/>


<param name="StartingLocation" sqlType="STRING"/>

<param name="EndingLocation" sqlType="STRING"/>


<operation name="getTrains">

<call-query href="getTVGTrains">

<with-param name="StartingLocation" query-param="StartingLocation"/>

<with-param name="EndingLocation" query-param="EndingLocation"/>




Now create same to other also

Here is sample Web request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice"> 

Sample respond

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
      <Entries xmlns="http://ws.wso2.org/dataservice"> 
            <TourDuration>5:30 hours</TourDuration> 
            <TourDuration>4:30 hours</TourDuration> 

Then ESB for Proxy For Cloning and aggregating (If respond and different then use XSLT mediator for informing those in to one formation)

<proxy xmlns="http://ws.apache.org/ns/synapse" name="AllEuropTrains" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">





<endpoint name="TGV">

<address uri="http://localhost:9764/services/TGV/"/>




<endpoint name="EUROStar">

<address uri="http://localhost:9764/services/EUROStar/"/>




<endpoint name="THYLYS">

<address uri="http://localhost:9764/services/THYLYS/"/>








<messageCount min="-1" max="-1"/>


<onComplete xmlns:m0="http://ws.wso2.org/dataservice" expression="//m0:Entries">

<log level="custom" separator=",">

<property name="MessageFlow" value="======================= Sending Back the Aggregated Responses. ==============="/>


<log level="full" separator=","/>


<source xmlns:m1="http://ws.wso2.org/dataservice" clone="true" xpath="//m1:Entries/m1:Entry"/>

<target type="body" action="child"/>







<publishWSDL key="conf:/blog/train/AllTrain.wsdl"/>



Then Try out the proxy from here you will see all respond in one message


Time to enjoy joying more services with Clone and Aggregate.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}