Getting started with Data Services using WSO2 WSAS-2.0

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.

 

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.

Figure 02

Click on 'Define Data Service' link.

Figure 03

 

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

 

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

Now your here.

 

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.

 

Your screen will be updated as follows.

 

 

Add another mapping with using following values.

 

Field

Value

Select Type

Output Element

Element Name

Email

Column Name

EMAIL

 

Now the screen should look like this.

 

 

 

And the full screen would look like the following.

 

Figure 8

 

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.

Figgure 10

 

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

 

Figure 11

 

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.

Figure 12

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.

 

You will be taken to a screen similar to following.

 

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.

 

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)

 

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

 

Figure 16

 


References

1.Data Service Specification (http://wso2.org/wiki/display/wsf/Data+Services+and+Resources)

 

AttachmentSize
EmployeeServices.txt780 bytes
cllewisl062.gmail.com's picture

Great blog, this could be

Great blog, this could be the best blog I ever visited this month. Never stop to write something useful dude! Carl blog
latex.mattress.yahoo.com's picture

Thanks for the step. I have

Thanks for the step. I have tried to follow your step, but I have been find a problem to operate this system. free ads |part time jobs|latex mattress

yorusamasan.gmail.com's picture

You saved my alot of time

You saved my alot of time thank you so much for sharing your experience. Keyword Elite 2
halloween's picture

Indeed, too bad one can't

Indeed, too bad one can't just call a stored procedure to perform the login itself........ I'm currently using SHA1 to store hashes of passwords and i'm lost on how to compare login data....

feliduca's picture

n my very limited

n my very limited experience, exposing data sources as webservices with a very minimal amount of coding is the holy grail of SOA, even though about every single sw architect I ever met is against this principle.

It is based on the 80/20 rule: after designing your service, 80% of the changes will be to the data model and will have to be reflected directly into the service interface (double work!). 20% of the changes will be to to the data model and not require an interface change (work saved).

As an down-to-earth example, we always add new fields to existing queries, but very seldom change the database while keeping the same webservice interface (usually when you change db the app gets a major version upgrade too, with new/extended capabilities thrown in).

That's wht I built my own SOA architecture around the design of directly exposing data sources (eg query and recordset objects), while making the webservice layer completely transparent to the coder.

To just shield client away from direct table access, implement all db access via stored procedures, and you got the holy grail.

______________________
Submited by : Libros Gratis

billxa's picture

Welcome

It is great that WSO2 is adding this data services capability.  xaware.org, an open source data integration toolset, is built around the idea of data services.  The xaware project offers complemetary capabilities - bi-directional, multi-source, multi--format, multi-consumer, SOAP, POX/REST access to exiting data sources as services mash-ups.  Those of us in the xaware data services community welcome WSO2 and hope we can collaborate to drive innovation in making existing data available as services.  Bill Miller,  XAware

afkham_azeez's picture

installation failure

Hi,

I tried out XAware. Downloaded the full Linux distribution which is close to 500MB. However, when I tried to run the installer, it simply failed without a proper error message. Here is my console output:

-----------------------------------------------------------------------------------

azeez@delly:/software$ ./install.bin
Preparing to install...
Extracting the JRE from the installer archive...
Unpacking the JRE...
Extracting the installation resources from the installer archive...
Configuring the installer for this system's environment...

Launching installer...

/libjvm.so'.mp/install.dir.2619/Linux/resource/jre/lib/i386/server

-----------------------------------------------------------------------------------

Any idea what is wrong?

 

Regards

Afkham Azeez

billxa's picture

You should be able to find

You should be able to find help with this on the XAware forums at http://www.xaware.org/component/option,com_fireboard/Itemid,3/

Latest Webinar
Sumedha Rubasinghe, an Architect and Product Manager of WSO2 will explain you how to create your own web applications using WSO2 Cloud platform, WSO2 Stratos.
Wednesday, August 4, 10.00 AM (PDT)

Wednesday, August 4, 9.00 AM (GMT)