powered by Jive Software

Messages not being sent?

We have a server application that is running in jboss, and we have started using smack as a means to notify when certain events happen within the application. However, we are seeing a problem that occurs with about 10% of the messages we send. That is that we see smack connect successfully to the jabber server, but we don’'t see any message sent, and then we see it disconnect.

Our server is Jabberd 1.4.2. We are running all messaging over SSL. We have been running Jabberd in debug mode so that we can see all events taking place in the server. Messages that are successful appear just as expected. We see our “smack” client establish an SSL session, become authenticated, then we see the message sent to the expected recipient, and then we see the closing of the SSL session. However, on the occasions when it fails, we see the “smack” client establish an SSL, session, become authenticated, but we do not see the message being sent, and then we see the closing of the SSL session.

Our debug log for our jboss application traces the calls we are making to smack and we can see a one to one correlation with the messages being sent in jboss with the connection of smack with the server. But in the case of a failed message, we still see in our jboss log that the message was sent, but at the jabber server side a message never gets sent, we only see the session created and then disconnected.

We have provided our code below…

Has anyone else seen this type of behavior, or know how we might better determine what is going wrong in our process.


public static boolean sendIM( Integer nAccountId, Vector to , String strMsg )
{
    boolean bRetVal = false ;
        SSLXMPPConnection IMconnection = null ;
    Chat chat = null ;
    String strRecipientName = null;     if(nAccountId.intValue()==1) {
        try {
            GlobalUtils.log( CLASS_NAME, GlobalUtils.kLOG_INFO, "Sending Jabber message...");         // Connect if we are not connected already
        IMconnection = ConnToJabberServer(nAccountId);                    
        // Send to each recipient
        Iterator iter = to.iterator();
        while( iter.hasNext() ) {
            strRecipientName = ( String ) iter.next();
            if ( IMconnection != null ) {
                if (  IMconnection.isConnected() ) {
                    chat = IMconnection.createChat( strRecipientName + "." + nAccountId.toString() + "@" + kJabberServerName) ;
                    if (chat != null) {
                         chat.sendMessage(".\n- Hi " + strRecipientName + " -\n" + strMsg );
                        GlobalUtils.log( CLASS_NAME, GlobalUtils.kLOG_INFO, "Sent message to: " + strRecipientName + "." + nAccountId.toString() + "@" + kJabberServerName);
                    }
                    else {
                        GlobalUtils.log( CLASS_NAME, GlobalUtils.kLOG_INFO, "Failed to create jabber chat object...");
                    }
                    bRetVal = true ;
                }
            }
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
        finally {
            if (  IMconnection != null )
                if ( IMconnection.isConnected() )
                    IMconnection.close() ;
        }
    }
    return( bRetVal );
}

Message was edited by: KrashTestDummy

Hi,

If you have a chance, please edit your post and surround your Java code with java source code without the spaces between brackets and ‘‘code’’ (I added spaces between the brackets and the code words so it won’'t be parsed). That will pretty print your code.

You may want to read this post:

that explains how Smack uses exceptions. You are doing null checks on your created objects - it’'s not necessary since any failure to create a valid object will result in a thrown exception.

There is a small chance that your connection is being closed before the message is transmitted to the server. It’'s hard to tell though. Could you recreate the error in a standalone java application? That would give us a better test case we can then run and see where the problem lies (just attach the source to your reply). It would also let you start the app with the Smack debug option turned on allowing you to see the packet streams being exchanged.

-iain

I reformatted your code so that it’'s more readable. Aaargh, tabs suck!

A few comments:

  • As Iain mentioned, you should remove the null checks. There is no need for them.

  • You shouldn’‘t create the XMPP connection inside of that method. You need to make sure there isn’‘t more than one connection at a time to the server since most XMPP servers are setup to not allow more than one connection at a time. This is likely the source of your dropped connections – the method is called in different threads at the same time and then one of the connections fails. A much better architecture would be a connection created through a factory that included some logic to keep the connection open until it’'s been idle for five minutes or something. This will be much less wasteful then creating new connections all the time.

  • The Smack debug tool will help a bunch.

  • Why not use Jive Messenger as the server?

Regards,

Matt

Thanks for the suggestion. I am keeping the connection open for a longer time and that indeed fixed that problem.