Exposing a Datasource as a Data Service
com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Exposing a Datasource as a Data Service

In this tutorial, we will run through the process of service enabling an RDBMS as a data service.  For more information on the datasource types supported by WSO2 EI, see the What's Next section.

Before you begin!

Follow the steps given below to set up a MySQL database for this tutorial.

  1. Install the MySQL server.

  2. Download the product installer from here, and run the installer.

  3. Download the JDBC driver for MySQL from here and copy it to your <EI_HOME>/lib directory.

  4. Create a database named Employees.

    CREATE DATABASE Employees;
  5. Create the Employee table inside the Employees database:

    USE Employees; CREATE TABLE Employees (EmployeeNumber int(11) NOT NULL, FirstName varchar(255) NOT NULL, LastName varchar(255) DEFAULT NULL, Email varchar(255) DEFAULT NULL, Salary varchar(255));

Let's get started

Creating the data service

Follow the steps given below.

  1. Start the WSO2 ESB profile.

  2. Open the ESB profile's Management Console using https://localhost:9443/carbon, and log in using admin as the username and the password.

  3. Click Data Service → Create, to start creating a data service.

  4. Enter the following name for the data service.

  5. Click Next to enter the datasource connection details.

Connecting to the datasource

Follow the steps given below.

  1. Click Add New Datasource and enter the following details:

  2. Save the datasource.

  3. Click Next, to start creating queries.

Creating a query to Get data

Let's create a query that can retrieve employee data, based on the employee number. That is, when the employee number is provided as an input, the data service should get the relevant employee details and present the result.

  1. Click Add New Query to start creating a new query.

  2. Enter the following details:

  3. Click Generate Input Mapping to create the input mapping. The employee number is the input as shown below.

  4. Click Generate Response to create the output mapping. This defines how the employee details retrieved from the datasource will be presented in the result. Note that, by default, the output type is XML. 

  5. Save the query.

Creating a query to Post data

Let's create another query to post new employee data to the datasource.

  1. Click Add New Query to start creating a new query.

  2. Enter the following details:

  3. Click Generate Input Mapping to create the input mapping. You need to specify values for the following elements when posting new employee data.

  4. Save the query.

Creating a query to Update data

Now, let's create a query that can update an existing employee record in the datasource.

  1. Click Add New Query to start creating a new query.

  2. Enter the following details:

  3. Click Generate Input Mapping to create the input mapping. You need to specify values for the following elements when posting new employee data.

  4. Save the query.

You should now have the following three queries created:

Create SOAP operations to invoke queries

Now, let's create SOAP operations to invoke the queries created above. Alternatively, you can create REST resources to invoke the queries. See the next section for instructions.

  1. Click Add New Operation and enter the details as shown below.

  2. Save the operation.

  3. Click Add New Operation and enter the details as shown below.

  4. Save the operation.

  5. Click Add New Operation and enter the details as shown below.

  6. Save the operation.

You can now invoke the data service query using SOAP.

Create REST resources to invoke queries

Now, let's create REST resources to invoke the queries created above. Alternatively, you can create SOAP operations to invoke the queries. See the previous section, for instructions.

  1. Click Add New Resource and enter the details as shown below.

  2. Save the resource.

  3. Click Add New Resource and enter the details as shown below.

  4. Save the resource.

  5. Click Add New Resource and enter the details as shown below.

    Save the resource.

  6. Click Finish to complete creating the data service.

Once you have defined the operation, click Finish to complete the data service creation process. You will now be taken to the Deployed Services screen, which shows all the data services deployed on the server.
You can now invoke the data service query using REST.


com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.