Use the web object channel to pass the Java object through the firewall

zhaozj2021-02-11  202

Summary

If you create an HTTP object channel between the web server and the Applet applet (or any Java Web client program), it will be very useful. In this way, dynamic data can be sent directly to the web client through the firewall in a serial manner. These data can be server-side JavaBean instances, ORB object references, mobile agents, etc. - There is no restriction on this! So, how is the RMI (remote method call)? If you use the standard RMI in JDK 1.1.x, you may meet some questions or restrictions. This trick will explain how a simple and easy-to-use HTTP object channel is implemented by way of explaining and analyzing techniques. (1,500 words)

In order to display dynamic data stored in JavaBeans in JavaBeans, I developed an applet applet. My web object channel function is gradually improved during this development process. I need to consider how to detect changes in this data, and how to download these Beans.

I decided to design a transport layer, allowing the Applet applet to request JavaBeans directly to the server in a serial manner. In addition, since the Applet applet will run outside the company's firewall, I decided to build the transport layer using HTTP.

When running a proxy server, the standard RMI solution requires additional layers, which will cause the applet applet to slow down. At the same time, I will also have to modify the existing servlet into an object that can be called remotely, and then register RMI. Other common questions from the RMI solution include:

Although the Netscape browser (all versions of the Netscape 4.03 after JDK 1.1) have patchs that support RMI, they have limited capacity in implementing communication between applet applets and servers. For example, some security managers do not allow creation of server socket serversocket. Instead, RMI multiplexes established sockets, so communication can maintain virtual bidirection. However, due to the additional layer of the management protocol, the communication speed will slow down.

Microsoft claims to "support Java" in MSIE. But although RMI is already part of the JDK version 1.1 technical specification, Microsoft's browser (Internet Explorer 4.0 and 5.0) does not support RMI by default. Users must install an RMI patch (for example, downloading from Microsoft or IBM website) to run the RMI Applet applet in their MS browser. For more details, see Resources.

Basically, the direct RMI solution is too slow and require too much extra code.

With my web object channel, I just need to extend the existing server-side applet to a new base class and then overload a method.

Model profile

The web object channel is implemented in a series of classes that enables the client and the server side to create a Java object channel. Since this implementation is based on HTTP (request, response protocol), the client needs to build a channel first. (See Figure 1)

figure 1

Click the thumbnail to view full map (15 KB)

The client object includes:

HTTPOBJECTCHANNEL, Client Channel - Access Points with server-side channels. It makes it possible to send HTTP requests to any given Web Server URL address (httpobjectRequest).

HTTPOBJECTREQUEST represents an HTTP request. It handles HTTP communication data between the web server. It sends a POST request to the web server (with the specified parameters) and then waits for returning Java objects. HTTPOBJECTVARG, a container for loading variable parameters. Any parameters required in the request (httpobjectRequest) should be set in this object.

转载请注明原文地址:https://www.9cbs.com/read-5981.html

New Post(0)