Intercepting Packets

Hi,

How do i intercept XMPP Packets/messages within a Sparkplug plugin? The only way I can think of so far is to use the Connetion object and login using the current username and pasword, but this seems cumbersome (unless I can retrieve it from the current session?).

Is there an easire way to intercept Packets?

Cheers,

John.

One way would be to implement the MessageListener. However, this is for Message Packets.

If you are wanting to intercept all packets.

You’'ll want to use smacks api.

You can get Sparks current connection with SparkManager.getConnection().

It will return an instance of XMPPConnection.

Here is the smack api:

http://jivesoftware.org/builds/smack/docs/latest/javadoc/

Here are the sparkplug dev examples:

http://jivesoftware.org/builds/sparkplug_kit/docs/latest/sparkplug_dev_guide.htm l

_Aaron

I forgot to give the smack example.

You’'d write a PacketListener, which would look something similar to this:

PacketListener packetListener = new PacketListener() {
    public void processPacket(Packet packet) {
         // Do what you want with the packet.
    }
};

Then you would get the current Connection like I showed before.

// Get the current Spark XMPP connection.
XMPPConnection connection = SparkManager.getConnection();

Then association the PacketListener to this connection.

// Add the packetlistener.
// packetFilter is something you will need to set in order to filter
// the type of packets you want.
connect.addPacketListener(packetListener, packetFilter);