powered by Jive Software

Smack 4.2.3 Unable To get Callabck to newIncomingMessage()


#1

Hi guys I know there are lot of questions out there for this and I’ve tried most of them but I am not quite sure that what is going on now.So the thing is when I am sending message from one user to another user,The sender newOutgoingMessage gets callback but receiver newIncomingMessage is not getting callback.So what is the situation:-

  1. Sender newOutgoingMessage getting callback but receiver newIncomingMessage is not getting callback.

  2. Even Though The receiver is online,newIncomingMessage not getting callback and once user is offline message is saved as offline message.(Presence is set to true)

  3. In the logs i can clearly see the message,but function is not getting callback.

Here is my code:-

                        XMPPTCPConnectionConfiguration config 	= 	null;
                        AbstractXMPPConnection 	connection	=	null;
                       ChatManager		 chatManager	=	null;

                       config	= XMPPTCPConnectionConfiguration.builder()
				  .setUsernameAndPassword("username","password")
				  .setXmppDomain("localhost")
				  .setPort(5222)
				  .setHost("localhost")
				  .setResource("username")
				  .setSecurityMode(SecurityMode.disabled)
				  .setSendPresence(true)
				  .setDebuggerEnabled(true)
				  .build();
                     
                     connection = new XMPPTCPConnection(config);
		     connection.connect();
		     connection.login();

                     chatManager	 	=	ChatManager.getInstanceFor(connection);
                     AddListeners.addListeners(connection,chatManager);

                 public static void addListeners(AbstractXMPPConnection connection,ChatManager           chatManager)
	{
		if(connection == null)
		{
			System.out.println("connection is null");
			return ;
		}
		else
		{
			System.out.println("Connected with: "+connection.getUser());
		}
	if(chatManager.addOutgoingListener(new OutgoingChatMessageListener()
		{
            @Override
            public void newOutgoingMessage(EntityBareJid to, Message message, Chat chat)
            {
               System.out.println("Sender 2 Message Called: New Message To "+ to+" : "+message.getBody()
                				+ " from : "+connection.getUser()+ "at: "+Util.currentDateTime());
            }
		}))
		{
			System.out.println("Outgoing Listener Added");
		}
		else
		{
			System.out.println("Failed To Add Outgoing listener");
			return ;
		}
		
		
		if(chatManager.addIncomingListener(new IncomingChatMessageListener() 
		{
			  @Override
			  public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) 
			  {
				  System.out.println("Receiver Message called : New incoming message from " + from + ": " + message.getBody()
						  			+ " at : "+Util.currentDateTime());
			  }
		}))
		{
			System.out.println("Incoming listener Added");
		}
		else
		{
			System.out.println("Failed To Add Incoming listener");
			return ;
		}
}

public static void sendMessage(AbstractXMPPConnection connection,ChatManager chatManager)
{
	try
	{
		if(connection == null)
		{
			System.out.println("connection is null");
			return ;
		}
		else
		{
			System.out.println("Connected with: "+connection.getUser());
		}
		
		EntityBareJid jid 	=   JidCreate.entityBareFrom("admin@localhost");
		Chat chat = chatManager.chatWith(jid);
		Message newMessage = new Message();
        newMessage.setBody("This is to confirm that it is working or not we will see 10");
        chat.send(newMessage);
    }
	catch(Exception e)
	{
		System.out.println("Exception caught in sending messages due to: "+e);
		return ;
	}
	System.out.println("completed");
}

But still Receiver addIncomingListener not geting call,can anybody help me with this and tell me what is going wrong?

Is there any configuration in ejabberd.yml file that I am missing?

Any help will be greatly appreciated.Thanks


#2

Could you share a stanza log?