Looking at JabberRPCResponder Step by Step

Now let’s examine the JabberRPCResponder script step by step so we can see how it works:

import org.jabber.jabberbeans.*;
import org.jabber.jabberbeans.Extension.*;
import org.jabber.jabberbeans.util.JID;
import java.net.InetAddress;
import java.util.Enumeration;
import java.io.*;
import helma.xmlrpc.*;

We need to bring in the jabberbeans classes as shown, as well as some core Java features that we’ll see used in the script a bit later: an InetAddress to represent the Jabber server’s hostname, an Enumeration interface to access the extensions in the incoming IQ elements, and java.io features for feeding the XML-RPC-encoded requests to the XmlRpcServer object. We also bring in the classes from the Helma XML-RPC library.

public class JabberRPCResponder implements PacketListener
{
  private String server   = "gnu.mine.nu";
  private String user     = "server";
  private String pass     = "pass";
  private String resource = "jrpc-server";

  private XmlRpcServer responder;

  private ConnectionBean cb;

The definition of our JabberRPCResponder class looks similar to that of the HostAlive class in Section 8.2. However, rather than merely connecting to a Jabber server and sending packets off down the stream, we want to listen for incoming packets—in this case, IQ elements carrying jabber:iq:rpc-qualified payloads—and handle them. Accordingly, we specify that our main class implements PacketListener, a JabberBeans interface that Jabber clients use to receive notification ...

Get Programming Jabber now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.