This document describes the way Apache JServ works and it is intended to give detailed information on its mode of operation to quickly bring new developers up to speed. It may give nice information for power users looking for a deeper knowledge for better configuration and fine tuning.
AJ is composed by two sides: client side and server side. They are also referred to as C side and Java side when more precise definition may generate misunderstandings.
Client side is responsible of making requests to the server side and waiting for a response, while server side handles the client requests, executes the requested servlets and sends back the generated response.
Let us suppose that we have these web server configurations (and others that are not important in this context):
ApJServMount /servlets ajpv11://localhost:8007/root
ApJServMount /servlets/admin ajpv11://jserv.apache.org:9009/admin
ApJServAction .jhtml /org.apache.jserv.servlets.JServSSI
Now we analyze the behavior of different URLs requested to the web server:
This URL gets parsed by the web server and passed to mod_jserv, that opens a connection to localhost on port 8007 using AJP version 1.1 (that currently is the only one supported, but other versions of the protocol will be implemented in the future), authenticates the connection, requests the servlet HelloWorldServlet on servlet zone root and waits for a response. When the response arrives, it is encapsulated with the right http headers (based on web server information and response information) and sent to the http client.
This URL is passed to mod_jserv but the connection is now open on port 9009 of a host named jserv.apache.org, using AJP version 1.1 and following the above path.
This URL is exactly equivalent to the one above.
This URL follows the same path as the one above, but the servlet requested is now apache.HelloWorldServlet, since directories are dot-formatted by the module if not recognized as mount points.
This URL looks for a servlet with full name admin.HelloWorldServlet.class, so that the name of the source file should have been class.java. This is why .class extension should be removed from the servlet URL requested.
This URL is passed to the .jhtml handler that actually is a servlet. So it is passed again to mod_jserv that requests the servlet org.apache.jserv.servlets.JServSSI on the protocol://host:port/zone defined for that mount point. Note that this class is always found by the servlet engine class loader because it resides on the class path (or, at least, it should).
For deeper understandings of the request/response process, please, refer to the protocol specifications for more details.
When AJ is started (either automatically or manually), a .properties file (usually named jserv.properties) is passed to the org.apache.jserv.JServ class as a command line parameter. This file specifies the configuration parameters needed by AJ to start. They include the port, the servlet zones with their configuration files, and security parameters. Also, a fine grain tracing capability is included for both debugging and logging purposes.
After parsing these configurations, servlet zones are loaded constructing an org.apache.jserv.JServServletManager class for each servlet zone, and the server bounds to the configured port, listening for connections.
When a connection is requested to its port, AJ filters the incoming connection closing it if it does not come from an allowed IP address. This is used against denial of service attacks. If the address is allowed, the connection is authenticated (see authentication on AJPv1.1). If authentication is successful, a new org.apache.jserv.JServConnection is constructed to handle the request process and, since it extends Runnable, it is passed to a thread for multithreading serving behavior. This allows AJ to the able to handle many concurrent simultaneous requests.
The JServConnection class receives the request parameters, then calls the right JServServletManager (specified by the request servlet zone) and obtains the requested servlet. Then, it sets up the environment for execution and calls the servlet's service() method. JServConnection, together with JServContext and JServSession, provide all the hooks to the Servlet APIs methods needed by the servlet to execute. JServConnection also encapsulates servlet input and output streams.
When servlet service() method is over and all output data has been passed to the client, JServConnection closes the socket connection, indicating the termination of the request process. Returning from its run() method causes both the thread and the class itself to be garbage collectable.
Copyright (c) 1997-99 The Java Apache Project.
$Id: operation.html,v 1.10 1999/06/09 05:21:22 jonbolt Exp $
All rights reserved.