Break through the firewall - Java tunnel communication based on HTTP protocol
Author: Author Du Du Xuan Xuan, Shanghai Institute of ZTE Corporation, a software engineer, you can contact him by du.xuan@zte.com.cn. Abstract Enterprise applications based on Java platform can be applied to the Internet through Java tunneling technology. Java Tunnel technology can establish a Java message tunnel and remote method call with existing web server and servlet containers. Since the HTTP protocol is based, the Java tunnel is a transparent tunnel of the firewall. Java Tunnel Technology is a nice choice for Internet enterprise applications based on Java platform. 1. Introduction In an Internet-based enterprise application, crossing the firewall is a problem that the enterprise application system must face. The HTTP protocol is the only protocol that can be free from the Internet, and the firewall only is transparent to HTTP access, and other protocols are blocked outside the firewall. Web Service is based on this reason, using HTTP to complete the integration of heterogeneous companies in the Internet. This article proposes to make the Java platform-based enterprise application does not have to wait for Web Service to gradually mature, and use Java tunnel technology to implement enterprise application deployment on the Internet. Java tunnel technology is not a new technology, which is a java object serialization and the combination of Web technology. In 2001, people have done tests based on Java tunnel. The book on Java servlet also has a discussion of Java tunnel technology (reference [2]). This article first reviews the basic principles of Java tunnel technology, and then achieve it through an example. This is the foundation with this Java tunnel callback technology and Internet communication based on Java tunnel technology. The content of this article can be used for the Java Web Start client deployment on the Internet, which can be used to use the Java application service interconnected by the Internet. 2. The SIMPLE Object Application Protocol in the Java Tunnel Communication Web Service technology is simple to serve the objects to serialize and deserialize the protocols with XML. The advantage of XML is the independence of the platform, regardless of the form of performance in different platforms, ultimately can use XML to implement the interchange of objects. Also, the Web Service based on the HTTP protocol can pass through the firewall. Web service technology integrates the application on the Internet is its strength. Web Service technology is a good idea, including IBM, Microsoft, Sun and other companies to promote their own related products. We can say that in the integration of the heterogeneous platform, the Web Service will play an important role in B2B applications. However, for enterprise applications for Java platforms, you can use the same principle of Web Service, using the Java platform object sequence, and then use Web technology to complete the application deployment on the Internet. Such techniques are Java tunneling techniques. Because this technology is implemented using existing basic techniques, it can be very easy to complete the system architecture. Of course, the positioning of the Java tunnel with the Web Service is completely different, and they should use in different occasions. Web service is more powerful, more common, is an emerging interviewable standard. It is also because of the power of Web Service, so it is more complicated. To answer the following questions, let's see which technology you need to architecture to architerate:
1. Is the interconnected system be a Java platform? 2. Do you want to deploy on the Internet? 3. Do you want to cross the firewall? If the answer to the first question is "No", other questions answer "Yes", then don't choose, you must use Web Server technology; if the above question is "Yes", you can use web service to come Architecture system, of course, you can also use it more convenient, simple, and efficient Java tunnel technology. The basic framework of Java tunnel technology is shown below. The communication architecture of the Java tunnel system provides HTTP services by Web Server, and servlet containers handle Java serialized objects. For such a framework, we can use common Tomcat, Jetty and other software as the Java tunnel technology to run an underlying environment. The basic working principle of Java tunnel technology is this: First, the Java client seizes objects, and uses the HTTP protocol packaging sequence-transmitted object's byte stream propagating on the Internet, and is submitted to the Web Server through the firewall. The servlet container peels off the HTTP protocol, takes out serialized objects, and re-sequences the Java object, and passes the application to the background. The entire work process is to perform the Java serialization, and complete communication on the Internet via the HTTP protocol. Since Java serialization technology is a function of Java 1.1, you can implement just as long as you implement a java.io.Serializable interface. There is a lot of implementation of the servlet container integrated Web Server, and there is no shortage of open source, such as Tomcat, Jetty. These reflect the simplicity of the Java tunnel technology framework. Below we take a look at how Java tunnel technology is implemented. 3. Example We choose Jetty (Jetty 4.2.21) as a running container for Web Server and Java Servlet. Write a normal Java application TunnelClient as a client of the Java tunnel. Write a Servlet program tunnelServer as a server of Java tunnel. As shown below, run the Java tunnel client program, call the tunnel service inside the program http://127.0.0.1:8080/servlets/servet/tunnelserver. Returns the object from the server, the object content is printed on the console. As shown below, it is the operation of TunnelServer in the Jetty server, we can see the screen prints of TunnelServer from the object content obtained by the client. From the following tunnel server program tunnelserserver, we can see that tunnel service is first a servlet program, TunnelServer inherits in java.servlet.httpservlet. Object transfer in the tunnel is achieved by java.io.ObjectInputStream, Java.io.ObjectOutstream. The object being passed, first must be a sequential object, that is, a java.io.Serializable interface must be implemented. The MSG class in the example code is a class that implements the java.io.serializable interface. The MSG object passes the remote delivery of an object through java.io.objectInputStream, Java.io.ObjectOutStream. Since TunnelServer is inherited in java.servlet.httpservlet, the object's transmission is based on HTTP protocol. The remote transfer of the object can be because the firewall is due to the result of the HTTP protocol.