For the fourth and fifth connection strategies to work, there has to be a way, hooked into a web server, to forward method invocations to the actual RMI server. The first implementation of this that Sun Microsystems, Inc. shipped was a compiled CGI script. Formally, it required the following:
Each remote method invocation was sent as a HTTP POST request.
The full URL being used was of the form /cgi-bin/java-rmi.cgi?forward=[port number].
The body of the POST contained all the data from the remote request as serialized objects that were then converted into an ASCII stream of characters.
After the servlet specification was defined,
Sun shipped a servlet that provided the same
functionality as the CGI script. In the discussion
that follows, we will use a stripped-down version
class to demonstrate how HTTP tunneling works.
In the remainder of this section, we will examine the servlet code in detail.
stripped-down servlet code consists of two main
classes and a set of custom exception classes. The
main classes are
They have the following roles:
This class extends
HTTPServlet. It receives requests and
performs preliminary validation (most of which
centers around processing the URL).
This is a set of static methods that know how to take an HTTP POST and resend it to an RMI server running on the same machine. ...