2 Configuring Oracle REST Data Services (Advanced)

This section explains how to configure Oracle REST Data Services for connecting to multiple databases for routing requests, and it refers to other documentation sources for other configuration information.

Note:

Oracle REST Data Services must be restarted after making configuration changes. See your application server documentation for information on how to restart applications.

Topics:

2.1 Configuring Multiple Databases

Oracle REST Data Services supports the ability to connect to more than one database. This section describes different strategies for routing requests to the appropriate database.

Topics:

2.1.1 About the Request URL

Oracle REST Data Services supports a number of different strategies for routing requests to the appropriate database. All of these strategies rely on examining the request URL and choosing the database based on some kind of match against the URL. It is useful to recap the pertinent portions of a request URL. Consider the following URL:

https://www.example.com/ords/sales/f?p=1:1

This URL consists of the following sections:

  • Protocol: https

  • Host Name: www.example.com

  • Context Root: /ords

    The context root is the location at which Oracle REST Data Services is deployed on the application server.

  • Request Path: /sales/f?p=1.1

    This is the portion of the request URL relative to the context root.

For different applications, it may be important to route requests based on certain prefixes in the request path or certain prefixes in the full request URL.

There are two steps to configuring multiple databases:

  1. Configuring the database connection information

  2. Configuring which requests are routed to which database

2.1.2 Configuring Additional Databases

When you first configure Oracle REST Data Services, you configure a default database connection named: apex. You can create additional database connections using the setup command.

Tip:

To see full help for the setup command type:

java -jar ords.war help setup

To create a database connection type the following:

java -jar ords.war setup --database <database name>

Where:

  • <database name> is the name you want to give the database connection.

You are prompted to enter the information required to configure the database. After you have configured the additional databases, define the rules for how requests are routed to the appropriate database.

2.1.3 Routing Based on the Request Path Prefix

You create request routing rules using the map-url command.

Tip:

To see full help for the map-url command type:

java -jar ords.war help map-url

If you want to route requests based just on matching a prefix in the request path portion of the URL, use the map-url command as follows:

java -jar ords.war map-url --type base-path --workspace-id <workspace name> <path prefix> <database name>

Where:

  • <workspace name> is the name of the Oracle Application Express workspace where RESTful services for this connection are defined. This may be omitted if RESTful Services are not being used.

  • <path prefix> is the prefix that must occur at the start of the request path.

  • <database name> is the name of the database connection configured in the previous step.

2.1.3.1 Example of Routing Based on the Request Path Prefix

Assuming Oracle REST Data Services is deployed on a system named example.com at the context path /ords, then create the following rule:

java -jar ords.war map-url --type base-path --workspace-id sales_rest /sales sales_db

This rule means that any requests matching https://example.com/ords/sales/... are routed to the sales_db database connection. The sales_rest workspace defined within the sales_db database is searched for RESTful Services definitions.

The previous rule matches all of the following requests:

https://example.com/ords/sales/f?p=1:1
https://example.com/ords/sales/leads/
https://www.example.com/ords/sales/forecasting.report?month=jan  (If www.example.com resolves to the same system as example.com.)

The previous rule does not match of any of the following requests:

http://example.com/ords/sales/f?p=1:1  (The protocol is wrong.)
https://example.com:8080/ords/sales/f?p=1:1  (The port is wrong: 443 is default for https, but don't specify if using default.)
https://example.com/ords/f?p=1:1  (Missing the /sales prefix.)
https://example.com/pls/sales/leads/  (The context path is wrong.)

2.1.4 Routing Based on the Request URL Prefix

If you want to route requests based on a match of the request URL prefix, use the map-url command as follows:

java -jar ords.war map-url --type base-url --workspace-id <workspace name> <url prefix> <database name>

Where:

  • <workspace name> is the name of the Oracle Application Express workspace where RESTful services for this connection are defined. This may be omitted if RESTful Services are not being used.

  • <url prefix> is the prefix with which the request URL must start.

  • <database name> is the name of the database connection.

2.1.4.1 Example of Routing Based on the Request URL Prefix

Assuming Oracle REST Data Services is deployed on a system named example.com at the context path /ords, then create the following rule:

java -jar ords.war map-url --type base-url --workspace-id sales_rest https://example.com/ords/sales sales_db

This rule means that any requests matching https://example.com/ords/sales/... are routed to the sales_db database connection. The sales_rest workspace defined within the sales_db database is searched for RESTful Services definitions.

The previous rule matches all of the following requests:

https://example.com/ords/sales/f?p=1:1
https://example.com/ords/sales/leads/
https://example.com/ords/sales/forecasting.report?month=jan

The previous rule does not match of any of the following requests:

