Exposing Pl/Sql as REST Web Service (Function Returning single value)

Perform following steps to expose Pl/SQL as a web service

 

1.       Create a Custom Package ,annotate it

2.       Create iLDT File

3.       Upload the iLDT File to Integration Repository.

4.       Search API in Integration Repository

5.       Deploy API as REST Service

6.       Create Grants for REST Service

7.       Invoke EBS REST Service (in JSON message format)

8.       Verify the results

 

Here we will take an example of Getting Employee Number based on Employee details provided when invoking the Web service.

 

Following steps will explain the process of exposing the Custom API that returns varchar variable as output when invoked.

 

Step 1: First Create a custom package xx_test_pkg with .pls extension and annotate it Only annotate the package specification. Below code was used for this Case study.

 

Package Specification:

/* Formatted on 19/7/2023 4:51:45 PM (QP5 v5.360) */
CREATE OR REPLACE PACKAGE xx_test_pkg
AS
    /* $Header: $ */

    /*#

    *  This interface returns the Employee Number.

    *  @rep:scope public

    *  @rep:product PER

    *  @rep:displayname xx_test_pkg

    *  @rep:lifecycle active

    *  @rep:compatibility S

    *  @rep:category BUSINESS_ENTITY PER_EMPLOYEE

    */

    /*#

    *  Returns Employee Number

    *  @param P_First_name VARCHAR2 First Name

    *  @param P_Last_name VARCHAR2 Last Name

    *  @param P_Email_address VARCHAR2 Email Address

    *  @return Employee_Number

    *  @rep:scope public

    *  @rep:lifecycle active

    *  @rep:displayname Return Employee Number

    */

    FUNCTION xxget_emp_number (p_first_name      IN VARCHAR2,
                               p_last_name       IN VARCHAR2,
                               p_email_address   IN VARCHAR2)
        RETURN VARCHAR2;
END xx_test_pkg;

Package Body

CREATE OR REPLACE PACKAGE BODY xx_test_pkg
AS
    FUNCTION xxget_emp_number (p_first_name      IN VARCHAR2,
                               p_last_name       IN VARCHAR2,
                               p_email_address   IN VARCHAR2)
        RETURN VARCHAR2
    AS
        xxreturn   VARCHAR2 (30);
    BEGIN
        SELECT 1
          INTO xxreturn
          FROM per_all_people_f
         WHERE     first_name = p_first_name
               AND last_name = p_last_name
               AND email_address = p_email_address;



        RETURN xxreturn;
    EXCEPTION
        WHEN NO_DATA_FOUND
        THEN
            RETURN 'No Data Found';
        WHEN OTHERS
        THEN
            RETURN 'Invalid Data';
    END xxget_emp_number;
END xx_test_pkg;

 

Step 2: Upload the .pls file to Oracle server.For our case study file was uploaded to custom_top Bin folder

Step 3: Create iLDT file by using following command and current Directory is where the .pls file was uploaded :

 

$IAS_ORACLE_HOME/perl/bin/perl      $FND_TOP/bin/irep_parser.pl     -g     -v     -username=sysadmin PER:patch/115/sql:xx_test_pkg.pls:12.0=xx_test_pkg.pls

 

Following message will appear after executing the command and it will generate ilDT file.




 

Step 4: Upload the generated iLDT file to Integration repository by using following command:

$FND_TOP/bin/FNDLOAD apps/apps 0 Y UPLOAD $FND_TOP/patch/115/import/wfirep.lct xx_test_pkg_pls.ildt





Step 5: Navigate to Integration Repository Responsibility, Click on Search.




Then on search Page enter “xx_test_pkg” in Internal Name and click on Go




 

Step 6: Click on the search result Link, it will display List of method available in the Interface Package.


 

Click on REST Web Service Tab

 


This page will display the Return Employee Number method.

 

Step 7: Now select Return Employee Number method ( we will create a user by invoking this Service once Deployed.) and enter Service Alias (This is mandatory) and then Click on Deploy button at bottom. You will receive message that service is successfully deployed and the status will be deployed.




 

