Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

WSO2 ESB Cloning and Aggregating With Train Sample

DZone's Guide to

WSO2 ESB Cloning and Aggregating With Train Sample

· Integration Zone
Free Resource

Learn how API management supports better integration in Achieving Enterprise Agility with Microservices and API Management, brought to you in partnership with 3scale

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)

image

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>

</config>

<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"/>

</result>

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

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

</query>

<operation name="getTrains">

<call-query href="getTVGTrains">

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

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

</call-query>

</operation>

</data>

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"> 
   <soapenv:Header/> 
   <soapenv:Body> 
      <dat:getTrains> 
         <dat:StartingLocation>Turin</dat:StartingLocation> 
         <dat:EndingLocation>Paris</dat:EndingLocation> 
      </dat:getTrains> 
   </soapenv:Body> 
</soapenv:Envelope>

Sample respond

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
   <soapenv:Body> 
      <Entries xmlns="http://ws.wso2.org/dataservice"> 
         <Entry> 
            <StartingLocation>Turin</StartingLocation> 
            <EndingLocation>Paris</EndingLocation> 
            <TourDuration>5:30 hours</TourDuration> 
            <TicketPrice>150</TicketPrice> 
            <TrainsName>TVG-2302</TrainsName> 
            <LeavingTime>8.30AM</LeavingTime> 
         </Entry> 
         <Entry> 
            <StartingLocation>Turin</StartingLocation> 
            <EndingLocation>Paris</EndingLocation> 
            <TourDuration>4:30 hours</TourDuration> 
            <TicketPrice>150</TicketPrice> 
            <TrainsName>TVG-3444</TrainsName> 
            <LeavingTime>10.00AM</LeavingTime> 
         </Entry> 
      </Entries> 
   </soapenv:Body> 
</soapenv:Envelope>

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">

<target>

<inSequence>

<clone>

<target>

<endpoint name="TGV">

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

</endpoint>

</target>

<target>

<endpoint name="EUROStar">

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

</endpoint>

</target>

<target>

<endpoint name="THYLYS">

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

</endpoint>

</target>

</clone>

</inSequence>

<outSequence>

<aggregate>

<completeCondition>

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

</completeCondition>

<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>

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

<enrich>

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

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

</enrich>

<send/>

</onComplete>

</aggregate>

</outSequence>

</target>

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

<description></description>

</proxy>

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


image

Time to enjoy joying more services with Clone and Aggregate.


Unleash the power of your APIs with future-proof API management - Create your account and start your free trial today, brought to you in partnership with 3scale.

Topics:

Published at DZone with permission of Eric Genesky. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}