[Download] | [Documentation Home] | [Release Note]
The purpose of this guide is to get you started on creating and invoking a data service using WSO2 Data Services Server as quickly as possible. We'll create a simple data service using Data Services Server creation wizard and then look at creating clients to access that service.
WSO2 Data Services Server is a convenient mechanism to provide a web service interface for data stored in some data sources. Data sources such as relational databases, CSV files, Microsoft Excel files and google spread sheets can be easily service enabled using Data Services Server. Now, the data can be exposed and accessed in a secured(using WS-Security) and reliable(using WS-ReliableMessaging) manner, and is also available for mashing-up with other Web services.
You can download WSO2 Data Services Server from the following location.
[Download WSO2 Data services Server ]
Figure 1: WSO2 Data Services Server Home Page
This guide assumes MySQL is configured in your system. If not, please download MySQL 5 or later version from here.
Lets create a simple data base with one table. Open a command prompt and type 'mysql -u root -p' to access mySQL prompt. If you installed mySQL default configurations, you may enter blank password and access mySQL prompt. Enter the following commands to create a sample database, create a table and populate sample data.
mysql>create database employeedb;
mysql>use employeedb;
mysql>create table employee(id VARCHAR(10) NOT NULL PRIMARY KEY, name VARCHAR(100), address VARCHAR(100));
mysql> insert into employee values('01','john','Boston');
mysql> insert into employee values('02','Micheal','Dallas');
mysql> insert into employee values('03','richard','Chicago');
mysql> exit;
Since we are using a MySQL database for our demonstration, we should copy mySQL JDBC driver to CARBON_HOME/repository/components/lib directory (e.g:- cp mysql-connector-java-5.0.3-bin.jar /home/user/wso2ds/wso2-dataservices-2.5.0/repository/components/lib).
After copying the necessary jdbc driver, make sure to restart WSO2 Data services solution server.
We are ready to create our first data service using WSO2 Data Services Server. We will make use of the sample MySQL 'employeedb' database we have created in the previous step.
Figure 2: WSO2 Data Services Server Create Data Service page
Now we can enter the data source details in this step. Let's start with giving a name for the data source as 'DataSourceEmp'.
Select the data source type as 'RDBMS' and enter the following values.
Database Engine = MySQL
Driver Class = com.mysql.jdbc.Driver
JDBC URL = jdbc:mysql://localhost:3306/employeedb
User name = root
Figure 3: Create Data source
Click on 'Save' button. You will see the created data source as follows.
Figure 4: Created data sources list
Query ID = DataQueryEmp
SQL Statement = select id, name, address from employee
Grouped by Element = Employees
Row name = Employee
Row namespace = http://test.org
Mapping Type = Element
Output field name = id
Data source column Name = id
Schema Type = xs:string
Mapping Type = Element
Output field name = name
Data source column Name = name
Schema Type = xs:string
Mapping Type = Attribute
Output field name = address
Data source column Name = address
Schema Type = xs:string
We have added one query to our data service configuration. In this example, we do not use an SQL statement which accepts input parameters. Therefore, we can ignore 'Input Mappings'.
Figure 5: Add New Querry
Figure 6: Add New Operations
You will notice that the query we have created in the previous step will be shown in 'Query' dropdown of the 'Add New Operation' window. Provide a name for the operation (e.g:- getEmployees) and click on 'Save'.
Your new data service will be listed in 'Deployed Services' page as follows.
Figure 7: Deployed Services
In this section, we'll look at two different ways to invoke our data service without writing single line of code. First we will invoke our data service using 'Tryit' utility which integrated in to WSO2 Data Service Server Management console. Then we invoke it using a simple HTTP GET request.
Figure 8: Service Management
Figure 9: Try-it
Click on 'getEmployees' button to invoke our data service. You will get the response message in the same page. Note that employee id and name will be returned as xml elements and address will be wrapped as an attribute. This is due to our output mapping configuration at step 2 of the wizard. We have configured id and name as element mapping types and address as attribute mapping type. You can edit them and observe the associated changes in response very easily using Tryit.
http://localhost:9763/services/EmployeeDataService/getEmployees
You will get the same result back as in 'Tryit' approach
For more details on the Data services see User Guide