The IQRPC classes
JabberBeans deals with Jabber element
extensions—<query/> and
<x/> tags—using individual
helper classes. We’ve seen this in the HostAlive
recipe in Section 8.2, where the
IQAuthBuilder class is used to construct an
authorization extension:
<query xmlns='jabber:iq:auth'> <username>alive</username> ... </query>
The helper classes are oriented around namespaces. Because we
have a new namespace to
deal with (jabber:iq:rpc), JabberBeans needs to have helper classes to handle extensions in that namespace.
We need a minimum of two helper classes. We need a class that represents an
extension—a <query/> tag—in
the
jabber:iq:rpc namespace. If we are going to construct
IQ elements containing such Jabber-RPC extensions, we also need a
class to build those extensions. The class that
represents the jabber:iq:rpc extension is called
IQRPC, and the class that is the builder for the
extensions is called IQRPCBuilder.
For an example we’re already familiar with, look at the steps leading up to the authorization phase in the HostAlive script (and indeed our JabberRPCResponder script, which is shown in the next section); the authorization IQ element is constructed as follows:
InfoQueryBuilder iqb = new InfoQueryBuilder();
IQAuthBuilder iqAuthb = new IQAuthBuilder();
iqb.setType("set");
iqAuthb.setUsername(user);
iqAuthb.setPassword(pass);
iqAuthb.setResource(resource);
iqb.addExtension(iqAuthb.build());If we bear in mind that this is what we want to end up with:
<iq type='set'> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access