Popular Posts

Saturday, April 19, 2008

Data services and mediating SOAP messages with Synapse DBReport mediator

Apache Synapse is an ESB that has been designed to be simple to configure, very fast, and effective at solving many integration and gatewaying problems. It comes with a set of ready-to-use transports and mediators.
Visit Apache synapse web for more information about message mediation.

WSO2 data services is a convenient mechanism to provide a Web service interface for data stored in some data source. Data sources such as relational databases, CSV files & MS-Excel files can be easily service enabled using Data Services.
You can find more details about WSO2 Data services from here

I got a lot of positive feedback about my previous posts (securing web services) since they helped beginners to understand and experiment with simple examples without digging in to complex details.
I thought to describe a simple scenario which demonstrates the usage of data services and synapse together. I hope the following step-by-step instructions will help most of the novice users to get started with WSO2 data services and Apache synapse in a fairly simple manner.

I am going to use the following open source software tools in this demonstration. So, please make sure you have configured them in your environment.

Apache Synapse 1.1.1 (Download)
WSO2 WSAS 2.2.1 (Download)
Apache derby (Download)
Apache JMeter (Download)

A SOAP request will be sent to WSO2 WSAS to get the net salary of an employee which resides in a database. The messages will be transferred via synapse. The response SOAP message will be subjected to mediation by synapse DBreport mediator. In which, the net salary of a different employee will be updated by evaluating the net salary of the requested employee. In other words, we will get the net salary of employee A and instruct synapse to update employee B's net salary to the net salary of employee A.

Step 1

Database preparation

We should prepare the necessary database and tables as the first step. Apache derby will be used in this example.
  • Start derby network server
Go to derby_home/bin and run startNetworkServer.bat
  • Create a database
start ij utility (derby_home/bin/ij.bat) and enter the following command.
CONNECT 'jdbc:derby://localhost:1527/employeedb;user=wsas;password=wsas;create=true';
  • Create a table and insert data
create table employee(name varchar(10), empid varchar(10), netsalary double);
insert into employee values ('Sean','1',1000.00);
insert into employee values ('John','1',3000.00);
insert into employee values ('David','1',2000.00);

Next, I'm going to create a data service using the above data source. Data services allow users to expose the relational data as web services so that they can be accessed and manipulated in programming language independent manner.

Step 2

Create a data service

Please make sure the derby client driver is available in your WSAS instance. Copy derby_home/lib/derbyclient.jar to WSAS_HOME/lib.

Install WSO2 WSAS if it is not already installed. start WSO2 WSAS using WSAS_HOME/bin/wso2wsas.bat