Step 8: Now you will see the link to WADL file , Click on the link . It shows the physical location of the service endpoint where the service is hosted.

 

<?xml version="1.0" encoding="UTF-8"?>

<application xmlns:tns1="http://xmlns.oracle.com/apps/per/rest/get_emp_num/get_emp_number/ "                                 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://wadl.dev.java.net/2009/02" xmlns:tns="http://xmlns.oracle.com/apps/per/soaprovider/plsql/rest/XX_TEST_PKG/" targetNamespace="http://xmlns.oracle.com/apps/per/soaprovider/plsql/rest/xxtr c_get_emp_number_pkg/" name="XX_TEST_PKG"><grammars>

<include xmlns="http://www.w3.org/2001/XMLSchema" href="http://xxx-xxx-

apdv01.cli.ad:8005/webservices/rest/Get_Emp_Num/?XSD=GET_EMP_NUMBER_SYNCH_TYP EDEF.xsd"/></grammars>

<resources                                               base="http://xxx-xxx-

ap01.xx:8000/webservices/rest/Get_Emp_Num/"><resource path="get_emp_number/"><method                                      name="POST" id="GET_EMP_NUMBER"><request><representation        type="tns1:InputParameters" mediaType="application/xml"/><representation        type="tns1:InputParameters" mediaType="application/json"/></request><response><representation type="tns1:OutputParameters"       mediaType="application/xml"/><representation type="tns1:OutputParameters" mediaType="application/json"/></response></method></resource></resources></ap plication>

Now open the the link highlighted in Yellow in new Browser window, it will show the input parameters that will be used later for invoking the Web Service.

 

Step 9.Now Click on the Grants Tab, select return Employee Number and then click on Create Grant button





Step 10: Select a grantee type. In our Case Study we will enter SYSADMIN and then click on Create Grant Button.

 

It will display confirmation message:




 

To Revoke Grants click on Revoke Grants button under Grants Tab, it will display List of users with access for revoking the Grants.

To Undeploy the Web services select the method and click on undeploy under the REST Web Services Tab

 

Step 11: Now we will invoke this web service using Advanced REST Client apps available in Google Chrome.

Please refer to the steps from case study 1 to invoke the web service. For this case study following details were used:

 

Link:- http://xxx-xxx-ap01.xx:8000/webservices/rest/Get_Emp_Num/get_emp_number/

 

Payload:

 

{

"Get_Employee_Number": {

"@xmlns": "http://xmlns.oracle.com/apps/per/rest/Get_Emp_Num/get_emp_number", "RESTHeader": {

"xmlns": "http://xmlns.oracle.com/apps/per/rest/Get_Emp_Num/header", "Responsibility":"US_HRMS_MANAGER",

"RespApplication":"PER", "SecurityGroup":"STANDARD", "NLSLanguage":"AMERICAN", "Org_Id" :"201"

},

"InputParameters": { "P_FIRST_NAME": XX", "P_LAST_NAME": "XX"

}

}

}

 

Step 12: Enter the payload information and click on send. You will receive attached response.

 

{

"OutputParameters" : {

"@xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance",


"@xmlns"                                                                 :

"http://xmlns.oracle.com/apps/per/rest/Get_Emp_Num/get_emp_number/", "GET_EMP_NUMBER" : "1"

}

}

 

 




 

 

Exposing Standard API as REST Web Service and invoke

Perform following steps to expose Pl/SQL as a web service

 

1.       Search API in Integration Repository

2.       Deploy API as REST Service

3.       Create Grants for REST Service

4.       Invoke EBS REST Service (in JSON message format)

5.       Verify the results

 

Here we will take an example of creating a user by exposing FND_USER_PKG Interface API and then invoking it to create user.

 

Following steps will explain the process of exposing the standard API and then invoking it.

 

Step 1: Navigate to Integration Repository Responsibility, Click on Search.





 

Then on search Page enter “FND_USER_PKG” in Internal Name and click on Go




 

