Member Sign In
Not a member?

A Wired.com user account lets you create, edit and comment on Webmonkey articles. You will also be able to contribute to the Wired How-To Wiki and comment on news stories at Wired.com.


It's fast and free.

Sign in with OpenID
Sign In
Webmonkey is a property of Wired Digital.
processing...
Join Webmonkey

Please send me occasional e-mail updates about new features and special offers from Wired/Webmonkey.
Yes No

Please send occasional e-mail offers from Wired/Webmonkey affiliated web sites and publications, and carefully selected companies.
Yes No

I understand and agree that registration on or use of this site constitutes agreement to Webmonkey's User Agreement and Privacy Policy.
Webmonkey is a property of Wired Digital.
processing...

Retrieve Sign In

Please enter your e-mail address or username below. Your username and password will be sent to the e-mail address you provided us.

or
Webmonkey is a property of Wired Digital.
processing...

Welcome to Webmonkey

A private profile page has been created for you.
As a member of Webmonkey, you can now:
  • edit articles
  • add to the code library
  • design and write a tutorial
  • comment on any Webmonkey article
Close
Webmonkey is a property of Wired Digital.

Sign In Information Sent

An e-mail has been sent to the e-mail address registered in this account.
If you cannot find it in your in-box, please check your bulk or junk folders.
Sign In
Webmonkey is a property of Wired Digital.

Getting started with Data Services using WSO2 WSASv2

/skill level/
/viewed/
0 Times

Article

Data Services is a convenient mechanism to provide a service interface to data stored in a relational database. Parameters for the Web service will be passed to SQL query & you will get custom defined xml response, generated using database data.

Objective
This starter guide will explain how to deploy a simplest form of data service using sample embedded derby database that ships with WSO2WSAS-2.0.
My main intention is to guide you through how to deploy a simple data service without paying attention to too many configuration details. More advance features will be discussed in a future article.

Prerequisites
1. Download WSO2WSAS-2.0 from http://dist.wso2.org/products/wsas/java/2.0/
2. Install it as a standalone server (Install location will be referred to as WSAS_HOME hereafter.)
3. Download & Install Ant (version 1.6.5 or higher) from http://ant.apache.org/
4. Start WSO2WSAS-2.0 (run WSAS_HOME/bin/wso2wsas.bat | wso2wsas.sh)
5. Open a web browser & navigate to https://localhost:9443/
6. Login to WSO2WSAS-2.0 (using Username/password = admin/admin)

 

Step 1 – Creating & populating sample database

1. In a new command window, go to WSAS_HOME/samples/DataService & type 'ant'.
2. This will produce an output similar to following.

 

1-create-database.jpg

Now you have a sample Derby database created & populated. From next step onwards, we will be using this database to create our Data Service.

 

Step 2 – Define Data Service Screen

In a web browser, click on 'Services' link (upper left hand corner) & you will be taken to following screen.

2-connection-details.jpg

Click on 'Define Data Service' link.

3-configuration-step1.jpg

 

Step 3 – Creating a Data Service (Configuring connection)
Fill the screen using values in table below & click 'next' button.

Field name

Value

Data Service Name

EmployeeServices

Database Type

Apache Derby (select)

Driver Class

org.apache.derby.jdbc.EmbeddedDriver (automatically filled)

JDBC URL

jdbc:derby:../samples/DataService/database/DATA_SERV_SAMP

Username

wsas

Password

wsas

 

4-configuration.jpg

Step 4 – Creating a Data Service (Configuring SQL Query)

Now your here.

5-Query-screen.jpg

 

Fill first part of this screen with values from following table.

 

Field

Value

Query Id

allEmployees

SQL Statement

select FIRSTNAME, EMAIL from WSO2WSAS.EMPLOYEES

Grouping element name

Employees

Row name

Employee

 

 

Adding Result-to-output mapping

Enter following values to 'Add/Edit output mapping' section & click 'Store Mapping' button.

6-result-to-output-mapping-1.jpg

 

Your screen will be updated as follows.

 

6-result-to-output-mapping-2.jpg

 

Add another mapping with using following values.

 

<col width="312"></col> <col width="313"></col> <tbody> </tbody>

Field

Value

Select Type

Output Element

Element Name

