This class can’t be compiled successfully until you have created the handler class DmozHandler. The DmozServer application takes a port number as a command-line argument and calls the startServer() method with this argument.
The startServer() method creates a WebServer object that monitors that port number for incoming XML-RPC requests. One handler is added to the server: a DmozHandlerobject given the name “dmoz”; then the server’s start() method is called to begin listening for requests. That’s all the code required to implement a functional XML-RPC server.
Most of the work is in the remote methods you want a client to call, which don’t require any special techniques as long as they are public and they return a suitable value. To give you a complete example you can test and modify to suit your own needs, the DmozHandler class is provided. The techniques employed in this class were covered during Day 18, “Accessing Databases with JDBC,” and are a good review of how to use JDBC to retrieve records from a database—in this example a MySQL database called db1. Enter the text of Listing 20.5 and save the file as DmozHandler.java; then compile the classes DmozServer.java and DmozHandler.java.
Lines 28–32 of the DmozHandler application should be changed to reflect your own database drive, username, and password. You also might need to change the rest of the string used to connect to the database, depending on your driver. The server is run by specifying the port number at a command line, as in this example:
java DmozServer 4413
After the server is up and running, you can modify the SiteClient application to connect to a different XML-RPC server. Change lines 36–37 of Listing 20.3 to replace localhost:4413 with a reference to the server’s computer followed by a colon and port number, as in the following:
XmlRpcClient client = new XmlRpcClient( “http://cadenhead.org:4413/”);