FileDocCategorySizeDatePackage
LightweightXmlRpcServer.javaAPI DocExample5521Sat Jun 03 12:43:32 BST 2000com.oreilly.xml

LightweightXmlRpcServer

public class LightweightXmlRpcServer extends Object
LightweightXmlRpcServer is a utility class that will start an XML-RPC server listening for HTTP requests and register a set of handlers, defined in a configuration file.
author
Brett McLaughlin
version
1.0

Fields Summary
private helma.xmlrpc.WebServer
server
The XML-RPC server utility class
private XmlRpcConfiguration
config
Configuration file to use
Constructors Summary
public LightweightXmlRpcServer(String configFile)

This will store the configuration file for the server to use.

param
configFile String filename to read for configuration information.
throws
IOException when the server cannot read it's configuration information.


        config = new XmlRpcConfiguration(configFile);
    
Methods Summary
public static voidmain(java.lang.String[] args)

Provide a static entry point.


        if (args.length < 1) {
            System.out.println(
                "Usage: " +
                "java com.oreilly.xml.LightweightXmlRpcServer " +
                "[configFile]");
            System.exit(-1);
        }

        try {
            // Load configuration information
            LightweightXmlRpcServer server =
                new LightweightXmlRpcServer(args[0]);

            // Start the server
            server.start();
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    
private voidregisterHandlers(java.util.Hashtable handlers)

This will register the handlers supplied in the XML-RPC server (typically from {@link #getHandlers()}.

param
handlers Hashtable of handlers to register.

        Enumeration handlerNames = handlers.keys();

        // Loop through the requested handlers
        while (handlerNames.hasMoreElements()) {
            String handlerName = (String)handlerNames.nextElement();
            String handlerClass = (String)handlers.get(handlerName);

            // Add this handler to the server
            try {
                server.addHandler(handlerName,
                    Class.forName(handlerClass).newInstance());

                System.out.println("Registered handler " + handlerName +
                                   " to class " + handlerClass);
            } catch (Exception e) {
                System.out.println("Could not register handler " +
                                   handlerName + " with class " +
                                   handlerClass);
            }
        }
    
public voidstart()

This will start up the server.

throws
IOException when problems occur.

        try {
            // Use Apache Xerces SAX Parser
            XmlRpc.setDriver(config.getDriverClass());

            System.out.println("Starting up XML-RPC Server...");
            server = new WebServer(config.getPortNumber());

            // Register handlers
            registerHandlers(config.getHandlers());

        } catch (ClassNotFoundException e) {
            throw new IOException("Error loading SAX parser: " +
                e.getMessage());
        }