http://example.com/ords/sales/f?p=1:1  (The protocol is wrong.)
https://example.com:8080/ords/sales/f?p=1:1  (The port is wrong: 443 is default for https, but don't specify if using default.)
https://example.com/ords/f?p=1:1  (Missing the /sales segment of the base URL.)
https://example.com/pls/sales/leads/  (The context path is wrong.)
https://www.example.com/ords/sales/forecasting.report?month=jan  (The host name is wrong.)

2.2 Using the Multitenant Architecture with Oracle REST Data Services

This section outlines the installation choices and different scenarios associated with copying and moving pluggable databases introduced by the Oracle Database 12c multitenant architecture with respect to Oracle REST Data Services.

2.2.1 Understanding the Installation Choices

Oracle Database 12c Release 1 (12.1) introduces the multitenant architecture. This database architecture has a multitenant container database (CDB) that includes a root container, CDB$ROOT, a seed database, PDB$SEED, and multiple pluggable databases (PDBs). A PDB appears to users and applications as if it were a non-CDB. Each PDB is equivalent to a separate database instance in Oracle Database Release 11g.

The root container, CDB$ROOT, holds common objects that are accessible to every PDB utilizing metadata links or object links. The seed database, PDB$SEED, is used when creating a new PDB to seed the new pluggable database. The key benefit of the Oracle Database 12c multitenant architecture is that the database resources, such as CPU and memory, can be shared across all of the PDBs. This architecture also enables many databases to be treated as one for tasks such as upgrades or patches, and backups.

You can install Oracle REST Data Services into one or more pluggable databases PDBs in a multitenant database or into the container database (CDB). The installation choices are as follows:

  • If you want the same version of Oracle REST Data Services available in all the PDBs, then install it into the CDB. The rest of the instructions in this topic refer to installing into the CDB.

  • If you want only some PDBs to be able to use Oracle REST Data Services, or if you want different PDBs to use different versions of Oracle REST Data Services, then install into the desired PDBs. (Use the same procedure as for a non-CDB.)

When Oracle REST Data Services is installed into a CDB, it is installed in the root container, the seed container, and any existing PDBs. The root container (CDB$ROOT) includes the ORDS_METADATA schema to store the common database objects for Oracle REST Data Services packages, functions, procedures, and views. It also includes the Oracle REST Data Services public user (ORDS_PUBLIC_USER).

The seed container (PDB$SEED) includes the ORDS_METADATA schema and the Oracle REST Data Services public user. You can create a new PDB by copying PDB$SEED and creating metadata links back to the common database objects in the ORDS_METADATA schema within the CDB$ROOT. As a result, there are multiple copies of the Oracle REST Data Services tables and only single copies of the Oracle REST Data Services packages, functions, procedures, and views. Thus, each PDB has the ORDS_METADATA schema and its own copy of the Oracle REST Data Services tables, so that it can hold the metadata for the Oracle REST Data Services application within that PDB. Each PDB also has its own Oracle REST Data Services public user.

See also "Creating a PDB using the Seed" in Oracle Database Administrator's Guide.)

2.2.2 Installing Oracle REST Data Services into a CDB

If you want to have all PDBs in a multitenant environment to use the same Oracle REST Data Services release and patch set, install into the CDB. (This option will not allow you to have different releases of Oracle REST Data Services in different PDBs.)

Before installing into the a CDB:

  • Ensure that the PDBs are open (not mounted/closed) in read/write mode (except for PDB$SEED, which remains in read-only mode). See "Modifying the Open Mode of PDBs" in Oracle Database Administrator's Guide.

  • Ensure that the default and temporary tablespaces to be used by the ORDS_METADATA schema and the ORDS_PUBLIC_USER user exist and that you know the tablespace names. The installation procedure creates those users, but it does not create the tablespaces.

    Note that ORDS_METADATA and ORDS_PUBLIC_USER are also installed in the seed container, and that the default and temporary tables will have to exist in PDB$SEED. If these tablespace do not already exist there, then you will have to create the tablespaces in PDB$SEED; see "Running Oracle-Supplied SQL Scripts in a CDB" in Oracle Database Administrator's Guide.

To install Oracle REST Data Services into a CDB, follow these steps.

  1. Go to the folder into which you unzipped the Oracle REST Data Services installation kit.

  2. Enter the following command:

    java -jar ords.war install advanced
    

    Note:

    To use the pluggable mapping feature, see Making All PDBs Addressable by Oracle REST Data Services (Pluggable Mapping).

  3. When prompted, enter the database connection information for your CDB:

    Enter the name of the database server [localhost]:
    Enter the database listen port [1521]:
    Enter 1 to specify the database service name, or 2 to specify the database SID [1]:
    Enter the database service name: (for example, cdb.example.com)
    
  4. Verify the Oracle REST Data Services installation:

    Enter 1 if you want to verify/install Oracle REST Data Services schema or 2 to skip this step [1]:
    

    Accept or enter 1 (the default) to install Oracle REST Data Services into the CDB and all of its PDBs.

  5. Enter and confirm the ORDS_PUBLIC_USER password:

    Enter the database password for ORDS_PUBLIC_USER:
    Confirm password:
    
  6. When prompted, enter additional information as needed. (See Advanced Installation Using Command-Line Prompts.)

