Java Reference
In-Depth Information
Using Apache XML-RPC, the web server allows any public method in the handler to be
called, so you should use access control to keep prying clients out of methods that should
remain off limits.
As the first step toward the creation of an XML-RPC service, the following code creates
a simple web server that takes XML-RPC requests. Enter the text of Listing 20.4 and
save the file as DmozServer.java .
LISTING 20.4
The Full Text of DmozServer.java
1: import java.io.IOException;
2: import org.apache.xmlrpc.WebServer;
3: import org.apache.xmlrpc.XmlRpc;
4:
5: public class DmozServer {
6: public static void main(String[] arguments) {
7: if (arguments.length < 1) {
8: System.out.println(“Usage: java DmozServer [port]”);
9: System.exit(0);
10: }
11: try {
12: startServer(arguments[0]);
13: } catch (IOException ioe) {
14: System.out.println(“Server error: “ +
15: ioe.getMessage());
16: }
17: }
18:
19: public static void startServer(String portString) throws IOException {
20: // Start the server
21: int port = Integer.parseInt(portString);
22: System.out.println(“Starting Dmoz server ...”);
23: WebServer server = new WebServer(port);
24:
25: // Register the handler
26: DmozHandler odp = new DmozHandler();
27: server.addHandler(“dmoz”, odp);
28: server.start();
29: System.out.println(“Accepting requests ...”);
30: }
31: }
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.
 
Search WWH ::




Custom Search