March 7, 2011, 11:55 a.m.
posted by berg
Working with Apache XML-RPC
There are a lot of different ways for two computer programs to communicate with each other over the Internet or another network. The simplest of all may be XML-RPC, which is short for XML Remote Procedure Call, a protocol developed in 1998 by Dave Winer of UserLand Software and Microsoft to foster web services.
Client/server implementations of XML-RPC are now available for most operating systems and programming languages in wide use. Winer publishes a directory of them on the Web at http://www.xmlrpc.com.
XML-RPC works by transmitting XML over HTTP, the same protocol that's used by web browsers and web servers. XML was covered in Hour 21, "Reading and Writing XML Data," and you'll get more practice with the XML Object Model (XOM) class library as it's employed during this hour.
The XML-RPC protocol makes it possible to call methods and receive data in return in a language- and operating system–independent manner.
The process isn't directly analogous to Java—you don't create an object and call a method, because XML-RPC is simpler than Java and supports different data types. XML-RPC also does not support objects.
Behind the scenes, XML-RPC supports its own distinct data types, but you don't need to know any of that when using Apache XML-RPC, a class library offered by the developers of the Apache web server and Tomcat Java servlet container.
Apache XML-RPC can be downloaded from http://ws.apache.org/xmlrpc, a site that includes Javadoc documentation and additional support. The software is released under an open source license, so you must familiarize yourself with its terms before deciding whether to adopt it on a project.
Though version 2.0 of Apache XML-RPC was released in spring 2005, this hour's Java classes have been written for version 1.2, a stable release that has been available for more than a year. You may be able to compile and run these classes with the most current 2.0 release by the time this chapter sees print.
To install Apache XML-RPC, download the software as a ZIP archive (Windows), or in TAR.GZ format on other operating systems. Two files must be stored in a directory that's in the Classpath of the Java interpreter and compiler. For version 1.2, these files are xmlrpc-1.2-b1.jar and xmlrpc-1.2-b1-applet.jar.
The programs that you create during this hour will function as an XML-RPC client and XML-RPC server to enhance the capabilities of the LottoMadness application from Hour 15, "Responding to User Input."
LottoMadness will gain the ability to save the results of the drawings that it performs, sending results to a central server where they are saved as an XML file.
This requires two programs—a client that makes an XML-RPC method call and a server that takes the call.