Groovy Jabber-RPC
Jabber-RPC
allows you to make XML-RPC calls using the Jabber protocol. Groovy has a Jabber-RPC implementation which allows you to create a local Jabber-RPC server and to make calls on remote Jabber-RPC servers. Jabber servers are widely available and very easy to set up and run. The Google GTalk service uses Jabber and the Groovy Jabber-RPC package works over GTalk.
We use the excellent
Smack
Jabber library from Jive Software to handle the protocol details.
The Server
It's really easy to set up a server which provides a set of remotely callable functions.
- Create a server object
import groovy.net.xmlrpc.*
import org.jivesoftware.smack.XMPPConnection
def server = new JabberRPCServer()
- Add some methods
- Start the server
def serverConnection = new XMPPConnection("talk.example.org", 5222, "example.org")
serverConnection.login("myServerId", "myServerPassword") server.startServer(serverConnection)
- You're done!
The Client
It's pretty easy to make the remote calls too
- Create a proxy object to represent the remote server
def clientConnection = new XMPPConnection("talk.example.org", 5222, "example.org")
clientConnection.login("myClientId", "myClientPassword") def serverProxy = new JabberRPCServerProxy(clientConnection, "myServerId")
- Call the remote method via the proxy
println severProxy.echo("Hello World!")
- As long as myClientId@example.org and myServerId@example.org are buddies then the call will be made and the result returned