Java Reference
In-Depth Information
The web server does not contain the remote methods that clients call via XML-RPC.
These reside in other Java classes, which are called handlers.
To add a handler, call the server's addHandler( String , Object ) method with the speci-
fied handler name and handler object.
The first argument to addHandler() is a name to give the handler, which can be any-
thing—it's comparable to naming a variable. Clients will use this name when calling
remote methods.
The SiteClient application created earlier today called the remote method
dmoz.getRandomSite() . The first part of this call—the text preceding the period—refers
to a handler named dmoz .
The second argument to addHandler() is an object of the class that has public methods,
which can be called remotely.
The following statements create a handler for a WebServer object named server :
DmozHandler odp = new DmozHandler();
server.addHandler( “dmoz”, odp);
The handler in this example is a DmozHandler object, which contains a getRandomSite()
method that returns information about a random site in the Open Directory Project.
You'll be creating this class later.
A class that handles remote method calls can be any Java class that contains public
methods that return a value, as long as the methods take arguments that correspond with
data types supported by Apache XML-RPC: boolean , byte[] , Date , double , Hashtable ,
int , String , and Vector .
You can easily put existing Java classes to use as XML-RPC handlers without modifica-
tion as long as they do not contain public methods that should not be called and each
public method returns a suitable value.
20
CAUTION
The suitability of return values relates to the Apache XML-RPC
implementation rather than XML-RPC itself. Other implementations
of the protocol are likely to have some differences in the data
types of the arguments they take in remote method calls and the
values they return.
Search WWH ::




Custom Search