Introduction
For internet applications with dynamic contents, more and more J2EE components
(Servlets, JSP’s, EJB) come into operation.
With servlet based applications, the servlets are stored in the filesystem and
accessed and executed by a web server with its servlet engine e.g. Apache / Jserv.
For database access, methods like JDBC or SQLJ are used.
Oracle8i /9i brings some extensions in the area of server side Java programming. In
this article we consider a configuration of a Web application where:
References
Components
All required components (Oracle HTTP Server , JRE, JDK, JSDK) are available with the
Oracle 9i installations CD-ROM.
Terms
See [1]
OSE is a built-in Web server with an integrated servlet engine running inside Oracle
9i. OSE executes Java Server Pages, Servlets and Java Stored Procedures.
See [3] [4]
JNDI defines a hierarchical directory model for the administration of Web application
objects (Servlets, initial parameters, JSP's etc.).
Access to the JNDI structure and its objects is permitted by a session shell tool
called "sess_sh". The tool is driven by a command language similar to Unix. JNDI
supports three type of access rights: READ, WRITE and EXECUTE.
Fig 1 Example: JNDI structure for a single domain Web service
Example (command within the session shell tool):
$ createwebservice -root /SougDemoRoot SougDemo
/SougDemoRoot: Name of the rootdirectory
SougDemo: Name of the Web service
In a single-domain Web service the Web domain corresponds to the root
directory of the Web service.
The hierarchical model represents a presentation layer and complies to the JNDI
standard. In effect, directories and objects are stored in database tables.
Example:
$ addendpoint -port 7778 -register SougDemo SougEndpt01
SougDemo: Name of the Web service
SougEndpt01: Name of the Endpoint
Access to OSE Servlets
Oracle8i OSE provides two different access methods:
Fig2 Direct client access
The HTTP-Client sends an URL in the form:
http://<host>:<port>/<webservice>/<servlet>
to the listener port (endpoint). The listener forwards the request to the OSE, which
reads the associated servlet context from the JNDI and executes the servlet.
An URL with a the pattern:
http://<host>:<port>/<webservice>/<html_page>
causes the OSE to read the HTML-page from the predefined OS-Directory.
Each HTTP-Client request initiates the OSE to start a new DB session. The session
runs in the context of the Web service owner. A DB session activates its own Java
Virtual Machine (JVM). The JVM runs in the same address space as the SQL- and
PLSQL-engine and provides therefore a faster access to database objects without
additional login.
DB-Session termination is controlled by the use of a timeout parameter.
Fig3 Indirect access to the OSE over the Oracle HTTP Server
In this configuration the OSE serves as an additional servlet engine for the Oracle
HTTP server. Servlets without database access are stored in the repository or in a
servlet zone of the Apache Web server respectively (see [5]). Servlets with
database access are loaded into the database. This architecture allows a flexible
scalability for Web applications.
The Oracle HTTP-Server analyses a client-URL:
-
If it contains a static page from the path indicated by the DOC_ROOT
directive, this page is sent back to the caller
-
If it contains a servlet zone, the request is forwarded to the MOD_JSERV
module.
-
If it contains a servlet context of an OSE-handler, the first part "http://<host>:<port>" of the URL is
removed and the remaining part is transferred to MOD_OSE, which then connects
to the OSE.
Remark:
A servlet context "SougDemo" is defined with the following directive: (See
Configurationfile: mod_ose.conf)
<Location /SougDemo/* >
SetHandler aurora-server
</Location>
Servlets loaded and published in a JNDI servlet context can be configured to run
either in stateful or in a stateless context. A stateful application tracks status
information for all request-response sequences of a HTTP-client session. Cookies or
URL-rewrites are the mechanism in charge. For details see [1].
Summary
Using the OSE for 3-tier applications offers additional scalability. Depending of its
task, Java servlets can run either in the middle-tier or in the database server.
The administration of a Web service within the JNDI namespace is rather annoying!
Example Configuration
You will find running examples for the different access methods and step by step
instructions for the configuration of the Oracle Servlet Engine, the Oracle HTTP
Server (Apache/Jserv) and the particular examples.
Configuration Steps
Summary of Examples
|
|
|
|
1
|
Direct access from a HTTP client to the OSE, calling a static HTML page
(example_1.html) in the OS filesystem.
|
|
2
|
Direct access from a HTTP client to a servlet in the OSE. The servlet reads the
EMP table using the internal KPRB JDBC driver..
|
|
3
|
Calling a servlet in the servlet zone of the Oracle HTTP server (Apache).
|
|
4
|
Calling a servlet in the OSE over the Oracle HTTP server. The servlet reads the
EMP table using the internal KPRB JDBC driver.
|
Platform
These examples have been installed and configured on the following platform:
We also installed, configured and successfully tested the whole application
on a Win 2K PC.
Requirements
# This are the normal parameters
# parallel_automatic_tuning = false
# shared_pool_size = 20000000
# This are the necessary parameters to setup
# the JAVA development
parallel_automatic_tuning = false
shared_pool_size = 200000000
java_pool_size = 100000000
Installscripts:
ORACLE_HOME\javavm\install\initjvm.sql
ORACLE_HOME/Apache
When you install the Oracle HTTP Server, you will be asked for the location of the
JDK. This is usually not within the ORACLE_HOME path. We install the JDK in
/usr/local/jdk. We noticed, that only JDK Version 1.3 works well.
4096 Jun 27 2001 j2sdk-1.3.1-FCS-linux-i386/
26 Mar 8 22:25 java -> j2sdk-1.3.1-FCS-linux-i386/
26 Mar 8 22:20 jdk -> j2sdk-1.3.1-FCS-linux-i386/
7 Mar 7 13:59 jsdk -> JSDK2.0/
4096 Apr 21 1998 JSDK2.0/
Installation
ORACLE_HOME\javavm\install\init_jis.sql
mts_dispatchers="(PROTOCOL=tcp)"
DB-Restart (if changes occoured)
GRANT JAVAUSERPRIV TO SCOTT;
Additional information for the Java enviroment is provided under:
$ORACLE_HOME/javavm/readme.txt
Examples
Configuration steps for all examples, please take note of:
$ Unixprompt
sess> Prompt sess_sh tool
SQL> SQL*PLUS Prompt
\ Line continuous character, not part of the command,
copy all continuous lines in one single line.
$ sess_sh -u sys/manager -role SYSDBA -s jdbc:oracle:oci8:@
--Session Shell--
--type "help" at the command line for help message
sess> createwebservice -root /SougDemoRoot SougDemo
sess> chown -R SCOTT /SougDemoRoot
sess> chmod -R +rwx SCOTT /SougDemoRoot
Direct access from a HTTP client to the OSE, calling a static HTML page in the OS
filesystem.
$ mkdir <DIR>/SougDemo/StaticPages/
$ sess_sh -u sys/manager -role SYSDBA -s jdbc:oracle:oci8:@
sess> createwebdomain -docroot <DIR>/SougDemo/StaticPages
/SougDemoRoot
sess> createcontext -virtualpath /SougDemo
-docroot <DIR>/SougDemo/StaticPages \
/SougDemoRoot SougDemoContext
sess> addendpoint -port 7778 -register SougDemo
SougEndpt01
sess> chmod -R +rwx SCOTT /SougDemoRoot
sess> exit
SQL> exec dbms_java.grant_permission (\
'SCOTT','SYS:java.io.FilePermission',\
'<DIR>/SougDemo/StaticPages/\
example_1.html','read'
);
commit;
http//:<your_host>:7778/SougDemo/example_1.html
Direct access from a HTTP client to a servlet in the OSE. The servlet reads the EMP
table using the internal KPRB JDBC driver.
$ javac ReadEmployees.java
$ loadjava -verbose -u SCOTT/tiger ReadEmployees.class
arguments: '-verbose' '-u' 'SCOTT/tiger'
'ReadEmployees.class'
created :JAVA$CLASS$MD5$TABLE
creating : class ReadEmployees
created :CREATE$JAVA$LOB$TABLE
loading : class ReadEmployees
$ sess_sh -u sys/manager -role SYSDBA -s jdbc:oracle:oci8:@
sess> publishservlet -virtualpath \
/Emp \
/SougDemoRoot/contexts/SougDemoContext \
ReadEmployees SCOTT:ReadEmployees
sess> chmod -R +rwx SCOTT /SougDemoRoot
sess> exit
http//:<your_host>:7778/SougDemo/Emp
Calling a servlet in the servlet zone of the Oracle HTTP server.
$ORACLE_HOME/Apache/Apache/conf/httpd.conf
# Include JServ Module
include "/usr/oracle/product/9.0.1/Apache/Jserv/etc/jserv.conf"
# This port is used when starting without SSL
Port 7777
$ORACLE_HOME/Apache/Jserv/etc/jserv.conf
ApJServMount /SougdemoJserv /SougdemoJserv
$ORACLE_HOME/Apache/Jserv/etc/jserv.properties
# Servlet Zones parameters
zones=SougdemoJserv
...
SougdemoJserv.properties=<your_path> \
/Jserv/sougdemojserv.properties
$ORACLE_HOME/Apache/Jserv/etc/zone.propertes
as a template file and save it as:
<your_path>/Jserv/sougdemojserv.properties
# List of Repositories
repositories==<your_path>/Jserv
Create and compile a Java servlet e.g.
$ javac HelloAkadia.java
and save it as
<your_path>/Jserv/
$ORACLE_HOME/Apache/Apache/bin/
$ ./apachectl [start,stop,restart,...]
Test example 3 with the URL
http//:<your_host>:7777/SougdemoJserv/HelloAkadia
Calling a servlet in the OSE over the Oracle HTTP Server (Apache). The servlet reads
the EMP table using the internal KPRB JDBC driver.
For this example the same servlet is used as for example 2.
Apache configurationfiles (Check and change if necessary)
...
Port 7777
...
# Include the Oracle configuration file for custom settings
include "/opt/oracle/product/9.0.1/Apache/Apache/conf/oracle_apache.conf"
...
include "/opt/oracle/product/9.0.1/Apache/modose/conf/ose.conf"
...
LoadModule ose_module libexec/libjipa8i.so
#
# Apache configuration
# Domain: /webdomains
#
# o/p generated by
# exportwebdomain -format apache -netservice
# AuroraSrv1 -nodocs -nodefault /webdomains
#
<IfModule mod_ose.c>
AuroraService AuroraSrv1
#
# Context for VPATH /SougDemo/
#
<Location /SougDemo/>
AddHandler aurora-server snoop
</Location>
# SougDemo
# * ==> all Servlets under /SougDemo
<Location /SougDemo/*>
SetHandler aurora-server
</Location>
</IfModule>
$ORACLE_HOME/Apache/Apache/bin/
$ ./apachectl [start,stop,restart,...]
Add the following entry to tnsnames.ora:
AuroraSrv1.world
(DESCRIPTION = (ADDRESS = (COMMUNITY = tcp.world)
(PROTOCOL = TCP) (Host = <your_host>) (Port = 1521))
(CONNECT_DATA = (SID = <your_SID>)
(GLOBAL_NAME = <your_SID>.world)
(PRESENTATION = http://SougDemo)
(SERVER = SHARED)))
$ lsnrctl
$ reload <your_listener>
$ exit
Invoke the session shell tool
$ sess_sh -u sys/manager -role SYSDBA -s jdbc:oracle:oci8:@
sess> addendpoint -net8 -register SougDemo SougNet8Endpt01
http//:<your_host>:7777/SougDemo/Emp
Notice that instead of port 7778 (direct access to the OSE ) port 7777 (access to the
Oracle HTTP server) is used.
Troubleshooting
If you cannot connect to the example, then try the following
-
Shutdown the Database
-
Shutdown Listener
-
Shutdown Apache
-
Startup the Database
-
Startup Listener
-
Startup Apache
|