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.
...
Start the WSO2 ESB profile.
Panel borderColor #542989 bgColor #ffffff borderWidth 1 Localtabgroup Localtab active true title On MacOS/Linux/CentOS Go to <EI_HOME>/bin and open Open a terminal and execute the following command:
Code Block ./integrator.shsudo wso2ei-6.6.0-integrator
Localtab title On Windows Go to Start Menu -> Programs -> WSO2 -> Enterprise Integrator 6.46.0 Integrator. This will open a terminal and start the ESB profile. - Open the ESB profile's Management Console using
https://localhost:9443/carbon
, and log in usingadmin
as the username and the password. Click Create under Data Service.
Enter
ExposeMySQLDatabaseService
as the name of the data service, and click Next.Click Add New Datasource and enter details for the new datasource as follows.
Datasource ID Datasource Datasource Type RDBMS Datasource Type (Default/External) Leave Default selected. Database Engine MySQL Driver Class com.mysql.jdbc.Driver
URL jdbc:mysql://localhost:3306/Company
User Name Enter your MySQL server's username. Example: root Password Enter your MySQL server's password.
If you have not assigned a password, keep this field empty.Enable OData Select this check box. Click Finish to save the data service.
Go to the Deployed Services screen and click the data service that you created.
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