How do I determine if a Chat.sendMessage() call is successful?

The only way that I can figure out to this is the following:

Chat chat = connection.createChat (recipient);

chat.sendMessage (“message body”);

Message m = chat.nextMessage (500);

if (null != m && chatm.getType ().equals (Message.Type.ERROR))

throw new Exception (“send Message failed”);

[/code

I think that there has to be some better way to determine if a Message was

sent successfully, because this only works if a jabber server specified in

the recipient JID is correct but the user is not registered.

The two specific cases that I am trying to detect are:

  1. when a message is sent to an invalid JID. An example is a@b.com, where there is no user ‘‘a’’ registered at ‘‘b.com’’

  2. there is no jabber server running on ‘‘b.com’’.

Can this be done by creating the a listener and registering it properly? I am

very new to Smack and I would appreciate any help.

I’'m kinda new to Smack, but I think using the MessageEventNotificationListener is the common way.

See: http://www.jivesoftware.org/builds/smack/docs/latest/javadoc/org/jivesoftware/sm ackx/MessageEventNotificationListener.html

melinate

Thanks for the idea. The MessageEventNotificationListener does not appear to receive messages properly. I am wondering if this is a Jabber server configuration issue, because the test included in the the smack-dev source code for the MessageEventManager does not pass:

test $ junit org.jivesoftware.smackx.MessageEventManagerTest

.File config/test-case.xml not found. Using default config.

.File config/test-case.xml not found. Using default config.

.File config/test-case.xml not found. Using default config.

F

Time: 1.868

There was 1 failure:

  1. testRequestsAndNotifications(org.jivesoftware.smackx.MessageEventManagerTest)ju nit.framework.AssertionFailedError: Test failed due to bad results (2)[]

at org.jivesoftware.smackx.MessageEventManagerTest.testRequestsAndNotifications(Me ssageEventManagerTest.java:262)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja va:25)

FAILURES!!!

Tests run: 3, Failures: 1, Errors: 0