Oracle APEX 安装Oracle REST Data Services (ORDS) 教程

时间:2024-03-24 13:46:02

1- Introduction

Tài liệu được viết dựa trên:
  • Oracle 11g, 12c

  • ORDS 3.x

2- What is Oracle REST Data Services?

Oracle REST Data Services (ORDS)  is a data service which is used to replace Oracle HTTP server and mod_plsql. It bases on Java EE that provides RESTful service and increases security capability. it can deploy on WebLogic, Tomcat, Glassfish  or independently.
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程

3- Interaction between Oracle and Oracle APEX ORDS

Normally, there are two ways to install Oracle APEX. 

Method 1:
 Configure the Embedded PL/SQL Gateway: This is the way to configure Oracle APEX which  can run on Oracle XML DB HTTP Server, it is a HTTP that is available when you install Oracle 11g or higher. 

Method 2: Install Oracle APEX on a specific web server such as WebLogic, Tomcat or Glassfish, ... 

Link worked with Oracle APEX as followed:
  • http://your-server:8080/apex
To use RESTful services, you need to install  Oracle ORDS which can deploy on WebLogic Server, Tomcat, Glassfish,.. or independently. Oracle ORDS can read directly to Oracle APEX and replace completely Oracle HTTP Server, therefore you can use  RESTful on APEX and new URL to work with  Oracle APEX.
  • http://your-server:8080/ords
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程

4- Download Oracle ORDS

You can download Oracle ORDS at:
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Download results:
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程

5- Config ORDS for APEX

CD to apex home directory.
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Login to sqlplus as sysdba.
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Run the command to configure REST Service.
1
2
3
4
-- Configuring REST Service.
 
 
@apex_rest_config.sql
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Sau khi lệnh trên thực thi thành công, 2 user APEX_LISTENER và APEX_REST_PUBLIC_USER đã được tạo ra.
  1. APEX_LISTENER - The account used to query RESTful Services definitions stored in Oracle Application Express.
  2. APEX_REST_PUBLIC_USER - The account used when calling RESTful Services definitions stored in Oracle Application Express.

Enable Network Services

By default, Network Services are disable in Oracle 11g or the newer version. Therefore, you must use the package ofDBMS_NETWORK_ACL_ADMIN in order to to grant connect privileges to any host for the APEX_050000 database user
You need to query to view the APEX users in the database:
1
Select Username from All_Users where username like 'APEX%';
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Run command to grant connect privileges to any host for the APEX_050000 database user.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Declare
   Acl_Path Varchar2(4000);
Begin
   -- Look for the ACL currently assigned to '*' and give APEX_050000
   -- the "connect" privilege if APEX_050000 does not have the privilege yet.
   Select Acl
   Into   Acl_Path
   From   Dba_Network_Acls
   Where  Host = '*'
   And    Lower_Port Is Null
   And    Upper_Port Is Null;
   If Dbms_Network_Acl_Admin.Check_Privilege(Acl_Path
                                            ,'APEX_050000'
                                            ,'connect') Is Null Then
      Dbms_Network_Acl_Admin.Add_Privilege(Acl_Path
                                          ,'APEX_050000'
                                          ,True
                                          ,'connect');
   End If;
Exception
   -- When no ACL has been assigned to '*'.
   When No_Data_Found Then
      Dbms_Network_Acl_Admin.Create_Acl('power_users.xml'
                                       ,'ACL that lets power users to connect to everywhere'
                                       ,'APEX_050000'
                                       ,True
                                       ,'connect');
      Dbms_Network_Acl_Admin.Assign_Acl('power_users.xml'
                                       ,'*');
End;
/
 
Commit;
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程

Grant connect for APEX_050000 user (If database is Oracle 11g):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Declare
   Acl_Path Varchar2(4000);
Begin
   -- Look for the ACL currently assigned to '*' and give APEX_050000
   -- the "connect" privilege if APEX_050000
   --does not have the privilege yet.
   Select Acl
   Into   Acl_Path
   From   Dba_Network_Acls
   Where  Host = '*'
   And    Lower_Port Is Null
   And    Upper_Port Is Null;
   If Dbms_Network_Acl_Admin.Check_Privilege(Acl_Path
                                            ,'APEX_050000'
                                            ,'connect') Is Null Then
      Dbms_Network_Acl_Admin.Add_Privilege(Acl_Path
                                          ,'APEX_050000'
                                          ,True
                                          ,'connect');
   End If;
