Help with PacketCollector

Need help with the code snippet below. I was trying the below example but could not make it work.

public void testHugeMessage() {

getConnection(0).sendPacket(new Presence(Presence.Type.available));

getConnection(1).sendPacket(new Presence(Presence.Type.available));

// User2 becomes available again

PacketCollector collector = getConnection(1).createPacketCollector(

new MessageTypeFilter(Message.Type.chat));

// Create message with a body of 4K characters

Message msg = new Message(getFullJID(1), Message.Type.chat);

StringBuilder sb = new StringBuilder(5000);

for (int i = 0; i <= 4000; i++) {

sb.append(“X”);

}

msg.setBody(sb.toString());

// Send the first message

getConnection(0).sendPacket(msg);

// Check that the connection that sent the message is still connected

assertTrue(“Connection was closed”, getConnection(0).isConnected());

// Check that the message was received

Message rcv = (Message) collector.nextResult(1000);

assertNotNull(“No Message was received”, rcv);

}

The test fails because collector.nextResult(1000) returns NULL. Is there something I am missing? Please let me know. I tried increasing the timeout value to 5000 ms also.

I am sure message send and receive is working because I have checked it manually.

Thanks in advance.

Message was edited by: user1-user1

Message was edited by: user1-user1

but the following works. can someone please tell me what is the difference between the 2 approaches. Thanks

PacketCollector collector = getConnection(1).createPacketCollector(

new PacketFilter() {

public boolean accept(Packet p) {

if (p instanceof Message) {

Message m = (Message)p;

return true;

}

return false;

}

});

Here’‘s the accept method from MessageTypeFilter. I don’'t see the issue yet either.

public boolean accept(Packet packet) {<br />
        if (!(packet instanceof Message)) {<br/>
            return false;<br/>
        } else {<br/>
            return ((Message) packet).getType().equals(this.type);<br/>
        }
}