Home built Packet Interceptor modifying everything twice

Hi All,

I’m having real problems building even just a simple packet Interceptor.

The crux of my code is this:

private class SubmitterChatListener implements PacketInterceptor {


public void interceptPacket(Packet packet, Session session,

boolean incoming, boolean processed)

throws PacketRejectedException {

if (isEnabled()) {

if (packet instanceof Message) {

String modifiedMessage = ((Message) packet).getBody();

modifiedMessage = "[Modified Message]: " + ((Message) packet).getBody();

((Message) packet).setBody(modifiedMessage);

…but when I run it I get strange behavior. I have sent a test message from test12 to matt and I get:

(12:35:49 AM) test12: [Modified Message]: [Modified Message]: null

(12:35:56 AM) test12: [Modified Message]: [Modified Message]: Test Message

Any ideas what’s going on here? What;s the correct way to intercept packages, find whether it’s a chat message (and not a presence update or something) and modify the message body?

Many thanks


Hint: Add also the values of ‘incoming’ and ‘processed’ to modifiedMessage.