Java Naming and Directory Interface (JNDI) is a Java API (application programming interface) providing naming and directory functionality for Java software clients to discover and look up data and objects via a name. WSO2 Data Services Server supports JNDI InitialContext implementation by inheriting the JNDI implementation of Tomcat (http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html). JNDI helps decouple object creation from the object look-up. When you have registered a datasource with JNDI, others can discover it through a JNDI lookup and use it.
Adding a JNDI datasource
You can create the JNDI data source as you create your data service by following the steps given below.
Log in to the management console and select Create under Data Service menu.
In the Create Data Service screen, enter JNDI as the data service name.
Click Next. When you get to the Add New Data Source screen, select JNDI Datasource as the data source type. The JNDI-specific options will be available for editing.
The options in the above window are explained below:JNDI Context Class: The corresponding context factory class
Provider URL: The URL which specifies the location of a resource on the Web.
Resource Name: The name of the JNDI resource.
You can also expose a RDBMS Carbon datasource as a JNDI datasource using the Configure > Datasources menu of the management console. For instructions, see Adding datasources.
Defining a query
Now let's start writing a query for getting data from the datasource. The query will specify the data that should be fetched by this query, and the format that should be used to display data when the query is invoked.
- Click Add New Query to open the Add New Query screen.
- Enter the following values:
- Query ID: Enter an ID for the query.
- Datasource: Select the datasource for which you are going to write a query. Select the JNDI datasource that you created previously.
SQL: In this field, enter the SQL statement describing the data that should be retrieved from the RDBMS datasource.
Add input mappings: Input mappings allow you to add parameters to a query so that you can set the parameter value when executing the query.
Find out more about defining Input Mappings in WSO2 DSS.
Add output mappings: Out mapping is used to specify how the data that is fetched from your query will be shown in the response.
Find out more about defining Output Mappings in WSO2 DSS.
- Click Next to open the Operations screen.
Define operation to invoke the query
Data service operations are written to invoke queries.
- Click Add New Operation to open Add New Operation screen.
- Add a name for your operation in the Operation Name field.
- In the Query ID field, select the query that you defined previously.
- Save the operation.
Finish 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.