0
votes

I am facing the issue to retrieve offline message in android apps using smack api from XMPP Mongoose server. As per the code flow Try to retrive offline message when user become login in xmpp mongoose server before sending available presence to mongoose server.

Tried with two different way to retrieve offline message still not able to find working solution for the same. Both method which i tried those all things are explain below with detail.

Below Api we are using for the xmpp connection and all other extension :

// Smack (XMPP Client Library)


compile 'org.igniterealtime.smack:smack-android:4.1.6'


compile 'org.igniterealtime.smack:smack-tcp:4.1.6'

compile 'org.igniterealtime.smack:smack-im:4.1.6'


compile 'org.igniterealtime.smack:smack-android-extensions:4.1.6'

Tried retrive offline message Using offlineMessageManager

Below is code which I tried to retrieve offline message after login and before send available presence to server

try {


Boolean isFelxibleRetrievalSupport = offlineMessageManager.supportsFlexibleRetrieval();


Iterator i = (Iterator) offlineMessageManager.getMessages();


while (i.hasNext())

{
 Message msg = i.next();
 System.out.println("Got text [" + msg.getBody() + "] from [" + msg.getFrom() + "]");


} catch (XMPPException e)

{
 System.out.println("Error Offline Message.");
 e.printStackTrace();
 }

catch (SmackException.NotConnectedException e)

{
 System.out.println("Error Offline Message. No connection");
 e.printStackTrace(); 
}

catch (SmackException.NoResponseException e)

{
 System.out.println("Error Offline Message. No Reponse");
 e.printStackTrace();
 }

Issue case 1:

Below is exception detail which generate when above code execute

I got Exception when execute below line of code.

Iterator i = (Iterator) offlineMessageManager.getMessages();


Below is exception description which Generate when above line execute

org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: service-unavailable - cancel

Issue Case 2:

If checking is Flexible offline message supported from android code using smack from xmmp mongoose server so i got false value. Below is code which i used for testing.

Boolean isFelxibleRetrievalSupport = offlineMessageManager.supportsFlexibleRetrieval();

Issue Case 3:

When I try to retrieve supported features using below method using smack code like below.

ServiceDiscoveryManager manager = ServiceDiscoveryManager

.getInstanceFor(connection);

List AllFetures = manager.getFeatures();

Below is features list which i retrived:

http://jabber.org/protocol/bytestreams,

jabber:iq:privacy, urn:xmpp:ping,

http://jabber.org/protocol/commands,

jabber:iq:version,

jabber:iq:last,

http://jabber.org/protocol/xdata-validate,

http://jabber.org/protocol/xhtml-im,

vcard-temp,

http://jabber.org/protocol/chatstates,

urn:xmpp:receipts, urn:xmpp:time,

http://jabber.org/protocol/xdata-layout,

http://jabber.org/protocol/muc,

http://jabber.org/protocol/disco#items,

http://jabber.org/protocol/disco#info,

http://jabber.org/protocol/caps,

jabber:x:data

Tried to retreive offline message Using package listener from XMPP MongooseIM

below is code which i tried using package listener from smack api 4.1.6.

private static final StanzaFilter MESSAGE_PACKET_FILTER= new OrFilter(StanzaTypeFilter.MESSAGE);

configuration = XMPPTCPConnectionConfiguration.builder()

            .setServiceName(SERVICE_NAME)

            .setHost(KDevelopmentXMPPServer)

            .setPort(PORT)

            .setSendPresence(false)

            .build();

// Create Connection object of xmpp connection with configured detail

connection = new XMPPTCPConnection(configuration);

connection.addAsyncStanzaListener(new StanzaListener() {

            @Override

            public void processPacket(Stanza packet) throws SmackException.NotConnectedException {


                Log.d("CheckPacket", "OfflineMEssage");


                Message message = (Message) packet;

                if (message != null) {

                    if (message.getBody() != null) {



                        Log.i("XMPPClient", "Got text [" + message.getBody()

                                + "] from [" + message.getFrom() + "]");



                    }

                }



            }

        }, MESSAGE_PACKET_FILTER);

connection.login(user, password);

Thanks In Advance, Please anybody help me for best working solution for my critical issue.

2
Are you sure offline message support (module mod_offline) is enabled in your instance of MongooseIM? It doesn't seem so.erszcz
Hi erszcz, Yes it is enable. In our ios apps that is working. but issue is in only android using smack api.Kavita Mevada
It would help you to check the traffic at the XML XMPP level. You would see what you send exactly to your server and what the server reply.Mickaël Rémond

2 Answers

0
votes

The issue is in trying to fetch offline messages before sending the initial presence. XEP-0160 states:

When the recipient next sends non-negative available presence to the server, the server delivers the message to the resource that has sent that presence. [...]

MongooseIM works with accordance to this recommendation.

You already pointed out what is signaled by isFlexibleRetrievalSupport - the server does not support flexible offline message retrieval.

0
votes

I know I am writing this too late, but if someone like me who is hunting for same query as in "how to save and get archive messages in android app" can refer this answer :

Note : this is implemented in the lastest version

Requrirements :

  1. lastest openfire as of now 4.1.4
  2. install Archives plugin in openfire
    MamManager mamManager = MamManager.getInstanceFor(connection);
    boolean isSupported = mamManager.isSupportedByServer();
    if (isSupported) {
        MamManager.MamQueryResult mamQueryResult = mamManager.queryArchive(500);
        List<Forwarded> forwardedMessages = mamQueryResult.forwardedMessages;
        Forwarded d = forwardedMessages.get(0);
    }

Please Refer : Documention for MamManager Class