Access WSAS management console (https://localhost:9443) where we can configure our data service through UI.

Go to 'Services and service group management' page and click on 'Define data service' link. You will get a page as given below.

Enter 'Synapsedataservice' as the service name. Select 'RDBMS' as the data source. A pop-up window will be displayed where we can configure data base details.
Driver Class = org.apache.derby.jdbc.ClientDriver
JDBC URL = jdbc:derby://localhost:1527/employeedb
user name= wsas
password = wsas

Click on the 'Next' after configuring data source details. The second step of the data service configuration will be displayed. Click on 'New query' button. The following pop-up window will appear.

Enter the following details in the above window.

Query ID=Empsal
SQL Statement =
select * from employee where name = ?

Click on ' add new input mapping' and enter followings.

Grouped by element = employees
Row name = employee

Click on 'add new Output mapping' and enter the following values.
Mapping Type = element
Output field name = name, SQL column Name = name
Output field name = empid, SQL column Name = empid
Output field name = netsalary, SQL column Name = netsalary

After entering all of the above values, click 'Next' button in the data service - step 2.

Step 3 of the wizard will be displayed. Click on 'Add new operation' button and enter the following values.
Operation Name = EmpSalOp
Query= Empsal

Click 'Finish' to deploy the data service.

Step 3

Test the data service

You can test your data service simply by invoking it in RESTful manner. Issue the following url.

You should get the details of employee, Sean.


You should observe the simplicity of exposing relational data using WSO2 Data services. Lets see how we can use Apache Synapse to do some mediation in messages passing through it.

Step 4

Creating Synapse configuration

Install Synapse1.1.1 (just unzip the binary distribution). Synapse provides a xml configuration file to define the mediation rules using synpase configuration language. Open Synapse_home/repository/conf/synapse.xml.

Remove the existing contents of that file and add the following configuration.

<definitions xmlns="http://ws.apache.org/ns/synapse">
<sequence name="main">
<address uri="http://localhost:9762/services/Synapsedataservice"/>
<log level="custom">
<property name="text"
value="** Reporting to the Database **"/>
<sqlupdate employee set netsalary=? where name='John'</sql>
<parameter expression="//datas2:employees/datas2:employee/datas2:netsalary"
xmlns:datas2="http://ws.wso2.org/dataservice" type="DOUBLE"/>


Here, the request message pass through synapse will be directed to the data service endpoint without doing any mediation. It is defined in the <in/> element.
The SOAP response will be transferred via two different mediators.

Log - when the soap response reaches synapse, it just logs the message as defined.
dbreport - writes information to a Database, using the specified insert SQL statement.

In this configuration, we evaluate the response SOAP message using an XPath expression and get the net salary of the employee. Then we update the net salary of employee John with that.

Now you can start synapse with the above configuration by running synapse.bat.

To see how this works, we need to send a SOAP request message to Synapse. Apache Jmeter can easily be used to transmit a soap message.

Step 5

Test message mediation

Install jmeter in your system (Just unzip jmeter binary distribution). Run jmeter.bat.
Create a thread group and add SOAP/XML-RPC request sampler. (Please read http://wso2.org/library/1085 if you are not familiar with testing web services using Jmeter)

Add the following soap request in to the SOAP/XML-RPC data section.

<soapenv:envelope soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<axis2ns5:empsalop axis2ns5="http://ws.wso2.org/dataservice">

You may have wondered how I captured the above request Soap message. There are several different approaches.
1. write a java client and invoke the data service. Capture the message using apache Tcpmon
2. Enable Soap Tracing in the WSAS management console. As we did above, invoke the service in RestFul manner. Then access the SoapTracer in WSAS management console and copy the soap request. (This will be the easiest method)

Enter 'http://localhost:8080' as the URL in SOAP/XML-RPC request.
Enable 'Send SoapAction' and enter 'urn:EmpSalOp'

If everything is correct, you should see the following in your Jmeter console.

Run the sampler. You may check the synapse console where you can monitor the message mediation.

Lets see whether the net salary of John is updated as expected. Open the ij utility of Derby and issue the following SQL statement.
select * from employee;

You should notice that the net salary of John and Sean are same.

In this post, we looked at the WSO2 data services and Apache Synapse using a simple scenario. You will be able to improve the above scenario by applying more mediation rules.


Anonymous said...

Perfect!!You are a outstanding person!Have you ever wore chaussures puma,Here are the most popular puma CAT,Puma shoes store gives some preview of puma speed cat,and casual but no sweat puma basket.


Anonymous said...

Thank you so much!!polo shirt men'ssweate,Burberry Polo Shirts lacoste sweater, ralph lauren Columbia Jackets,ski clothing. Free Shipping, PayPal Payment. Enjoy your shopping experience on mensclothingus.com.You can find the father who desire fashionable, intellectual mens clothing simultaneously.

Anonymous said...

God bless you!I really agree with your opinions.Also,there are some new fashion things here,gillette razor blades.gillette mach3 razor bladesfor men.As for ladies,gillette venus razor blades must the best gift for you in summer,gillette fusion blades are all the best choice for you.

Anonymous said...

Do not mean bad.Thank you so much!I just want to show some fashion things to all of you.I like puma speed, puma femmes and other puma shoes. These puma sport items are at store recently and available for anyone.

Anonymous said...

Awesome!!!Best wishes for you !!cheap polo shirts is the father of the summer should be prepared to most commonly used item, it has both style and shape of Ralph Lauren Polo, and vest with a random function polo ralph lauren, so that in the short-sleeved apply to both on many occasions, the pink and black color men's polo shirts brought into effect, lightweight cotton, linen texture to demonstrate masculine temperament and sense of fashion exhaustively.

Anonymous said...

Fantastic!God bless you!Meanwhile,you can visit my China Wholesale,we have the highest quality but the lowest price fashion products wholesale from China.Here are the most popular China Wholesale productsfor all of you.You can visit http://chinaclothes.net.Also the polo clothing is a great choice for you.

Anonymous said...

polo ralph lauren RED! Series of design criteria - stylish, simple, self-cultivation. For the first time in 2009 in New York Fashion Week debut, RED! Series has a new Polo Shirts On Sale series from the traditional burberry polos LOGO, LOGO traditional crocodile logo at the Ralph Lauren Polo Shirts letter above, and the new series of letters with the cheappolos logo in line to be between a red symbol of Burberry Polo Shirts.

Anonymous said...

In this version of the ralph lauren polo, the styling and fabric is advertised as being made out of "playdry" material. Burberry Polo Shirts is another performance fabric which is intended to add luxury Cheap polo shirts, coolness, and moisture wicking qualities. Performance fabrics wholesale polo shirtswere originally created primarily for athletes and other sports enthusiasts who work up a good sweat ralph lauren polo shirts. The moisture wicking fabric in cheap ralph lauren polos draws the moisture away from the body which then evaporates quickly discount ralph lauren polos. ralphlaurenpoloshirts keep the body cooler and drier even when the athlete is under physical duress polo clothing.

Anonymous said...

Although many people criticize ed hardy clothing for having nothing but tattoo patterns, being filled with waste and useless things, it is widely acknowledged that ed hardy clothes draws the most attention of both common young people as well as many Hollywood welcomed stars for its punk ed hardy t-shirts rock styles. As a matter of fact, in such a world where all ed hardy shirts are much like each other, ed hardy mens creates yet another totally new global sensation in fashion crowd for ed hardy womens fancy design. An increasing number of people are charmed by the magic of amazing tattoo and impressive color of ed hardy sunglasses.

Anonymous said...

The larger that the head size is for your babolat pure drive, the more power you will be provided with. Additionally, a larger wilson k six size means a larger sweet spot which is why beginners as well as intermediate players often prefer to work with a head microgel with a larger head size. Additionally, thicker frames are also capable of generating more power as well. Smaller head sizes on prince-o3-tour on the other hand are capable of providing less power, but significantly more control cheap tennis racquets.new polos men poloswomen polosdiscount polossummer polospolo shirts whosalepolo fashionembroodered polostennis racketsclothing poloclothingedhardyshirtedhardyclothingsummer ed hardy clothingcheap shirtsed hardy brand.

Anonymous said...


Anonymous said...

Burberry polo shirt the steady, solid, so many young girls also love it. Speaking of people of a ralph lauren polo, think it a sign of nobility elegant waving in the horse club.spyder jacket in the cold in your winter activities can be easily.columbia jacket it is expensive, but here you do not need to consider the price of it. the north face jacket one of my favorite money, I do not know how many in this world of its fans.
ed hardy clothing
ed hardy clothes
ed hardy shirts
ed hardy t-shirts
ed hardy sunglasses
ed hardy mens
ed hardy womens

Anonymous said...

In preparation for the purchase of a tennis racquetbefore, we must consider your financial ability to bear; On this basis, a further comparison, as far as possible, choose your head tennis racquets. Now a lot of babolat pure drive and more mixed materials, the proportion of mixed-use to control the stiffness of the babolat aeropro drive and the shock-absorbing capacity, the more rigid babolat tennis racket, the swing more powerful force; but the relative resilience of the shock-absorbing capacity and wilson k factor performance of talks on the easier it is for the wrist and elbow injury.
Wholesale Handbags
Cheap Handbags
Womens Handbags
Cheap Purses
Designer Handbags

Anonymous said...


Anonymous said...

There are ed hardy shirts
,pretty ed hardy shirt for men,

ed hardy womens in the ed hardy online store

designed by ed hardy ,
many cheap ed hardy shirt ,glasses,caps,trouers ed hardy shirts on sale ,

You can go to edhardyshirts.com to have a look ,you may find one of ed hardy clothing fit for you
Top qualitymen's jacket,
These cheap jacket are on sale now,you can find
north face jackets inmage on our web
Ralph Lauren Polo Shirtsbuberry polo shirts

Anonymous said...

Do you wannaghd hair straighteners for you own , we have many
cheap ghd hair straightenersin style and great,you can choose one from these
hair straighteners
Authentic chaussure puma
chaussure sport
And chaussure nike shoes
Come here to have a look of our Wholesale Jeans
Many fashionMens Jeans ,eye-catching
Womens Jeans ,and special out standing
Blue Jeans ,you can spend less money on our
Discount Jeans but gain really fine jeans, absolutely a great bargain.
China Wholesale
wholesale from china
buy products wholesale
China Wholesalers