Step by Step
We’ll examine the script a chunk at a time. We start by importing the libraries (the classes) we would like to use:
import org.jabber.jabberbeans.*; import org.jabber.jabberbeans.Extension.*; import java.net.InetAddress;
The JabberBeans library is highly modular and designed so
we can pick only the features that we need; in this case, however,
we’re just going to import the whole set of classes within the
org.jabber.jabberbeans and
org.jabber.jabberbeans.Extension packages,
for simplicity.
We’re also going to be manipulating the Jabber server’s hostname,
so we pull in the InetAddress class for convenience.
The script must connect to the Jabber server on gnu.pipetree.com as the myserver user. We define some constants for this:
public class HostAlive
{
public static final String SERVER = "gnu.pipetree.com";
public static final String USER = "myserver";
public static final String PASSWORD = "secret";
public static final String RESOURCE = "alive";
In the same way as with the Python-based CVS notification script earlier in this chapter, we also start off by building a connection to the Jabber server. As before, it’s a two-stage process. The first stage is to create the connection object:
public static void main(String argv[])
{
ConnectionBean cb=new ConnectionBean();
A ConnectionBean object represents the connection
between the script and the Jabber server. All XML fragments (Jabber
elements) pass through this object.
Then it’s time to attempt the socket connection ...
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