| United States-English |
|
|
|
![]() |
Communicator HP e3000 MPE/iX Express 2 Based on Release 6.5: HP e3000 MPE/iX Computer Systems > Chapter 3 Technical ArticlesJava Servlets for MPE/iX |
|
By Barbara Dubbert Java Servlets for MPE/iX is add-on functionality to the Apache Web Servers for MPE/iX. With this new functionality, Java servlets can be compiled and run on the MPE platform. Java servlets are server-side Java code for creating dynamic web pages and developing web applications. Servlets are similar to java applets except they run on a server instead of in a browser Java Servlets for MPE/iX runs with Apache 1.3.9 for MPE/iX and HP WebWise Secure Web Server for MPE/iX. Servlets provide a powerful alternative to traditional CGI. Servlets can be used wherever CGI might normally be used yet they allow for session persistence and have faster startup times than traditional CGI . Servlets also have all the advantages of the Java language such as ease of development, platform independence, and a large set of available APIs. Like CGI, servlets extend the functionality of a web server. For example, a servlet could be written to do any of the following:
But servlets have several advantages over CGI:
Java Servlets for MPE/iX is currently available as an individual patch from the HP Response Center. It is not part of the Express 2 release. Java Servlets can be installed on either MPE/iX Release 6.0 or 6.5 and run with either Apache 1.3.9 or WebWise Secure Web Server for MPE/iX. The HPRC can provide you with the correct patch version for your release and web server. WebWise Secure Web Server is available for ordering. For information on obtaining WebWise, please visit the WebWise site on Jazz at http://jazz.external.hp.com/src/webwise/. Apache 1.3.9 for MPE/iX is currently available as an individual patch from the HP Response Center. Please refer to the Apache 1.3.9 article in this Communicator for release and installation information about Apache 1.3.9. Java Servlets do not work with Apache 1.3.4 since this version lacks the necessary DSO capability. Java Servlets running on MPE/iX require the following software and patches:
Any additional requirements for Apache 1.3.9 or WebWise Secure Web Server should be met before installing and running Java Servlets. The following are estimates of disk space needs:
The Java Servlets product on MPE/iX consists of an add-on module to Apache, called "mod_jserv," and a standalone Java application, referred to as the "servlet engine" or JServ. Mod_jserv is implemented as a Dynamic Shared Object (DSO) and the servlet engine runs on top of the MPE's Java Virtual Machine (JVM). Mod_jserv module and the servlet engine are open source software from the Java Apache Project, Apache JServ 1.1 The MPE implementation of Java servlets is referred to as a three-tiered model because it consists of three components. Some implementations of Java servlets are two-tiered with the servlet engine being part of the web server. The three tiers on MPE/iX are:
Apache's mod_jserv and the servlet engine communicate through a special protocol, Apache JServ Protocol (AJP), which runs on top of TCP. The TCP connection is usually through the localhost, 127.0.0.1, but can also be via a remote host. For a remote host, the Apache Web Server and the servlet engine are on separate machines. A servlet is a body of server-side Java code that is loaded into and runs inside the servlet engine. It receives and responds to requests from clients in a manner similar to CGI. When making a request, the web browser acts as a client and sends its request to Apache using the HTTP protocol. Apache's mod_jserv translates this HTTP request into AJP and acts as the AJP client by sending the request over the network (local or remote) to the servlet engine. The servlet engine acts as the AJP server and listens on a specific port (8007 by default) for incoming requests. The servlet engine will process a request by executing the requested servlet. When the servlet has completed processing its request, the servlet engine responds back to Apache using AJP. Apache converts the AJP response to HTTP and sends it back to the client browser. Java Servlets for MPE/iX installs and runs under directory /APACHE/PUB for Apache or directory /APACHE/SECURE for WebWise Secure Web Server. Under one of these directories will be the following files and subdirectories: JSRV - The Apache job stream file for starting the JServ engine. It contains the necessary variables for running the engine as a standalone process. JSRVS is the job file for WebWise. JSRVOFF - The Apache job stream file for stopping the JServ engine. JSRVSOFF is the job file for WebWise. libexec - The subdirectory containing mod_jserv.so, the JServ class files (ApacheJServ.jar), and an example file and documentation for creating your own DSOs. servlets - This subdirectory is the pre-configured repository for servlet files. It contains two simple servlet source files and their corresponding class files. These files are used for testing the installation. conf/jserv - A subdirectory containing three new configuration files: jserv.conf, jserv.properties, and root.properties. htdocs/jservdocs - This subdirectory is the root for the Apache JServ documentation including the API specification in javadoc format, a feature list, FAQs, and several in-depth articles on functionality. htdocs/JSDK2.0/doc/apidoc/ - This subdirectory contains the JSDK2.0 API specification in javadoc format. lib/jsdk.jar - Class files in jar format of the Java Servlet Development Kit 2.0 (JSDK2.0). logs/mod_jserv.log - The log file created and used by the Apache module, mod_jserv.so. logs/jserv.log - The log file created and used by the servlet engine, JServ. Mod_jserv is the add-on module to Apache that communicates with the servlet engine, JServ. It converts browser HTTP requests to servlet AJP requests then converts servlet AJP responses to HTTP responses and returns them to the client browser. Mod_jserv has a ".so" suffix because it is a Dynamic Shared Object (DSO), an NMXL on MPE. Mod_jserv is written in C and has the same structure as other Apache compiled-in modules. Because it is a DSO, it is loaded and run at Apache startup or restart. This is the "servlet engine," a 100% pure java application that executes servlets. This servlet engine executes like a regular Java application with a static main method in class org.apache.jserv.JServ. This version of the servlet engine, Apache JServ 1.1, executes servlets that are compliant with JavaSoft's Java Servlet APIs, version 2.0. The servlet engine forwards AJP client request data to the requested servlet and then forwards the servlet response back to the AJP client. This version of Java Servlets for MPE/iX uses the class definitions from Sun's Java Servlet Development Kit 2.0 (JSDK2.0). JSDK2.0 is a Sun product that can be downloaded for free from Sun's web site. For your convenience, the JSDK2.0 class definitions are installed as part of Java Servlets for MPE/iX in their complete and unmodified form. These servlet classes come packaged by Sun in a Java archive file, jsdk.jar. Any version of the servlet classes other than JSDK 2.0 (past, present, or future version) may not work with this release of Java Servlets for MPE/iX and should not be used. The jsdk.jar class library file is installed in /APACHE/PUB/lib for standard Apache and in /APACHE/SECURE/lib for WebWise. All servlets use the class definitions in jsdk.jar. Because the servlet engine is itself a servlet, the jsdk.jar file is also required for the servlet engine to run. The JSDK2.0 API documentation is also distributed in its complete and unmodified form with your installation at http://yourhost.com/JSDK2.0/doc/apidoc. This includes:
Additional components of the JSDK2.0 are available by downloading the entire package from Sun's site at http://java.sun.com/products/servlet. The JSDK2.0 is not an HP product and is not supported by HP. This is the first of three new configuration files. This configuration file contains directives for Apache only and is not read by the servlet engine. It contains directives which, for example, indicate whether mod_jserv.so should be loaded and whether the servlet engine will be run automatically or be manually started. Automatic launching of the servlet engine is not supported on MPE/iX. The ApJServManual directive should always be set to true: ApJServManual on The grammar for this file follows the grammar used by other Apache configuartion files: DirectiveName value This file is read once at Apache startup or restart. This is the second of three new configuration files. This file contains all the properties required by the servlet engine. Some properties are passed to the Java Virtual Machine (JVM) and others include various security preferences, settings for internal communication between the servlet engine and the Apache web server, properties for enabling logging, and a list of all servlet zones and their respective property files. The grammar for this file follows a grammar similar to Java property files: property_name=value, value, ... This file is read by both mod_jserv and by the servlet engine. It is loaded once at startup, so changes are available only after restart of the web server and of the JVM. This is the third of three new configuration files. Each servlet zone requires its own properties file. The installation and configuration processes set up one servlet zone called "root" and its corresponding properties file called "root.properties". A properties file contains a list of servlet repositories for a specific zone. This is the location of the servlet class files for that zone. Any other settings that are specific to a zone must also be in the properties file. It also contains aliases and initialization arguments for the servlets in that zone. Properties files use the same grammar as the jserv.properties file and are usually named using the zonename.properties syntax. This file is read once by the servlet engine at startup. Servlet Repository - A servlet repository is a collection of servlets and may be either a directory or archive, such as a zip or jar file. Servlet Zone - The servlet engine partitions its execution space into secured, separated zones. A servlet zone represents a collection of servlets that represent the same security restrictions. They are similar to a web server's virtual host. Local Mode - This is when the web server and the servlet engine reside on the same machine. This is the fastest and most common mode of operation because the client (web server) communicates with the servlet engine over a local loopback interface (127.0.0.1) instead of over the network. Remote Mode - This is when the web server and the servlet engine reside on different machines. This mode might be desirable when load balancing. Java Servlets is installed by following the patch installation instructions. Successful installation depends on properly installing and configuring the Apache Web Server, the Apache JServ module (mod_jserv), the Jserv servlet engine and the JVM. To ensure success, the following should be verified before beginning installation of Java Servlets:
You can check your version of the JVM by invoking the command, :java -version A simple program like HelloWorld can be used to verify if Java is set up correctly. The program below should be created in HelloWorld.java: public class HelloWorld
To compile HelloWorld.java, shell/iX>javac HelloWorld.java To run HelloWorld, shell/iX>java HelloWorld For information on installing and running Java, WebWise, or Apache on MPE/iX, please refer to the Additional Resources section at the end of this document. Java Servlets are configured in a few, easy steps.
The servlet installation job creates 3 sample configuration files in the directory conf/jserv. These sample files are derived from their corresponding default files for use on MPE. Copy these sample files to create your own configuration files. Make sure to log on first as MGR.APACHE:
or
Modify your conf/httpd.conf file by adding an include directive after the last AddModule directive in the module list. The included file, jserv.conf, contains a LoadModule directive for loading the mod_jserv.so library. For WebWise Secure Web Server, the include should be added after mod_ssl.c as shown here:
For Standard Apache, the include should be added after mod_setenvif.c as shown here:
The conf/jserv/jserv.conf file contains configuration directives for viewing servlet status once the servlet engine has started. To enable, replace "your.PC.com" with the IP address of your PC's browser (127.0.0.1 is equivalent to "localhost"). This feature should be enabled for trusted users only (i.e. the system administrator) and probably disabled on production systems. To disable this feature, remove your PC's address from the "allow from" directive.
The servlet engine, JServ, is started by streaming JSRV (for standard Apache) or JSRVS (for WebWise Secure Web Server). The servlet engine is stopped by streaming JSRVOFF (for standard Apache) or JSRVSOFF (for WebWise Secure Web Server). Change the TZ variable for your local timezone in JSRV and JSRVOFF or in JSRVS and JSRVSOFF,
JServ should never be terminated using the POSIX shell's kill command. Terminating it with kill prevents it from cleanly destroying all servlets. To start WebWise Secure Web Server and the servlet engine,
To start standard Apache and the servlet engine,
Starting the servlet engine also starts up the Java Virtual Machine (JVM) since the servlet engine itself is a servlet. Because the JVM is starting up, there will a short delay before the engine is running. Successful installation and startup of the servlet engine can be verified by
For the first startup after installation, it is best to start Apache or WebWise Secure Web Server then check the conf/error_log and conf/mod_jserv.log files. This will verify that the web server has started successfully and was able to load the mod_jserv module. Mod_jserv.log is created at Apache startup, if it doesn't already exist. Next, start the servlet engine. Jserv.log is created when the servlet engine is started.
Once the servlet engine is running, you can view servlet status by calling the servlet status handler (the trailing slash is required),
To run the example servlets,
To access the Jserv documentation,
To stop WebWise Secure Web Server and the servlet engine,
To stop standard Apache,
Mod_jserv.log records messages and errors encountered by Apache's mod_jserv module. This includes messages about communicating via AJP to JServ, the servlet engine. When this log file is disabled, its messages are redirected to Apache's error_log. The number of messages logged to this file can be adjusted by setting the log level. Directives for disabling or changing the log file (ApJServLogFile) and for setting the logging level (ApJServLogLevel) are found in conf/jserv.conf file. Mod_jserv.log is created at Apache startup time, if it doesn't already exist, similar to Apache's other configuration files. Jserv.log records messages and errors encountered by the servlet engine. Directives to control this log file are found in the jserv.properties file. Jserv.log can be configured to also log servlet exceptions and various internal debugging information. Due to the large number of objects created and managed for logging, logging to jserv.log can cause performance degradation. This effect of logging should be considered when deciding if or how much to log. Java servlets on MPE follow the same rules and conventions as Java programs on MPE. Any HP e3000 editor can be used to create a servlet file but, like Java programs, Java servlets must be in bytestream format. Servlets created with vi or using Samba from a PC will always be in bytestream format. Servlet files created using traditional HP e3000 editors such as EDIT/3000 and HP EDIT must be converted to bytestream using the tobyte utility. For information on tobyte, execute "man tobyte" in the POSIX shell to invoke the POSIX help facility. The naming conventions for Java servlets follow those of Java programs:
The jsdk.jar servlet classes in the JSDK2.0 are required for proper servlet execution whether you write your own servlets or get them from another source. The jsdk.jar file contains the javax.servlet and javax.servlet.http packages. To view the list of classes in the jsdk.jar file, use the Java Archive Utility:
or
For servlet API documentation and examples, use the following URL on your own server:
Servlets can be written to call any of the Java APIs available to Java applications. Servlets use the Java standard extension classes in the packages javax.servlet (the basic Servlet framework) and javax.servlet.http (extensions of the servlet framework for servlets that answer HTTP requests) that are in the jsdk.jar file. Since servlets are written in Java and follow a standard framework, they are portable between operating systems. Here is an example of a simple servlet.
The above is an example of an HTTP servlet since it extends the HttpServlet class. For HTTP servlets, an HTTP method (i.e., GET) is generally handled by a corresponding Java method (i.e. doGet). The method should return a response which contains a body and header field(s) which describe the body. In this example, the doGet method in the HttpServlet base class is overridden. The body is the HTML output and the header field is the Content-Type "text/html." This is an example of a static servlet that returns the same output every time it is called. The class path is where the JVM looks for class definitions. The jsdk.jar file, which contains servlet class definitons, should be specified to the JVM by adding its path to the CLASSPATH environment variable. CLASSPATH can be set at the command line or in a profile file:
or
Servlets are compiled using the Java compiler, javac. The path to the javac binary can be fully qualified or the PATH variable can be modified to include it. PATH can be set at the command line or in a profile file.
or
If you are planning to compile multiple servlets, you may want to set the PATH and CLASSPATH variables in the .profile file for MGR.APACHE or in the system-wide /etc/profile.local file. To create a new .profile file with these variables for MGR.APACHE:
The sample configuration files are set up to execute servlets from the /APACHE/PUB/servlets directory for standard Apache and from /APACHE/SECURE/servlets for WebWise. This is where your servlet .class files must reside. This directory is a servlet repository in the " root" zone and is configured in the root.properties file:
To run the servlet HelloWorld from the servlets repository, enter its URL in your web browser:
or
"HelloWorld" is the name of the servlet to run and "servlets" and "servlet" are the mount points for the "root" zone. Zone mount points are specified in the jserv.conf file using the ApJServMount directive. Here are the ApJServMount values set in the jserv.conf.sample file:
Mounting maps a URL to a zone. With the above mounts , requests to a URL starting with /servlets or /servlet will be handled by the servlets in the zone "root." Servlets can be passed input in a manner similar to CGI. To run the servlet "MyServlet" with an address input value, the URL would be,
The following are additional resources for Java servlets, Java, WebWise Secure Web Server, and Apache. Release documents for Java, WebWise, and Apache are on HP's online documentation site, http://docs.hp.com/mpeix. Java servlets resources:
Apache Web Server for MPE/iX resources:
WebWise Secure Web Server for MPE/iX resources:
Java for MPE/iX resources:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||