Requirements:
- WSO2 DSS 2.5.1
- Jdk 1.6
- Mysql (for now), Oracle etc
Create Database:
Open mysql
Enter username/password – root/root
Command - Create database employeedb
Command - Use employeedb
In this example I have created a database with the name of “employeedb” and created an employee table in this db, as show below.
Insert some values in this table
Insert into employee values (1, ‘shri’, ‘noida’);
Insert into employee values (2, ‘pankaj’, ‘Faridabad’);
Insert into employee values (3, ‘Mohit’, ‘Delhi’);
You can see all the values by select query.
Select * from employee.
We have created database which has employee table, and this table has some values. Now we have to call these values from WSO2 DSS.
Let’s start with DSS...
DATA SERVICE SERVER:
Start the server from below location (double click on wso2server.bat file)
D:\...\wso2dataservices-2.5.1\bin\wso2server.bat
Server will be running on below address.
https://10.167.19.32:9443/carbon/admin/login.jsp
Enter Username/Password – admin/admin
You can see all the WebServices on clicking the of ‘List’ link under the ‘service’ tab.
Let’s create a new DSS service, click on create link under ‘dataservice’.
Enter “EmployeeDataService” in dataservice textbox, click next.
In next page fill all required fields
In this Example we are using mysql database so giving the details of mysql db, in case, we need to use oracle or any other database, then we need to change fields accordingly.
dataSource Id – dataSourceEmp
DataSource Type – RDBMS
Database Engine - Generic
Driver Class - com.mysql.jdbc.Driver
JDBC URL - jdbc:mysql://localhost:3306/employeedb
User Name – root
Password - root
After filling the entire required details click “Test Connection” button, if connection is ok then it will give a “successfully connected” popup message otherwise will give an error message.
Click “Save” button.
If we need to create or add more data Source the repeat the above process again otherwise click “Next” button.
In this Page fill all required fields.
Query Id – DataQueryEmp
Data Source – DataSourceEmp (It comes automatically after creating data source in previous page)
SQl - select id, name, address from employee
Now we need give input or output mapping.
When we have to take output according to given input, at that scenario we have to give input mapping here. In this example we are not giving any input criteria, just getting the output from the select query.
Only output mapping is needed here.
In the “Result (Output Mapping)” block define below property.
Grouped by element – employees
Row name – employee
Row namespace - http://test.org
For defining output mapping click “Add new output Mapping”.
In the database, employee table has 3 input and we have to take all 3 as output (as given in select query).
For that we are mapping all three elements here.
Below image is added for ‘id’ element
Below image is added for ‘name’ element
Below image is added for ‘address’ element
Click on “Main Configuration” button.
Click “Yes”.
Output mapping should look like below image.
Click “Save” button.
Now we have to create operations by which values or data from the db can be retrieved.
Click “Add new operations”
Give Operation Name - getEmployees
Query ID – Select “DataQueryEmp”.
Click “Finish” Button.
Our Service has been created.
Now there is a link “try this service” click on this.
Click on “getEmployee” button.
No comments:
Post a Comment