Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In this tutorial, we will run through the process of exposing and RDBMS as an OData service. When OData is enabled for a datasource, you do not need to manually define CRUD operations. They are automatically created.

...

  1. Download the product installer from here, and run the installer.
    Insert excerpt
    EI6xx:Installing the ProductEI6xx:
    Installing the Product
    nopaneltrue

  2. Install the MySQL server.
  3. Download the JDBC driver for MySQL from here and copy it to your <EI_HOME>/lib directory.
  4. Create a MySQL database named CompanyAccounts.

    Code Block
    CREATE DATABASE CompanyAccounts;
  5. Create a table in the CompanyAccounts database as follows.

    Code Block
    CREATE TABLE ACCOUNT(AccountID int NOT NULL,Branch varchar(255) NOT NULL, AccountNumber varchar(255),AccountType ENUM('CURRENT', 'SAVINGS') NOT NULL,
    Balance FLOAT,ModifiedDate DATE,PRIMARY KEY (AccountID)); 
  6. Enter the following data into the table:

    Code Block
    INSERT INTO ACCOUNT VALUES (1,"AOB","A00012","CURRENT",231221,'2014-12-02');

...

  1. Start the WSO2 ESB profile.

    Panel
    borderColor#542989
    bgColor#ffffff
    borderWidth1
    Localtabgroup
    Localtab
    activetrue
    titleOn MacOS/Linux/CentOS

    Go to <EI_HOME>/bin and open a terminal and execute the following command:

    Code Block
    ./integrator.sh
    Localtab
    titleOn Windows
    Go to Start Menu -> Programs -> WSO2 -> Enterprise Integrator 6.4.0 Integrator. This will open a terminal and start the 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 Add New Datasource and enter details for the new datasource as follows.

    Datasource IDDatasource
    Datasource TypeRDBMS
    Datasource Type (Default/External)Leave Default selected.
    Database EngineMySQL
    Driver Classcom.mysql.jdbc.Driver
    URLjdbc:mysql://localhost:3306/Company
    User NameEnter your MySQL server's username. Example: root
    PasswordEnter your MySQL server's password. 
    If you have not assigned a password, keep this field empty. 
    Enable ODataSelect this check box.

Access the data service using CRUD operations

Open a command prompt execute the following CURL commands using CRUD operations:

Note

Note that you should have privileges to perform CRUD operations on the database. If not, the OData service will not work properly.

  • To get the service document:

    Code Block
    curl -X GET -H 'Accept: application/json' http://localhost:9763/odata/ExposeDatabaseService/Datasource
  • To get the metadata of the service:

    Code Block
    curl -X GET -H 'Accept: application/xml' http://localhost:9763/odata/ExposeDatabaseService/Datasource/$metadata
  • To read details from the ACCOUNT table:

    Code Block
    curl -X GET -H 'Accept: application/xml' http://localhost:9763/odata/ExposeDatabaseService/Datasource/ACCOUNT