Subject: Configuring Oracle Servlet Engine (OSE) for HTTP access to Oracle8i Creation Date: 24-JAN-2001 PURPOSE ------- This note explains how to configure Oracle Servlet Engine (OSE) for HTTP access to Oracle8i. Introduction to Oracle Servlet Engine (OSE) -------------------------------------------- OSE works as a specialized Web server, designed as a scalable servlet server inside the Oracle8i database. The servlet classes are loaded into Oracle8i, and published in a JNDI namespace inside the database. A servlet runner handles HTTP requests, instantiates published servlets in sessions, and invokes servlet methods. Configuring Oracle Servlet Engine (OSE) --------------------------------------- To configure OSE we need to connect to Oracle8i session namespace using sess_sh tool. For more information on sess_sh check Oracle8i Java Tools Reference Release 3 (8.1.7) $sess_sh -user sys/pwd -service sess_iiop://myserver:2481:V817 1. Web Service -------------- OSE serves one or more Web Services, WebService is the entry point of your Web Applications, and we can think of it as virtual web server. The most important Web Service parameters are its port and its corresponding JNDI root directory. $ createwebservice -root /myWebServer myWebServer The above example creates a Web Service named myWebServer (you will retrieve this name in the /service JNDI directory) with the JNDI root of the service being in the /myWebServer directory. 2. Web Domain ---------------- Web Domain is the contents of its corresponding Web Service. A Web domain contains: configuration information stored in an object called config, servlet contexts, realms, logs. There are two types of WebService - Single Domain Service - Multi Domain Services The Web domain identification for HTTP requests depends on OSE configuration: Single Domain Service --------------------- The address part of the sent URL is actually ignored and the Web Domain is solely determined by the port that is used to connect to OSE. If that service is a Multi-Domain service, then the address part and server IP used to connect to the server are used to determine which domain to use. Multi Domain Service -------------------- This note do not explains Multi-domain service configuration. $ createwebdomain -docroot D:\Oracle\OraWeb /myWebServer The above example creates a Web Domain stored in the /myWebServer JNDI directory which should already exists as a Web Service root directory. Also, the default physical location of all static pages (-docroot option) will be /disk1/OSE/HTML. This example is based on a Single Domain Service configuration. 3. Web Service endpont ---------------------- A Web Service network entity is called an endpoint and can be associated with one or more HTTP listener or HTTP dispatcher. We need to add at least one endpoint to this service. We have following options to connect to Oracle8i OSE using HTTP endpoints: 1. Oracle Net Listener - HTTP service dynamically registert to listener - HTTP service statically configured it listener.ora 2. Oracle Dispatcher directly 3. Oracle HTTP Server (Apache) and mod_ose 3.1. Oracle Net Listener 3.1.1. Endpoint statically configured in Listener.ora $ addendpoint -port 7777 myWebServer Listener_static # MTS_DISPATCHER : # # 1. TCP dispatcher (generic) for OSE access over Listener # mts_dispatchers = "(ADDRESS=(PROTOCOL=TCP))(DISPATCHERS=1)" # # 2. TCP dispatcher (for myWebServer service only) OSE access over Listener # mts_dispatchers = "(ADDRESS=(PROTOCOL=TCP))(DISPATCHERS=1)(PRE=http://myWebServer)" # # LISTENER : # # Listener static configuration for myWebServer running in OSE # (ADDRESS = (PROTOCOL = TCP)(HOST = ukp15002)(PORT = 7777)) # (PROTOCOL_STACK = (PRESENTATION = http://myWebServer)) # # TNSNAMES : No setup 3.1.2. Endpoint dynamically registered to Listener $ addendpoint -port 8888 -register myWebServer Listener_dynamic # MTS_DISPATCHER : # # 1. TCP dispatcher (generic) for OSE access over Listener # mts_dispatchers = "(ADDRESS=(PROTOCOL=TCP))(DISPATCHERS=1)" # # 2. TCP dispatcher (for myWebServer service only) OSE aces over Listener # mts_dispatchers = "(ADDRESS=(PROTOCOL=TCP))(DISPATCHERS=1)(PRE=http://myWebServer)" # # LISTENER : No setup # # TNSNAMES : No setup 3.2. myWebServer endpoint using Dispatcher only $ addendpoint -port 9999 myWebServer Dispatcher # MTS_DISPATCHER : # # HTTP dispatcher for direct access to OSE (for myWebServer service only) # mts_dispatchers = "(ADDRESS=(PROTOCOL=TCP)(PORT=9999))(DISPATCHERS=1)(PRE=http://myWebServer)" # # LISTENER : No setup # # TNSNAMES : No setup 3.3. Endpoint for Apache mod_ose -------------------------------- mod_ose is a module in the Oracle HTTP server (Apache), which serves as a conduit from Apache to OSE. In conjunction with mod_ose, OSE is the servlet engine for Apache, where only static pages are served by Apache and the dynamic pages are served by OSE. $ addendpoint -net8 myWebServer mod_ose # MTS_DISPATCHER : # # TCP dispatcher for access over Apache mod_ose # mts_dispatchers = "(ADDRESS=(PROTOCOL=TCP))(DISPATCHERS=1)(SERVICE=MODOSE)" # # LISTENER : Generic TCP listener on any port (example 1521) # # TNSNAMES : # # (ADDRESS = (PROTOCOL = TCP)(HOST = uks715)(PORT = 1521))) # (CONNECT_DATA =(SERVICE_NAME = MODOSE)(SERVER = SHARED) (PRESENTATION = HTTP://myWebServer) After publishing servlets we need to export configuration as mod_ose config file. $ exportwebdomain -format apache -netservice ose -nodefault /myWebServer \ &>d:\oracle\ora817\apache\apache\conf\mywebserver.cfg 4. Servlet Contexts ------------------- Think of a servlet context as an application loaded into OSE. It is a set of servlets, configuration parameters, JSPs, and pointers to static contents on the file system that are all accessible below the same virtual path used in the URI part of the URL. The servlet context is usually identifiable as the first segment of a URI?s path. A servlet context configuration describes how the Web server behaves when serving its contents (security, timeouts, MIME types, mapping of virtual paths extensions to servlets, statefulness). OSE supports nested servlet contexts that can inherit configuration properties from their parents. $ createcontext -virtualpath /myWebApp -docroot D:\Oracle\OraWeb /myWebServer myWebApp The above example creates a new Servlet Context named myWebApp in the myWebServer Web Domain. Each servlet published inside this context will be accessible by using, as the first part of the URI, the /myWebApp virtual path. Also, by default, every static pages served by this context will reside in the host path D:\Oracle\OraWeb. 5. Servlet Publication ---------------------- Servlet classes and any support classes must be loaded into Oracle8i with loadjava or CREATE JAVA. Then, it is possible to publish them in a servlet context with the session shell command publishservlet. Publishing a Servlet creates a JNDI object in the named_servlets subdirectory of the servlet contexts. This JNDI object lists the servlet classname and its initialization parameters. Servlets are associated with an HTTP virtual path as described in their JNDI servlet context config object. We need to create the sample Sevlet first, Hello.java sample is below : import javax.servlet.*; import javax.servlet.http.*; public class Hello extends HttpServlet { int i =0 ; public void doPost ( HttpServletRequest req, HttpServletResponse res )throws ServletException, java.io.IOException { res.setContentType("text/html"); java.io.PrintWriter out = new java.io.PrintWriter(res.getOutputStream()); i++; out.println(""); out.println(""); out.println("This is the Servlet from Database Hit is "+ i); out.println(""); out.println(""); out.flush(); out.close(); } public void doGet( HttpServletRequest req, HttpServletResponse res )throws ServletException, java.io.IOException { doPost( req,res); } } Compile the java file using $ javac Hello.java Load the java class to the scott schema $ loadjava -r -f -v -u SCOTT/TIGER Hello.class The above example load the Java Class Hello.class (implementing the HttpServlet Java interface) into the database schema SCOTT. $ sess_sh -user sys/pwd -service sess_iiop://myserver:2481:V817 $ publishservlet -virtualpath /myHelloServlet /myWebServer/contexts/myWebApp myHelloServlet SCOTT:Hello Once done, under the session shell tool, the Servlet named myServlet is published into the JNDI directory /myWebServer/contexts/myWebApp/named_servlets and is associated with the HTTP virtual path /myHelloServlet. Change the ownership for the Service. $ chown -R SCOTT /scottRoot $ chmod -R +rwx SCOTT /scottRoot Note: Security of OSE is not covered in this note. 6. Testing the web application ------------------------------ # Listener (static) http://myserver.com:7777/myWebApp/myHelloServlet # Listener (dynamic) http://myserver.com:8888/myWebApp/myHelloServlet # Dispatcher http://myserver.com:9999/myWebApp/myHelloServlet # Apache Mod_OSE http://myserver.com:80/myWebApp/myHelloServlet .