Methods Summary |
---|
public static void | main(java.lang.String[] args)
JabberRPCResponder server = new JabberRPCResponder();
try
{
server.start();
}
catch (Exception e)
{
System.out.println("Cannot start server: " + e.toString());
}
|
public void | receivedPacket(PacketEvent pe)
Packet packet = pe.getPacket();
System.out.println("RECV:" + packet.toString());
if (packet instanceof InfoQuery)
{
Enumeration e = ((InfoQuery)packet).Extensions();
if (e.hasMoreElements())
{
Extension ext = (Extension)e.nextElement();
String request = ext.toString();
String id = ((InfoQuery)packet).getIdentifier();
JID from = ((InfoQuery)packet).getFromAddress();
ByteArrayInputStream bis =
new ByteArrayInputStream(request.getBytes());
String result = new String(responder.execute(bis));
String response = result;
int pos = result.lastIndexOf("?>");
if (pos >= 0)
{
response = result.substring(pos + 2);
}
IQRPCBuilder iqrpcb = new IQRPCBuilder();
iqrpcb.setPayload(response);
InfoQueryBuilder iqb = new InfoQueryBuilder();
iqb.setType("result");
iqb.setIdentifier(id);
iqb.setToAddress(from);
iqb.addExtension(iqrpcb.build());
InfoQuery iq;
try {
iq = (InfoQuery)iqb.build();
}
catch (InstantiationException ie)
{
System.out.println("Build failed: " + ie.toString());
return;
}
cb.send(iq);
}
}
|
public void | sendFailed(PacketEvent pe)
Packet packet = pe.getPacket();
System.out.println("failed to send:" + packet.toString());
|
public void | sentPacket(PacketEvent pe)
Packet packet = pe.getPacket();
System.out.println("SEND:" + packet.toString());
|
public void | start()
cb = new ConnectionBean();
InetAddress addr;
cb.addPacketListener(this);
// Connect
cb.connect(addr=InetAddress.getByName(server));
// Authenticate
InfoQueryBuilder iqb = new InfoQueryBuilder();
IQAuthBuilder iqAuthb = new IQAuthBuilder();
iqb.setType("set");
iqAuthb.setUsername(user);
iqAuthb.setPassword(pass);
iqAuthb.setResource(resource);
iqb.addExtension(iqAuthb.build());
InfoQuery iq = (InfoQuery)iqb.build();
cb.send(iq);
// Send presence
PresenceBuilder pb = new PresenceBuilder();
cb.send(pb.build());
|