304 total views, 9 views today

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

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

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

 

Pre-Requisite

 

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

 

031417_2331_CreateaWebS1 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS2 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

1.3) Input a Project Name Click Next

 

031417_2331_CreateaWebS3 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

1.4) Input a package name and click Next

 

031417_2331_CreateaWebS4 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS5 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS6 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

1.7) Select Online Database Connection and Click Next

 

031417_2331_CreateaWebS7 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS8 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS9 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS10 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS11 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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 SessionEJB.java

 

 

 

031417_2331_CreateaWebS12 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS13 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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’

 

 

031417_2331_CreateaWebS14 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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 

 

031417_2331_CreateaWebS15 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS16 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

4.3) Click Next

 

031417_2331_CreateaWebS17 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS18 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

4.5) Click Next

 

031417_2331_CreateaWebS19 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS20 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS21 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

6. Deploy the Web Service

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

 

031417_2331_CreateaWebS22 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

6.2) Select Deploy to Application Server. Click Next

 

031417_2331_CreateaWebS23 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS24 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS25 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS26 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS27 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS28 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

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

 

031417_2331_CreateaWebS29 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

7.4) Output  rendered at the bottom of the page

 

031417_2331_CreateaWebS30 Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example

 

8. Download the Project

My Web Service Application

govindan Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example
Connect me

Govind

Thank you for visiting my personal blog. Myself Govindan, Software Developer by profession since 2006 and hence I started this blog early in 2016 and ever since I've been writing about technologies experienced and learnings of everyday life.

The views expressed on this blog are my personal views and do not necessarily reflect the views of my employer.

Please feeling free to reach me on any comments and feedbacks you have. Would be more than glad to listen and reply 🙂
govindan Create a Web Service from a table with OWSM Security using JDeveloper 12C - Example
Connect me
By | 2017-03-14T21:04:46+00:00 March 14th, 2017|Categories: Java, Jdeveloper|Tags: , , |0 Comments
Like us on Facebook.
Connect!