Email

Column Name

EMAIL

 

Now the screen should look like this.

 

6-result-to-output-mapping-3.jpg

 

 

And the full screen would look like the following.

 

8-query-configuration.jpg

 

Hit 'Store Query' button and the query will be saved. Click on the 'Next' button to continue.

 

 

Step 4 – Creating a Data Service (Configuring Operation)

Your screen should now look like following. The drop down in front of 'query' field will list the name of the SQL Query (i.e. allEmployees) that we entered in the previous step.

9-add-operation.jpg

 

Fill the 'Operation Name' field with the value 'getAllEmployees' & hit 'Store Operation' button. Your screen should appear like this.

 

10-operation-added.jpg

 

Step 5 – Deploying Data Service
We are about to deploy our simple data service. But please take a moment to check the content inside 'Preview of Data Service Configuration' box. It should be equivalent to following.

 

<data name="EmployeeServices">
<config>
<property name="org.wso2.ws.dataservice.driver">org.apache.derby.jdbc.EmbeddedDriver</property>
<property name="org.wso2.ws.dataservice.protocol">jdbc:derby:../samples/DataService/database/DATA_SERV_SAMP</property>

<property name="org.wso2.ws.dataservice.user">wsas</property>
<property name="org.wso2.ws.dataservice.password">wsas</property>
</config>

<query id="allEmployees">
<sql>select FIRSTNAME, EMAIL from WS02WSAS.EMPLOYEES</sql>
<result element="Employees" rowName="Employee">
<element name="Name" column="FIRSTNAME" />
<element name="Email" column="EMAIL" />
</result>
</query>
<operation name="getAllEmployees">
<call-query href="allEmployees" />
</operation>
</data>

 

If your configuration is not matching, chances are that you have made a mistake in one of the above steps. Please start from the beginning. (You can edit the existing configuration. But for brevity of this Starter Guide, I will not go into details of editing. It will be available in next tutorial).

The content here is explained in Data Service Specification [1]. You will find a link to this under references section.

Deploy the Data Service by clicking 'Finish' button.

You will be taken to 'Services' screen & after a while following service will appear on the you screen.

11-Deployed-service.jpg

Step 6 – Testing the Deployed Service
Congratulations !!!!. You have deployed a Data service running within WSO2WSAS-2.0. Let's call the service & examine the output.

Since Data Service is similar to any other web service, you can invoke it as same as you invoke other web service. But to make things easy, lets use the 'Try it' feature in WSO2WSAS-2.0 to invoke the service. Carryout following steps and you will invoke the service with zero coding !!!.

Click on the 'Service' link for EmployeeServices.

12-invoking-service-1.jpg

 

You will be taken to a screen similar to following.

17-http-binding-url.jpg

 

Copy Http endpoint reference (which is 'http://192.168.2.3:9762/services/EmployeeServices' in my case), append '/getAllEmployees' to end of it.

Finally URL should look like,

http://192.168.2.3:9762/services/EmployeeServices/getAllEmployees

'EmployeeServices' is the service name for our data service & 'getAllEmployees' is the operation we created.

Paste the above on new browser window & press enter. You will get a result window similar to following.

18-http-binding-result.jpg

 

This XML output is generated using data in the database (retrieved against the SQL Query we supplied in a step 4). The element names are in sync with element names we provided under section 'Result-to-output mapping'.

 

Step 7 : Another way to test the service

Go to Service description page for 'EmployeeServices'. Click on 'Try it' link. (Highlighted in the image bellow)

14-service-screen.jpg

 

In the screen the follows, click on 'getAllEmployees' button to invoke the service.

 

16-Try-it-results.jpg

Author: Sumedha Rubasinghe sumedha at wso2 dot com

Suggested readings

References 1.Data Service Specification (http://wso2.org/wiki/display/wsf/Data+Services+and+Resources) 2. How to expose Excel 97-2002 spreadsheet as a Data Service using WSAS - 2.0 https://wso2.org/blog/sumedha/2581

  • This page was last modified 06:55, 1 October 2008.
Edit this article
Reddit Digg
 
Subscribe now

Special Offer For Webmonkey Users

WIRED magazine:
The first word on how technology is changing our world.

Subscribe for just $10 a year