14 Extending ORDS Functionality with Plugins
This chapter explains and provides examples on using ORDS plugin framework.
ORDS has a plugin framework that allows you to add your own custom functionality
into the ORDS web application. Plugins can be added to the ORDS runtime by placing the
jar files in the lib/ext
directory. The ORDS distribution contains the
source for example plugins. The plugin examples can be built using Apache
ant
, a software tool used for automating the build processes.
- Plugin Demonstration Example
This section shows how you can locate and build a plugin demonstration example.. - Embedding Graal JavaScript Component
- Plugin Javascript
14.1 Plugin Demonstration Example
This section shows how you can locate and build a plugin demonstration example..
The plugin-demonstraion example is at examples/plugins/plugin-demo
location and contains the source for a HttpServlet
that
gets a database connection injected at runtime. The servlet uses that JDBC
database connection to run a query in the database and return a response at
runtime.
- Change the directory to
examples/plugins/plugin-demo
- Run
ant
to build theexamples/plugins/plugin-demo/built/plugin-demo.jar
file - Copy the
plugin-demo.jar
to the ORDS distributionlib/ext
directory and start an ORDS instance. - Invoke the servlet using the following URL pattern:
http://server/ords/schema/demos/plugin?who=somebody
- For example:
http://localhost:8080/ords/hr/demos/plugin?who=scott
where ORDS is configured with a default pool andHR
is an alias for a REST Enabled Schema in that database.
- For example:
Parent topic: Extending ORDS Functionality with Plugins
14.2 Embedding Graal JavaScript Component
The JavaScript component must be embedded as a plugin to be able to run JavaScript as a guest language in ORDS that is running in GraalVM for JDK version 21.
- GraalVM Polyglot API
- JavaScript language
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>polyglot</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<!-- Language: js -->
<artifactId>js</artifactId>
<version>${graalvm.version}</version>
<type>pom</type>
</dependency>
Refer to section, Embedding Languages in the GraalVM reference manual for more
information about dependency setup to embed languages. Once the required artifacts have
be dowloaded, place them in lib/ext/
directory to be included in the
classpath at runtime.
See Also:
Embedding LanguagesParent topic: Extending ORDS Functionality with Plugins
14.3 Plugin Javascript
ORDS provides a JavaScript as a service framework for customers to define
a JavaScript that can be executed in the ORDS instance on request. This is similar
to the conventional RESTful services concept used to develop the applications. The
framework is based on the module, template, and handler architecture. See Developing Oracle REST Data Services Applications. Rather than defining the modules, templates, and handlers in the
database, they are specified in an XML representation that is read from
lib/ext/
directory as a plugin.
plugin-javascript
example and the source can be found in the
examples/plugins/plugin-javascript
directory. This section
describes the key elements of the plugin.
Note:
GraalVM with JS component is required for JavaScript plugin ORDS feature to work.The example contains a number of inline and external definitions for JavaScript source. References to external JavaScript source are to the files that are found in the classpath.
File | Description |
---|---|
build.xml |
The ant build project.
|
src/js/example.js |
An example external JavaScript file. External here means, not defined in, but referred to from, the XML Resource Module file. |
src/META-INF/manifest.json |
A plugin configuration metadata file that ORDS reads at startup to register XML Resource Modules. |
src/META-ING/modules/javascript.xml |
An XML Resource Module file that defines an example module with a number of templates and handlers. |
- Change the directory to
examples/plugins/plugin-javascript
. - Run
ant
to buildexamples/plugins/plugin-javascript/built/plugin-javascript.jar
file. - Copy the
plugin-javascript.jar
file to the ORDS distributionlib/ext
directory and start the ORDS instance using a supported GraalVM with JS component. - Invoke the defined handlers using the URL pattern:
http://server/ords/javascript-examples/{template pattern}
.- For example:
http://localhost:8080/ords/javascript-examples/now
where the current time is returned.Note:
Unlike the ORDS REST Services, the JavaScript as a service implementation does not require or use a database connection.
- For example:
- Example Services Purpose and Use
This section provides the information on the purpose and use of the example services.
Parent topic: Extending ORDS Functionality with Plugins
14.3.1 Example Services Purpose and Use
This section provides the information on the purpose and use of the example services.
Purpose | Request | Action | Response |
---|---|---|---|
An example of inline Javascript that returns the current UTC time
as application/json .
|
/ords/javascript-examples/now |
GET |
{ "now":"2023-08-31T16:08:55.471Z" } |
An example of inline Javascript that accepts a parameter. | /ords/javascript-examples/future?days=7 |
GET |
{ "now":"2023-08-31T16:08:55.471Z",
"future":"2023-09-07T16:08:55.471Z", "days":7 } |
An example of inline Javascript that accepts various parameters from different sources. |
|
GET |
|
An example of external Javascript file that accepts a parameter. | /ords/javascript-examples/fibonacci?length=50 |
GET | {fib: 12586269025} |
An example of inline Javascript that uses implicit parameters
content_type and body_text for
getting the request values as well as using
ords_response to invoke
setStatus and setContentType
on HttpServletResponse .
|
|
POST |
|
Parent topic: Plugin Javascript