Step 2: Click on the search result, it will display List of methods available in the Interface Package.






Click on REST Web Service Tab



 


This page will display List of methods that can be deployed.

 

Step 3: Now select Create/Update User (we will create a user by invoking this Service once Deployed.) and enter Service Alias (This is mandatory) and then Click on Deploy button at bottom.

You will receive message that service is successfully deployed and the status will be deployed.




 

Step 4: Now you will see the link to WADL file, Click on the link. It shows the physical location of the service endpoint where the service is hosted.

 

<?xml version="1.0" encoding="UTF-8"?>

<application xmlns:tns1="http://xmlns.oracle.com/apps/fnd/rest/create_user/load_row/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://wadl.dev.java.net/2009/02" xmlns:tns="http://xmlns.oracle.com/apps/fnd/soaprovider/plsql/rest/fnd_user_p kg/" targetNamespace="http://xmlns.oracle.com/apps/fnd/soaprovider/plsql/rest/fnd_ user_pkg/"                              name="FND_USER_PKG"><grammars><include xmlns="http://www.w3.org/2001/XMLSchema"

 

href="http://xxx-xxx- apdv01.cli.ad:8005/webservices/rest/Create_User/?XSD=LOAD_ROW_SYNCH_TYPEDEF.x sd"/>

 

</grammars>

<resources                                               base="http://xxx-xxx-xx01.xx:8000/webservices/rest/Create_User/"><resource path="load_row/">

<method name="POST" id="LOAD_ROW"><request><representation type="tns1:InputParameters" mediaType="application/xml"/>

<representation type="tns1:InputParameters" mediaType="application/json"/>

</request>

</method>

</resource>

</resources>

</application>

 

Now open the link highlighted in Yellow in new Browser window, it will show the XSD file with input parameters that will be used later for invoking the Web Service.

 

Step 5.Now Click on the Grants Tab, select Create/Update User and then click on Create Grant button




 

Step 6: Select a grantee type.

Grantee Type can be one of the following values:

o    USER - The grantee is an individual user who was selected directly.

o    GROUP - The grantee is a group of users or a member of a group of users.

o    GLOBAL - The grant was issued to all users.

If you selected Specific User or Group of Users, specify the user or group for which to create the grants in the Grantee Name field.

 

In our Case Study we will enter SYSADMIN and then click on Create Grant Button.




 

It will display confirmation message:




To Revoke Grants click on Revoke Grants button under Grants Tab ,it will display List of users with access for revoking the Grants.

To Undeploy the Web services select the method and click on undeploy under the REST Web Services Tab

 

Step 7: Now we will invoke this web service using Advanced REST Client apps available in Google Chrome.

If not available download it from following link:


https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo

 

Now, after installing the REST client we will enter following details to invoke the web service:



Step 8: Enter the following header details:

Authorization by clicking on Add new header link then enters the application username/password by clicking on construct.




Then enter Accept, Content language




 


Select application/json in the Content Type below.

 

Step 9: Enter the following Link and payload information and click on send. The payload is constructed using the xsd file generated at Step 4.

 

Link : http://xxx-xxx-xx01.xx:8000/webservices/rest/Create_User/load_row/


Payload:

 

{

"Create_User": {

"@xmlns": "http://xmlns.oracle.com/apps/fnd/rest/create_user/load_row", "RESTHeader": {

"xmlns": "http://xmlns.oracle.com/apps/fnd/rest/Create_User/header", "Responsibility":"US_HRMS_MANAGER",

"RespApplication":"PER", "SecurityGroup":"STANDARD", "NLSLanguage":"AMERICAN", "Org_Id" :"201"

},

"InputParameters": { "X_USER_NAME": "XX_USER",

"X_ENCRYPTED_USER_PASSWORD": "XX_PWD", "X_START_DATE": "19/07/2023",

"X_EMAIL_ADDRESS": "xx_user@test.com"

}

}

}

 




Step 10: Now to verify if user is created query in FND_USER table to check the results.