Groovy Jabber-RPC
| Wiki Markup |
|---|
{link:Jabber-RPC|http://www.jabber.org/jeps/jep-0009.html}{link} |
| Excerpt |
|---|
allows you to make XML-RPC calls using the Jabber protocol |
We use the excellent
| Wiki Markup |
|---|
{link:Smack|http://www.jivesoftware.org/smack/}{link} |
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
Code Block java import groovy.net.xmlrpc.* import org.jivesoftware.smack.XMPPConnection def server = new JabberRPCServer() - Add some methods
Code Block java sever.echo = {return it} // the closure is now named "echo" and is remotely callable - Start the server
Code Block java def serverConnection = new XMPPConnection("talk.example.org", 5222, "example.org") serverConnection.login("myServerId", "myServerPassword") // logging in as myServerId@example.org server.startServer(serverConnection) - You're done!
...
- Create a proxy object to represent the remote server
Code Block java def clientConnection = new XMPPConnection("talk.example.org", 5222, "example.org") clientConnection.login("myClientId", "myClientPassword") // logging in as myClientId@example.orgm def serverProxy = new JabberRPCServerProxy(clientConnection, "myServerId")
- Call the remote method via the proxy
Code Block java 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