Exception
   -- When no ACL has been assigned to '*'.
   When No_Data_Found Then
      Dbms_Network_Acl_Admin.Create_Acl('power_users.xml'
                                       ,'ACL that lets power users to connect to everywhere'
                                       ,'APEX_050000'
                                       ,True
                                       ,'connect');
      Dbms_Network_Acl_Admin.Assign_Acl('power_users.xml'
                                       ,'*');
End;
/
 
Commit;

Grant connect for APEX_050000 user (If database is Oracle 12c):

Procedures CREATE_ACL, ASSIGN_ACL, ADD_PRIVILEGE and CHECK_PRIVILEGE in DBMS_NETWORK_ACL_ADMIN are deprecated in Oracle Database 12c. Oracle recommends using APPEND_HOST_ACE instead.
1
2
3
4
5
6
7
8
9
10
-- Sử dụng cho Oracle 12c.
 
BEGIN
    DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
        host => '*',
        ace => xs$ace_type(privilege_list => xs$name_list('connect'),
                           principal_name => 'APEX_050000',
                           principal_type => xs_acl.ptype_db));
END;
/
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程

6- Deploying ORDS

Note: you must sure that you have installed Jave version 7 or higher and declare PATH variable. You can see how to install Java at:
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Add the path to bin folder of Java at the end of PATH
  • ;C:\DevPrograms\Java\jdk1.8.0_65\bin
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Unzip the file ord - **. zip that you have downloaded to a folder
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
You can see that in the folder unzipped have ords.war file
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Copy  images folder in apex to ords folder:
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Now, we will install  Oracle ORDS independently (It is not necessary to deploy on Weblogic, Tomcat or other web server)
CD to ords folder:
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Next, login sqlplus as sysdba.
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Your Oracle APEX is running on Oracle XML DB  HTTP Server, you should disable it with the command:
1
2
3
4
5
6
7
8
--  Disable Oracle APEX on Oracle XML DB HTTP Server.
 
EXEC DBMS_XDB.SETHTTPPORT(0);
 
 
-- Note: You can enable it with command:
 
EXEC DBMS_XDB.SETHTTPPORT(8080)
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Exit sqlplus. And CD to ords:
Run command:
1
2
3
4
5
6
7
# Run command:
 
java -jar ords.war
 
# Or:
 
java -jar ords.war install
Enter the address of the machine that contains the database (default is localhost):
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Port of database (Default is 1521):
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Enter Service Name or SID of database:
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Enter password for ORDS_PUBLIC_USER
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Sqlplus requests to re-enter the user database information with sysdba rights. (Enter sys and then password).
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
SQLPlus will ask whether you use Oracle APEX or not, if yes let's enter 1, then press "enter" to continue.
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Entering a password for user will be created (APEX_PUBLIC_USER):
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Next, enter 1 to specify password for 2 newly created  user database (APEX_LISTENER, APEX_REST_PUBLIC_USER).
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Select 1 to start ORDS in standalone mode:
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
You have configured ORDS successfully. Close CMD window
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程

Running ORDS

Note: You can run the command below to see the help:
1
java -jar ords.war help standalone
CD to ORDS folder and run command:
1
java -jar ords.war standalone --port 8080 --apex-images C:/DevPrograms/ords/images
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
For the 1st time, it will ask where to place configure file:
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
ORDS has been successfully deployed.
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Note: If you receive an error:
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Unlock for APEX_PUBLIC_USER user
1
2
3
4
5
6
7
8
Column username format a25;
Column account_status format a25;
 
-- Query unlocked APEX user.
 
select username,account_status from dba_users
 where lock_date is not null
 and username like 'APEX%';
1
Alter user APEX_PUBLIC_USER account unlock;
The configure file is also created after you deployed ORDS:
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程
Don't close the window above, you can use APEX with new url:
Oracle APEX 安装Oracle REST Data Services (ORDS) 教程