Vous êtes sur la page 1sur 11

1) Install ORDS via SQL Developer for development purpose in local system.

Download apex Image war file:


https://dbamon.dev.redhat.com/orawebsite/downloads/apex_images.war
Create Apex Image directory in local system and use its path during installation of ORDS. (i.e.
jar xvf apex_image.war)
Install ORDS as per below web site.
https://www.oracle.com/webfolder/technetwork/tutorials/obe/db/ords/r30/Install_Administer_ORD
S/Install_Administer_ORDS.html#section2

once installed and running check from browser http://localhost:8080/ords/

2) Enable database schema


BEGIN
ORDS.ENABLE_SCHEMA(p_enabled => TRUE,
p_schema => 'APPS',
p_url_mapping_type => 'BASE_PATH',
p_url_mapping_pattern => 'apps',
p_auto_rest_auth => FALSE);
end;

3) Create Administer and Developer connection in sql developer.


a) Go to View→ Rest Data Services → Administration. Create connection as follows.

b) Go to View→ Rest Data Services → Development. Create connection as follows. Schema name
must be the name of the schema which was enabled in above step #2.
4) Expose table as Rest web service
https://www.oracle.com/webfolder/technetwork/tutorials/obe/db/ords/r30/AutoREST
%20Enable/AutoREST%20Enable.html#section1

5) Devleope View or query and expose it as Rest web service


https://www.oracle.com/webfolder/technetwork/tutorials/obe/db/ords/r30/REST
%20Development/REST%20Development.html#section4
a) Create Module using Get method and below query without parameter.
select hp.party_name,hca.account_number
, cursor(select hl.address1
, hl.address2
,hl.address3
,hl.state
,hl.county
,hl.postal_code
,hl.country
,cursor(
select hcsu.site_use_code
from apps.hz_cust_site_uses_all hcsu
where hcsu.cust_acct_site_id = hcas.cust_acct_site_id
)site_uses
from apps.hz_parties hp
, apps.hz_cust_acct_sites_all hcas
, apps.hz_party_sites hps
, apps.hz_locations hl
where hp.party_id = hca.party_id
and hp.party_id = hps.party_id
and hcas.cust_account_id = hca.cust_account_id
and hcas.party_site_id = hps.party_site_id
and hps.location_id = hl.location_id) sites
from apps.hz_cust_accounts_all hca
, apps.hz_parties hp
where hca.party_id = hp.party_id
and rownum < =10
b) Check the details of module. Observe url pattern http://localhost:8080/ords/xxrhops/xxrhops/tca.
This url will be used to call this rest web service.

6) Expose plsql procedure as Rest webservice using ORDS.


https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-remote-procedure-call-rpc-and-
output-parameters
https://oracle-base.com/articles/misc/oracle-rest-data-services-ords-create-basic-rest-web-services-
using-plsql

a) Ex: Accept parameter in Json format(3 level) via plsql procedure and provide output in
Json format(3 level). In below scenario we are providing OU name, Order Status and Sold to
Customer name in Json format as parameter to xxrh_ont_ords.get_order.
xxrh_ont_ords.get_order returns order details as response to caller.
I) Create package in database:

CREATE OR REPLACE PACKAGE xxrh_ont_ords


as
procedure get_order(p_order_enquiry IN clob
,p_order_out OUT SYS_REFCURSOR
);
end xxrh_ont_ords;
/
CREATE OR REPLACE PACKAGE body xxrh_ont_ords
AS
procedure get_order(p_order_enquiry IN clob
,p_order_out OUT SYS_REFCURSOR
)
IS
--l_ord_ref IS REF CURSOR;
CURSOR json_cur(v_json clob)
IS
SELECT json1.ou_name
,json1.order_status
,json1.sold_to_cust
FROM XMLTABLE('/json/row' PASSING APEX_JSON.to_xmltype(v_json)
COLUMNS
ou_name VARCHAR2(240) PATH '/row/ou_name',
order_status VARCHAR2(240) PATH '/row/l2/order_status',
sold_to_cust VARCHAR2(240) PATH '/row/l2/l3/sold_to_cust'
) json1;
r_json_cur json_cur%ROWTYPE;
l_order_number oe_order_headers_all.order_number%TYPE;

BEGIN

