Developer Studio - Tutorial
Let's consider a scenario of a
Health Care Organization. This organization provides some facilities as a
service to the customer who is consuming the services via a Mobile
Application. Customer wants to find the details of the nearest health
care center/facilities based on his/her geographical coordinates
(longitude and latitude). Let's assume that there is no direct mapping
between the coordinates and
the Healthcare facilities. Apparently, the organization
has 3 different services namely 'Geo Service' , 'HC Facility
Locator Service' and 'Health Care center Information Service' which are
exposed as SOAP services. So, this is a typical service
integration scenario, where we need to integrate these 3 services and
expose the integrated business functionality as a single
service.
Considering
the incremental development, our goal is to resolve the coordinates
which sent by the customer and find-out the matching
Healthcare Center details, so the message sends to the 'Geo Service' to
resolve the zip code from the given
coordinate. This example shows the implementation of a customer
sends a message
which goes through a proxy service to the Geo Service and sending back
the response to the customer.
Creating a New ESB Project
- Open Developer Studio Dashboard and select 'ESB Config Project' under the Enterprise Service Bus category.
- If you want to create this ESB project from existing configuration files, select 'Point to Existing Synapse-configs Folder'. Otherwise select 'New ESB Config Project.
- Give a unique name for the project. (If you select the option to point to an existing Synapse-configs folder, then give a name and click Browse to navigate to the folder containing the configuration files) Optionally specify the location where you want to save the project (or leave the default location specified). You can optionally specify the working set, if any, that you want to include in this project.
- A Maven POM file will be generated automatically for this project. If you want to include parent POM information in the file from another project in this workspace, click Next, click the Specify Parent from Workspace check box, and then select the parent project.
- Click Finish.
- If you specified a folder with existing configuration files, specify whether you want to open those files now
The new ESB project has been created in the workspace. If you browse inside the project, you will see a project structure as below, with folders created for different resources such as endpoints, local entries, proxy services, and sequences.
Message Mediation
- Create a new custom proxy by right click on the created ESB config project( new -> proxy service -> Create a new Proxy Service) and name it as 'HCCProxyService'. Select the Proxy Service Type as 'Custom Proxy'.
- Since the original request from the client comes to the 'InSequence' of the proxy service, let's consider the implementation of the inSequence. First from the tool pallet drag and drop a 'Property Mediator' for longitude to the inSequence of the proxy service.
- Then change its properties. When editing the Value Expression it will pop up a Namespace Property Editor and insert the namespace property, namespace as follows and then click Add and then OK.
- The properties window will displays as follows
- Create another property mediator to extract the value of latitude as well.
- Then drag and drop a 'Log Mediator' to verify that the values are properly extracted
- Then edit its properties . When editing the 'Properties' property it will pop up a Log Mediator Configuration window and edit it as follows
- Now we have extracted the required values, in order to create a new Geo Service request we may use XSLT, PayloadFactory or Enrich mediators. We have used Enrich mediators in this example. Drag and drop three Enrich Mediators and edit its properties. The source will look like this
<enrich>
<source clone="true" type="inline">
<geo:getZipCode xmlns:geo="http://geo.wso2">
<geo:longitude>0</geo:longitude>
<geo:latitude>0</geo:latitude>
</geo:getZipCode>
</source>
<target action="replace" type="body"/>
</enrich>
<enrich>
<source clone="true" property="longitude" type="property"/>
<target action="replace" type="custom"
xmlns:geo="http://geo.wso2" xpath="//geo:getZipCode/geo:longitude/text()"/>
</enrich>
<enrich>
<source clone="true" property="latitude" type="property"/>
<target action="replace" type="custom"
xmlns:geo="http://geo.wso2" xpath="//geo:getZipCode/geo:latitude/text()"/>
</enrich>
- Then drag and drop Log Mediators for verification.
- Finally modify the HCCProxyService's inSequence by specifying the send mediator with 'GeoEP' and the receiving sequence as 'hcfrequest.
- This is the full configuration of the inSequence of the HCCProxyService
<inSequence>
<property action="set"
expression="//heal:getHealthcareCenterInfo/heal:longitude/text()"
name="longitude" scope="default" type="STRING" xmlns:heal="http://healthcare.wso2"/>
<property action="set"
expression="//heal:getHealthcareCenterInfo/heal:latitude/text()"
name="latitude" scope="default" type="STRING" xmlns:heal="http://healthcare.wso2"/>
<log category="INFO" level="custom" separator=",">
<property expression="$ctx:longitude" name="Longitude"/>
<property expression="$ctx:latitude" name="Latitude"/>
</log>
<enrich>
<source clone="true" type="inline">
<geo:getZipCode xmlns:geo="http://geo.wso2">
<geo:longitude>0</geo:longitude>
<geo:latitude>0</geo:latitude>
</geo:getZipCode>
</source>
<target action="replace" type="body"/>
</enrich>
<enrich>
<source clone="true" property="longitude" type="property"/>
<target action="replace" type="custom"
xmlns:geo="http://geo.wso2" xpath="//geo:getZipCode/geo:longitude/text()"/>
</enrich>
<enrich>
<source clone="true" property="latitude" type="property"/>
<target action="replace" type="custom"
xmlns:geo="http://geo.wso2" xpath="//geo:getZipCode/geo:latitude/text()"/>
</enrich>
<log category="INFO" level="custom" separator=",">
<property name="MessageFlow" value="===== Sending Request To : GeoWS ========="/>
</log>
<log category="INFO" level="full" separator=","/>
<send receive="hcfRequest">
<endpoint key="GeoEP"/>
</send>
</inSequence>