Most read:
Popular archives:
JavaWorld's new look is here!
We've upgraded the site with a fresh look-and-feel, improved topical navigation, better search, new features, and expanded
community platform. Learn more about the changes to JavaWorld.
| Oracle Compatibility Developer's Guide |
| The Explosion in DBMS Choice |
I decided to design a transport layer that would allow the applet to request the JavaBeans directly from the server in a serialized form. Moreover, since the applet would be used outside the corporate firewall, I decided to use HTTP to build the layer.
A standard RMI solution would have incurred extra delays when run with proxy servers, making the applet appear slower. Additionally, I would have had to modify my existing servlets into remotable objects, then deal with an RMI registry. Other common problems with the RMI solution include:
ServerSockets. Instead, RMI multiplexes on the established socket, so communication remains (virtually) bidirectional, but slows down
because of the additional layer that manages the protocol.
Basically, the straight RMI solution was too slow and required too much additional coding.
With my custom Web Object Tunneling, I only had to modify my existing servlets to extend a new base class and override a single method.
Web Object Tunneling is implemented inside a set of classes, which enables the creation of Java object channels between clients and servlets. The client party originally creates the channel, since the implementation is based on HTTP (request/response protocol). (See Figure 1.)
Figure 1
Click on thumbnail to view full image (15 KB)
The client-side objects involved are:
HttpObjectChannel, the client-side channel -- the entry point for any communication with server-side channels. It makes it possible to initiate
HTTP requests (HttpObjectRequest) to any given Web server URL (HttpObjectChannelServlet).
HttpObjectRequest, which represents an HTTP request. It handles the HTTP communication exchanges with the Web server. It sends POST requests (along with any desired argument) to the Web server and waits for Java objects to be returned.
HttpObjectVarg, a variable arguments container. Any argument required in a request (HttpObjectRequest) should be SET inside this object.
The server-side objects involved are:
HttpObjectChannelServlet, the server-side channel. You can extend this class to construct a servlet that can respond to HTTP requests with serialized
Java objects.
HttpObject: This interface can be implemented by any (serializable) object that should be "freed" right after HttpObjectChannelServlet sends it to the client. That is, if you want to help the garbage collector clean the object, implement HttpObject with a customized free() method (for example, to close sockets or break circular references).
This example makes an HTTP request to a servlet, sends it some variables (var1, var2, and var3), waits for an object to be returned, and prints the returned object.