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

The Bank via HTTP Tunneling

HTTP tunneling is enabled by default in RMI. Using HTTP tunneling doesn’t require any code changes on either the client or the server. Instead, all that is required is that a web server be installed and configured. The complete list of steps to accomplish this for the bank example are:

  1. Install the web server. I chose to install JavaWebServer because, as far as I can tell, it is the easiest web server to install and configure.

  2. Add the servlet to the web server. This boils down to somehow telling the web server that URLs beginning with /cgi-bin/java-rmi.cgi are mapped to the servlet handling HTTP tunneling (in this case, SimplifiedServletHandler).

  3. Test to make sure everything works.

Testing is sometimes a little tricky. Developers often don’t have a firewall readily available in their development environment. To help get around this difficulty, Sun has provided a socket factory class, sun.rmi.transport.proxy.RMIHttpToCGISocket-Factory, which only uses HTTP tunneling when attempting to connect to a server. That is, of the five ways a default socket factory can connect to a server, instances of sun.rmi.transport.proxy.RMIHttpToCGISocketFactory will use only the final two. Namely:

  1. It attempts to connect on port 80 of the server machine and send the request to a URL beginning with /cgi-bin/java-rmi.cgi. The interpretation of this URL is that the request will be forwarded to a program that interprets the HTTP request and forwards it, as an HTTP request, to ...

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