|
Let's go back to that idea of locally collecting information on a client computer and sending the information across a network to a server. We are supposing that a user on a local machine will fill out an information request form. The data is sent to the vendor's server. The server processes the request and will, in turn, want to send back product information the client can view, as shown in Figure 5-1. Figure 5-1. Transmitting objects between client and serverIn the traditional client/server model, the client translates the request to an intermediary transmission format and sends the request data to the server. The server parses the request format, computes the response, and formats the response for transmission to the client. The client then parses the response and displays it to the user. If you implement this approach by hand, there is a significant coding hassle: You have to design a transmission format, and you have to write code for conversion between your data and the transmission format. NOTE
What we want is a mechanism by which the client programmer makes a regular method call, without worrying about sending data across the network or parsing the response. The problem is, of course, that the object that carries out the work is not located in the same virtual machine. It might not even be implemented in the Java programming language. The solution is to install a proxy for the server object on the client. The client calls the proxy, making a regular method call. The client proxy contacts the server. Similarly, the programmer of the server object doesn't want to fuss with client communication. The solution is to install a second proxy object on the server. The server proxy communicates with the client proxy, and it makes regular method calls to the server object (see Figure 5-2). Figure 5-2. Remote method call with proxiesHow do the proxies communicate with each other? That depends on the implementation technology. There are three common choices:
NOTE
CORBA and SOAP are completely language neutral. Client and server programs can be written in C, C++, Java, or any other language. You supply an interface description to specify the signatures of the methods and the types of the data your objects can handle. These descriptions are formatted in a special language, called Interface Definition Language (IDL) for CORBA and Web Services Description Language (WSDL) for SOAP. Quite a few people believe that CORBA is the object model of the future. Frankly, though, CORBA has had a reputationsometimes deservedfor complex implementations and interoperability problems. After running into quite a few CORBA problems while writing this chapter, our sentiments about CORBA are similar to those expressed by French president Charles De Gaulle about Brazil: It has a great future . . . and always will. SOAP may have once been simple, but it too has become complex, as it acquires more of the features that CORBA had all along. The XML protocol has the advantage of being (barely) human-readable, which helps with debugging. On the other hand, XML processing is a significant performance bottleneck. Overall, CORBA is more efficient, although SOAP is a better fit for a web architecture. If both communicating objects are implemented in Java code, then the full generality and complexity of CORBA and SOAP is not required. Sun developed a simpler mechanism, called Remote Method Invocation (RMI), specifically for communication between Java applications. NOTE
Because RMI is easier to understand than CORBA or SOAP, we start this chapter with a thorough discussion of RMI. In the last sections of this chapter, we briefly introduce CORBA and SOAP. We show you how to use CORBA for communicating between Java and C++ programs and how to access a web service with SOAP. |
|