OPEN json_cur(p_order_enquiry);
FETCH json_cur INTO r_json_cur;
CLOSE json_cur;
APEX_JSON.initialize_clob_output;
insert into xxrh_ords_temp values('r_json_cur.sold_to_cust:'||r_json_cur.sold_to_cust);
insert into xxrh_ords_temp values('r_json_cur.order_status:'||r_json_cur.order_status);
insert into xxrh_ords_temp values('r_json_cur.order_status:'||r_json_cur.ou_name);
OPEN p_order_out FOR SELECT ooh.order_number
, ooh.sold_to sold_to_customer
, ooh.price_list price_list
, ooh.sold_to_contact
, ooh.flow_status_code
, ooh.org_name
, cursor(
SELECT ool.line_number
,ool.ordered_item
,ool.ordered_quantity
,cursor (
SELECT ools.line_number
, ools.ordered_item
, ools.ordered_quantity
FROM oe_order_lines_all ools
WHERE SERVICE_REFERENCE_LINE_ID = ool.line_id
AND SERVICE_REFERENCE_TYPE_CODE = 'ORDER'
) service_line
FROM xxrhops.xxrh_oe_order_lines_v ool
WHERE ool.header_id = ooh.header_id
AND ool.SERVICE_REFERENCE_LINE_ID is null
) main_line
FROM xxrhops.xxrh_oe_order_headers_v ooh
WHERE header_id in (4076868,4076865,4076864,4076866,4076867,4076863)
AND UPPER(ooh.org_name) = UPPER(r_json_cur.ou_name)
AND UPPER(ooh.sold_to) = UPPER(r_json_cur.sold_to_cust)
AND UPPER(ooh.flow_status_code) = UPPER(r_json_cur.order_status);

END get_order;
END xxrh_ont_ords;
/

II) Create Rest webservice via ORDS.


→ connect to REST Development as below.

→ Create new module as described in oe-pkg module in below image. Here “R1” will be input
parameter to web service in Json format and “orders” is response to caller from web service in Json.
Note the URI from ORDS.

III) Test the webservice via Postman as below.


URI : http://localhost:8080/ords/apps/oe-pkg/get-orders
Parameter : R1 : [{
"ou_name": "RH US Operating Unit",
"l2": {
"order_status": "ENTERED",
"l3": {
"sold_to_cust": "SunGard Data Systems Inc."
}
}
}]
Method : POST

Click on send and get the response as below.


b) Ex: In this example create a procedure to create hz party using api. Build Rest webservice
to invoke this procedure.

I) Create this procedure in database.


create or replace PROCEDURE xxrh_ords_ar_create_party_prc(p_party_name IN VARCHAR2)
AS
p_organization_rec apps.HZ_PARTY_V2PUB.ORGANIZATION_REC_TYPE;
x_return_status VARCHAR2(2000);
x_msg_count NUMBER;
x_msg_data VARCHAR2(2000);
x_party_id NUMBER;
x_party_number VARCHAR2(2000);
x_profile_id NUMBER;

BEGIN
p_organization_rec.organization_name := p_party_name;
p_organization_rec.created_by_module := 'XXRHOPS';

apps.hz_party_v2pub.create_organization (
'T',
p_organization_rec,
x_return_status,
x_msg_count,
x_msg_data,
x_party_id,
x_party_number,
x_profile_id);

dbms_output.put_line(SubStr('x_return_status = '||x_return_status,1,255));
dbms_output.put_line('x_msg_count = '||TO_CHAR(x_msg_count));
dbms_output.put_line(SubStr('x_msg_data = '||x_msg_data,1,255));

IF x_msg_count >1 THEN

FOR I IN 1..x_msg_count

LOOP
dbms_output.put_line(I||'. '||SubStr(apps.FND_MSG_PUB.Get(p_encoded =>
apps.FND_API.G_FALSE ), 1, 255));

END LOOP;
commit;
END IF;
END xxrh_ords_ar_create_party_prc;
II) Create Module with “Post” method and invoke above procedure.

Check the url in details section

This URI http://localhost:8080/ords/apps/ar/create_party will be used to test this rest webservice


from SOAP UI.

III) Test Rest Web service “Get” method via browser.


Take #5 b) as an example, http://localhost:8080/ords/xxrhops/xxrhops/tca is the url to test rest
web service and this can be invoked locally from browser.

IV) Test Rest Web service “Post” method via SOAP UI.
Post method can only be tested via SOAP UI or any other tool except browser.
Here is the way to test post method and invoke plsql procedure using rest webservice from SOAP
UI. In this considering extample created above in #6(a) and Rest url is
http://localhost:8080/ords/apps/ar/create_party.

Vous aimerez peut-être aussi