powered by Jive Software

Problem forwarding to roster

In the following code all of the print statements (which just call System.out.println()), print out exactly what you would expect.

But, when using the smack debugger (and witnessing who actually receives message), it will do something random:

For example: If the users bob@domain, joe@domain, and steve@domain are all on this user’s roster, bob will get one message, and joe will get 2, and steve will get 0.

private synchronized void forwardMessageToRoster(Message message) {
if(conn != null) {
if(conn.isConnected()) {
Roster r = conn.getRoster();
Collection res = r.getEntries();
Iterator iter = res.iterator();
ChatManager chatmanager = conn.getChatManager();
while(iter.hasNext()) {
RosterEntry re = (RosterEntry) iter.next();
debugPrint("Roster Entry: " + re.getUser());
Chat newChat = chatmanager.createChat(re.getUser(), null);
try {
debugPrint("Send message: " + message.getBody());
debugPrint("To user: " + newChat.getParticipant());
} catch (XMPPException ex) {
//Logger.getLogger(AlertBot.class.getName()).log(Level.SEVERE, null, ex);

I fixed this by changing the line:

** newChat.sendMessage(message); -> **** newChat.sendMessage(message.getBody());**