- 196K All Categories
- 2.1K Data
- 208 Big Data Appliance
- 1.9K Data Science
- 447.4K Databases
- 220.8K General Database Discussions
- 23 Multilingual Engine
- 516 MySQL Community Space
- 463 NoSQL Database
- 7.8K Oracle Database Express Edition (XE)
- 2.9K ORDS, SODA & JSON in the Database
- 469 SQLcl
- 3.9K SQL Developer Data Modeler
- 185.9K SQL & PL/SQL
- 20.9K SQL Developer
- 292.6K Development
- 7 Developer Projects
- 124 Programming Languages
- 289.4K Development Tools
- 95 DevOps
- 3K QA/Testing
- 645.5K Java
- 23 Java Learning Subscription
- 36.9K Database Connectivity
- 150 Java Community Process
- 104 Java 25
- 22.1K Java APIs
- 137.8K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 15 Java Essentials
- 143 Java 8 Questions
- 85.9K Java Programming
- 79 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.2K Java SE
- 13.8K Java Security
- 197 Java User Groups
- 238 LiveLabs
- 35 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.8K Other Languages
- 2.3K Chinese
- 166 Deutsche Oracle Community
- 1.2K Español
- 1.9K Japanese
- 225 Portuguese
Working with PL/SQL Web Service in JDeveloper 12c
By Kumar Abhishek Shahi
Numerous legacy systems that have Procedural Language/Structured Query Language (PL/SQL) code containing complex business logic are in migration. The business need is to reuse them and create an interface to expose them to various other systems..
Publishing the PL/SQL package as a Web Service is a simple solution to such scenarios:
- It reduces development effort because existing code can be re-used.
- The complex logic which has been put in the PL/SQL code which has been running over years and tested should not be re-written.
- Web Services built on top of it can be consumed by any application i.e. Web Application, Desktop Application, Mobile Interface as well as Portals and other Packaged Applications.
This Article focuses on:
- How we can publish a PL/SQL Package as Web Service using JDeveloper 12c.
- How we can consume those services in an ADF Application.
- JDeveloper 12c
- Oracle Database XE
- Basic PL/SQL knowledge
I have taken a simple use case of converting USD Amount to INR Amount.
In this exercise,
- I have created a sample PL/SQL package using DB Explorer in JDeveloper.
- Package has been exposed as a Web Service and tested using HTTP Analyzer.
- At the end, there is an ADF Web Application which consumes Web Service and displays it a beautiful UI using JSF Page.
Creating a PL/SQL Package to Convert USD to INR
- Open DB Explorer.
- Create a DB connection.
Note: Make sure HR schema is unlocked. Refer to Unlock HR Schema for more detail.
- Open SQL Worksheet to run SQL scripts.
- Create a package utility with a function to convert USD to equivalent INR amount.
create or replace PACKAGE Utility AS FUNCTION UsdToInr(usdAmt number) return number; END Utility;
Create package and function body.
create or replace PACKAGE BODY Utility AS FUNCTION UsdToInr(usdAmt IN number) RETURN number IS inrAmt number(5) := 0; BEGIN SELECT usdAmt*60 into inrAmt from dual; RETURN inrAmt; END UsdToInr; END Utility;
Publishing Package as a Web Service
Create custom application.
- Specify application name and package structure.
- Select Project Features “SOAP Web Service” and add it to the selected by clicking ">"
Click “Finish” to create application.
- To publish SQL Package as TOPLink DB Web Service Provider, Right Click on Project-> Click “From Gallery”
- Select TOPLink DB Web Service Provider and click OK.
- Go through the Web Service Provider Wizard
- Select PL/SQL Web Service Provider. (We are using SQL package to expose it as a Web Service.) Click Next.
- Specify required properties: Database Connection Name, Database Package, Web Service Name, etc. Click Next.
- Select the function that needs to be exposed as service.
- Click Finish. It will take a while to generate Web Service using Package.
Testing PL/SQL Web Service
- Right click on DBWSProvider.java.
- Select Test Web Service from the pop-up menu.
- HTTPAnalyzer will open. Enter USDAmount = 50 and click “Send Request.”
You can see that the result is displayed as 3000.
Copy the Web Service Definition Language (WSDL) URL for future use:
Creating User Interface to Consume Web Service
Create new ADF Fusion Web Application.
Specify Application Name and package structure.
Click Next and then Finish. An ADF Web Application will generate.
Create New Web Service Data Control using copied WSDL.
Create New Data Control. Select Web Service Data Control using SOA/REST.
Specify DC Name and WSDL. Check Copy WSDL Locally so that there is no need to hit the server to see whether WSDL is readable or not.
Select Response Format.
Click Finish to generate Data Control out of WSDL.
Create New JSF Page
Create JSF page.
Add one PanelGroupLayout and one panel box to it.
Expand DataControl and drag usdAmt as inputText. Change label to “Amount in USD.”
Drag BigDecimal as outputText. Change label to “Amount in INR.”
Drag Data Control as method->AdfButton. Change label to “Convert.” .Change ActionListener to Action for AdfButton.
- Save and run!
Exposing PL/SQL Package as Web Service is a proven solution which could be achieved using JDeveloper 12c. JDeveloper 12c enables developers to generate and consume Web Service from one IDE. PL/SQL Web Services offers greater flexibility, scalability and reuse of existing resources.
About the Author
Kumar Abhishek Shahi is a principal consultant at Oracle Corporation, Working as an Architect for Webcenter Portal and ADF-based solutions, including technical architecture evaluation, performance tuning, code review, creating POCs and developing full-fledged solutions.