I have changed the code to use StringUtils and that looks fine. I attach the provider and the packet class files. As you can see they are completely trivial!
Its probably best if I give you an example of using the API in Groovy and than in Java
We are trying to expose the two static methods called “echo” on the following Java class:
class Echo {
public static String echo(final String s) {return s;}
public static int echo(final int i) {return i;}
}
This is how we do it in Groovy:
import groovy.net.xmlrpc.*
import org.jivesoftware.smack.XMPPConnection
def serverConnection = new XMPPConnection(“127.0.0.1”, 5222, “handel”)
def clientConnection = new XMPPConnection(“127.0.0.1”, 5222, “handel”)
serverConnection.login(“server”, “1234”)
clientConnection.login(“client”, “1234”)
println “Starting Server”
def server = new JabberRPCServer()
server.echo = Echo
server.startServer(serverConnection)
println “Started Server”
def proxy = new JabberRPCServerProxy(clientConnection, “server@handel”)
println proxy.echo(“hello”)
println proxy.echo(-3)
println proxy.echo(false)
The first few lines will be familliar to you
The JabberRPCServer instance will provide the service.
The line “server.echo = Echo” tells the server to expose all the static methods called “echo” in the class Echo.
Calling startServer starts the server listening on the connection for jabber-RPC packets. It’'s a multithreaded server so it can deal with mutiple simultaneous calls.
The rest of the script sets up a client connection to the server we have just started.
The JabberRPCServerProxy object wraps the client connection to be used to send the call.
You can just make calls on the proxy object and it will forward them to the remote server and return the result.
The result of executing the script is:
Starting Server
Started Server
hello
-3
Caught: groovy.net.xmlrpc.XMLRPCCallFailureException: XML-RPC call Failure: fault string = "No signature of method Echo.echo() is applicable for argument types: (java.lang.Boolean) values: ", fault code = 0
at Test.run(Test.groovy:24)
at Test.main(Test.groovy)
This is the eqivalent Java version:
public class TestSmack {
public static void main(String[] args) throws Exception {
final XMPPConnection serverConnection = new XMPPConnection(“127.0.0.1”, 5222, “handel”);
final XMPPConnection clientConnection = new XMPPConnection(“127.0.0.1”, 5222, “handel”);
serverConnection.login(“server”, “1234”);
clientConnection.login(“client”, “1234”);
System.out.println(“Starting Server”);
final JabberRPCServer server = new JabberRPCServer();
server.setProperty(“echo”, Echo.class);
server.startServer(serverConnection);
System.out.println(“Started Server”);
final JabberRPCServerProxy proxy = new JabberRPCServerProxy(clientConnection, “server@handel”);
System.out.println(proxy.invokeMethod(“echo”, new Object[]{“hello”}).toString());
System.out.println(proxy.invokeMethod(“echo”, new Object[]{new Integer(-2)}).toString());
System.out.println(proxy.invokeMethod(“echo”, new Object[]{Boolean.FALSE}).toString());
}
}
JabberRPCProvider.java (1871 Bytes)
JabberRPC.java (1003 Bytes)