2.2.3 Upgrading Oracle REST Data Services in a CDB Environment

When you use a new release of Oracle REST Data Services, upgrading its schema in the CDB and its pluggable databases (PDBs) will occur automatically when you perform a simple or advanced installation.

For example:

java -jar ords.war

If Oracle REST Data Services is already installed or upgraded, a message displays the Oracle REST Data Services schema version, and you will not be prompted for information.

If an error occurred, view the log files.

2.2.4 Making All PDBs Addressable by Oracle REST Data Services (Pluggable Mapping)

Pluggable mapping refers to the ability to make all PDBs in a CDB addressable by Oracle REST Data Services. To use this feature, follow the instructions in this topic.

If the Oracle REST Data Services configuration file includes the db.serviceNameSuffix parameter, this indicates that the Oracle REST Data Services pool points to a CDB, and that the PDBs connected to that CDB should be made addressable by Oracle REST Data Services.

The value of the db.serviceNameSuffix parameter must match the value of the DB_DOMAIN database initialization parameter, and it must start with a period (.). To set the value of the db.serviceNameSuffix parameter:

  1. In SQL*Plus, connect to the root as a user with SYSDBA privileges.

  2. Check the value of the DB_DOMAIN database initialization parameter.

    SQL> show parameter DB_DOMAIN
    
  3. Exit SQL*Plus.

    SQL> exit
    
  4. If the DB_DOMAIN value was not empty, then on the command line enter the command to create the key and value for the db.serviceNameSuffix parameter and its DB_DOMAIN. This will be used to add this entry to the Oracle REST Data Services configuration file.

    echo db.serviceNameSuffix=.value-of-DB_DOMAIN > snsuffix.properties
    

    For example, if DB_DOMAIN is set to example.com, enter the following:

    echo db.serviceNameSuffix=.example.com > snsuffix.properties
    
  5. If the db.serviceNameSuffix parameter value is not defined, enter a command in the following format to add an entry to the configuration file:

    java -jar ords.war set-properties --conf pool-name snsuffix.properties
    

    Where pool-name is one of the following:

    • poolName for a PL/SQL Gateway configuration

    • poolName_pu for an Oracle REST Data Services RESTful Services configuration

    • poolName_rt for an Application Express RESTful Services configuration

    Example 1: You want to make PDBs in a CDB addressable globally. Specify defaults by entering the following command:

    java -jar ords.war set-properties --conf defaults snsuffix.properties
    

    Note:

    The approach shown in Example 1 (setting the property for all pools through the defaults.xml file) is best for most use cases.

    Example 2: You want to make PDBs in a CDB addressable for your PL/SQL Gateway, and your pool name is apex. Enter the following command:

    java -jar ords.war set-properties --conf apex snsuffix.properties
    

    For example, if the database pointed to by apex has a DB_DOMAIN value of example.com and contains the two PDBs pdb1.example.com and pdb2.example.com, the first PDB will be mapped to URLs whose path starts with /ords/pdb1/, and the second PDB will be mapped to URLs whose path starts with /ords/pdb2/.

    Example 3: You want to make PDBs in a CDB addressable for your Oracle REST Data Services RESTful Services, and your pool name is apex_pu. Enter the following command:

    java -jar ords.war set-properties --conf apex_pu snsuffix.properties
    

    Example 4: You want to make PDBs in a CDB addressable for your Application Express RESTful Services and your pool name is apex_rt. Enter the following command:

    java -jar ords.war set-properties --conf apex_rt snsuffix.properties
    

2.2.5 Uninstalling Oracle REST Data Services in a CDB Environment

To uninstall Oracle REST Data Services from a CDB, use the uninstall command.

For example:

java -jar ords.war uninstall

Oracle REST Data Services will be removed from the CDB and its pluggable databases (PDBs).

2.3 Support for Oracle RAC Fast Connection Failover

Oracle REST Data Services support the Fast Connection Failover (FCF) feature of Oracle Real Application Clusters (Oracle RAC).

