Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Create a Web Service from a table with OWSM Security using JDeveloper 12C – Example

Create a Web Service from a table with OWSM Security using JDeveloper 12C 

In this section, we walk through how to create a Web Service from a table using Developer 12C. The following are the series of steps we are going to execute

1. Create a Java EE Web Application with a Table entity

2. Create an EJB Stateless Session Bean

3. Add a custom operation for Web Service

4. Create a Web Service with OWSM Security

5. Adjust the JNDI Name

4. Deploy the Web Service

6. Test the Web Service using Weblogic Web Service Test Client

8. Download the Project


  • JDeveloper & WebLogic 12C: to develop, deploy and test this project
  • JNDI Name in WebLogic Server for database lookup
  • HR Database Schema (Ships with Oracle database)

1. Create a Java EE Web Application with a Table entity

1.1) Open JDeveloper , Click File >> New >> Application >> Select Java EE Web Application and click Ok

1.2) Input an Application Name ‘MyWebServiceApplication’ and Click Next

1.3) Input a Project Name Click Next

1.4) Input a package name and click Next

1.5) Select Entries from Tables in Invoke Wizard and click Finish

1.6) The Create Entities from Tables wizard opens. Click Next

1.7) Select Online Database Connection and Click Next

1.8) Click on the green Plus icon to create a database connection, Input HR Database details click Ok and Click Next. I have created HR connection that bundled with Oracle database

1.9) Input % in the Name Filter and click on the button Query. This will retrieve all the tables from HR schema. Move the table COUNTRIES from Available to Selected list. Click Next, Next and Finish

2. Create an EJB Stateless Session Bean

A Stateless session bean is required to create a Web Service. To create Stateless Session Bean

2.1) Right click on the Model project, New, Gallery, select EJB under Business Tier and Select Session Bean

2.2. Input EJB Name, Session Type as Stateless, click multiple Next and Finish

3. Add a custom operation for Web Service

This step is optional. Here I have explained how to add a custom operation to a Web Service.

3.1. The EJB Stateless Session bean has been created under Model package. Let’s create a custom method for the web service. Add the following method signature in the interface

String getCountryByName(String country_name);

3.2) Add the same method signature in LOCAL interface as well

3.3) Now define the explanation of the custom method in the EJB Session Bean. The method asks for the country name as an argument and it return Country ID. For example, if the user input INDIA it will return ‘IN’

public String getCountryByName(String country_name){

Query query = em.createNativeQuery("select country_id from countries where country_name = ?");

query.setParameter(1, country_name);

String CountryId = (String) query.getSingleResult();

return CountryId;



4. Create a Web Service with OWSM Security

Here we are going to create a Web Service from the Stateless session bean with OWSM Security. Once the security is enabled, user requires WebLogic username and password to connect to the web service

4.1) Right click on the EJB Stateless Session bean and select Create Web Service 

4.2) Input a service name. This is your WSDL name.

4.3) Click Next

4.4) Select the method you want to expose in the Web Service. Click Next

4.5) Click Next

4.6) Toggle on OWSM Policies at the top and Choose oracle/wss_username_token_service_policy , Click Next and Finish

5. Adjust your JNDI Name

5.1) Open the persistence.xml file under META-INF, Adjust the data source name corresponding to your sever. I have deployed this application in WebLogic server and have JNDI name jdbc/HRDS which connected to the HR database


6. Deploy the Web Service

6.1) Right click on the Model project, Deploy and select EJBWebService

6.2) Select Deploy to Application Server. Click Next

6.3) Either select your WebLogic server or click on the Green Plus icon to add your WebLogic server. I have my WebLogic server (local) instance created already, So I have selected local here

6.4) Select your server and click Finish. I have selected AdminServer because in my local WebLogic, the JNDI ‘jdbc/HR’ pointed to AdminServer

6.5) You will receive the following message in the deployment log


7. Test the Web Service

7.1) Once the application deployment successful. Go to WebLogic Web Service Test Client. The default URL is http://HOATNAME:PORT/ws_utc. The deployed web service will be listed on the page. Click the one that associated to the one we deployed

Note: The Web Service test client is disabled on the Production environment. To enable, click on how to enable Web Service Test Client

7.2) Select CountryByName Operations on the left-hand side. Input argument as India and enter the WebLogic username and password

7.3) Click on the OWSM Tab, Toggle on oracle/wss_username_token_client_policy, Input your WebLogic username/password again and click the button Invoke

7.4) Output  rendered at the bottom of the page


8. Download the Project

My Web Service Application

This post first appeared on Oracle ADF, BPM, BI And Primavera P6 Tutorials, please read the originial post: here

Share the post

Create a Web Service from a table with OWSM Security using JDeveloper 12C – Example


Subscribe to Oracle Adf, Bpm, Bi And Primavera P6 Tutorials

Get updates delivered right to your inbox!

Thank you for your subscription