O'Reilly logo

Java RMI by William Grosso

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Servlet Implementationof HTTP Tunneling

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 of the SUN class to demonstrate how HTTP tunneling works.

In the remainder of this section, we will examine the servlet code in detail.

The Servlet Code

The stripped-down servlet code consists of two main classes and a set of custom exception classes. The main classes are SimplifiedServletHandler and ServletForwardCommand. They have the following roles:

SimplifiedServletHandler

This class extends HTTPServlet. It receives requests and performs preliminary validation (most of which centers around processing the URL).

ServletForwardCommand

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required