Oracle REST Data Services runs with the Universal Connection Pool (UCP) in all the Application Server environments that it supports, such as WebLogic, Tomcat, GlassFish. UCP in turn supports Fast Connection Failover . To enable FCF, Oracle Notification Service (ONS) must to be enabled. To enable ONS, add entries to the list of properties in the Oracle REST Data Services defaults.xml configuration file as shown in the following code snippet:

<entry key="jdbc.enableONS">true</entry>
<entry key= "jdbc.ONSConfig">nodes=racnode1:4200,racnode2:4200\nwalletfile=/oracle11/onswalletfile</entry>
ONS is the messaging facility used to send the Fast Application Notification (FAN) events. When ONS is enabled, Oracle REST Data Services automatically enables FCF. To Enable specific FCF capabilities such as fail over or other advanced FCF capabilities such as load balancing, you need to add entries in the configuration file for the custom connection as shown in the following code snippet:
<entry key="db.connectionType">customurl</entry>
<entry key="db.customURL">jdbc:oracle:thin:@(DESCRIPTION=(FAILOVER=ON)(ADDRESS_LIST=
                (LOAD_BALANCE=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=prod_scan.example.com)(PORT=1521)))
                (CONNECT_DATA=(SERVICE_NAME=ISPRD)))|</entry>

After updating the defaults.xml configuration file, Oracle REST Data Services need to be restarted for the changes to take effect.

UCP supports Fast Connection Failover. FCF listens and responds to FAN events to deal with the following two scenarios:
  • Unplanned outages: When RAC detects an instance failure, it generates a FAN Down event which FCF picks up.  FCF then terminates all connections to the failed instance and directs all future requests to the surviving RAC instances.

  • Planned outages: For instance, when a Database Administrator (DBA) wants to gracefully shut down a RAC instance for performing some maintenance activity. The instance shutdown generates a FAN Planned Down event which FCF picks up. FCF then directs all new requests to other RAC instances and drains or allows currently active transactions to complete.

Note:

Long running transactions may need to be terminated forcefully.

2.4 Configuring Security, Caching, Pre- and Post Processing, Environment, and Excel Settings

To configure security, caching, pre- and post- processing, environment, and Excel settings, see Using SQL Developer Oracle REST Data Services Administration (Optional).

2.5 Configuring REST-Enabled SQL Service Settings

This section explains how to configure the REST- Enabled SQL service.

Note:

Enabling the REST- Enabled SQL service enables authentication against the Oracle REST Data Service enabled database schemas. This makes the database schemas accessible over HTTPS, using the database password. Oracle highly recommends that you provide strong secure database passwords
REST- Enabled SQL service is a feature of Oracle REST Data Service. By default, the REST Enabled SQL service is turned off. To enable the REST- Enabled SQL service and the REST- Enabled SQL Export service, perform the following steps:
  1. Locate the folder where the Oracle REST Data Services configuration file is stored.

  2. Open the defaults.xml file and add: <entry key="restEnabledSql.active">true</entry>.

  3. Save the file.

  4. Restart Oracle REST Data Services.

2.6 Configuring the Maximum Number of Rows Returned from a Query

To configure maximum number of rows returned from a query, perform the following steps:
  1. Locate the folder where the Oracle REST Data Services configuration file is stored.

  2. Open the defaults.xml file and update the value of the misc.pagination.maxRows parameter:<entry key=”misc.pagination.maxRows”>1500</entry>

    Note:

    The default value for misc.pagination.maxRows is 500.
  3. Save the file.

  4. Restart Oracle REST Data Services.

2.7 Configuring the Custom Error Pages

This section explains how to configure a custom error page instead of the error page generated by Oracle REST Data Services.

To configure a custom error page, perform the following steps:

  1. Locate the folder where the Oracle REST Data Services configuration file is stored.

  2. Open the defaults.xml file and update the value of the error.externalPath parameter:

    <entry key=”error.externalPath">/path/to/error/pages/folder/</entry>

    Where:

    • /path/to/error/pages/folder is the path to a folder containing files that define the error pages. The files are stored in {status}.html format.

      Where, {status} is the HTTP status code for which you want to create a custom error page.

  3. Save the file.

  4. Restart Oracle REST Data Services.

Example 2-1 Configuring custom error page for “HTTP 404” status code

To configure a custom error page for the “HTTP 404 – Not Found” status, perform the following steps:

  1. Create a file named 404.html.

  2. Save it under /usr/local/share/ords/error-pages/ folder.

  3. Configure the error.externalPath parameter to point to /usr/local/share/ords/errro-pages/ folder.

  4. Save the file.

  5. Restart Oracle REST Data Services.

2.8 Developing RESTful Services for Use with Oracle REST Data Services

For more information on how to develop RESTful Services for use with Oracle REST Data Services, see Developing Oracle REST Data Services Applications.