Search code examples
xmppejabberdsmackvcf-vcard

Error loading vCard information using Smack: "EmptyResultIQ cannot be cast to org.jivesoftware.smackx.vcardtemp.packet.VCard"


I am creating an android chat application using smack 4.1.1

I could load users vcard on my local test server (Openfire).

But now on ejabberd server when i try to load the vcard, I get the following error:

07-19 11:11:26.175: E/AndroidRuntime(13849): java.lang.RuntimeException: An error occured while executing doInBackground()
07-19 11:11:26.175: E/AndroidRuntime(13849):    at android.os.AsyncTask$3.done(AsyncTask.java:300)
07-19 11:11:26.175: E/AndroidRuntime(13849):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
07-19 11:11:26.175: E/AndroidRuntime(13849):    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
07-19 11:11:26.175: E/AndroidRuntime(13849):    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
07-19 11:11:26.175: E/AndroidRuntime(13849):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
07-19 11:11:26.175: E/AndroidRuntime(13849):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-19 11:11:26.175: E/AndroidRuntime(13849):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-19 11:11:26.175: E/AndroidRuntime(13849):    at java.lang.Thread.run(Thread.java:818)
07-19 11:11:26.175: E/AndroidRuntime(13849): Caused by: java.lang.ClassCastException: org.jivesoftware.smack.packet.EmptyResultIQ cannot be cast to org.jivesoftware.smackx.vcardtemp.packet.VCard
07-19 11:11:26.175: E/AndroidRuntime(13849):    at org.jivesoftware.smackx.vcardtemp.VCardManager.loadVCard(VCardManager.java:125)
07-19 11:11:26.175: E/AndroidRuntime(13849):    at service.ChatService$Connect.doInBackground(ChatService.java:331)
07-19 11:11:26.175: E/AndroidRuntime(13849):    at service.ChatService$Connect.doInBackground(ChatService.java:1)
07-19 11:11:26.175: E/AndroidRuntime(13849):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
07-19 11:11:26.175: E/AndroidRuntime(13849):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)

This line:

org.jivesoftware.smack.packet.EmptyResultIQ cannot be cast to org.jivesoftware.smackx.vcardtemp.packet.VCard

this is how i get vcard:

VCard info;
    for (RosterEntry entry : entries) {
        Presence entryPresence = roster.getPresence(entry.getUser());
        Presence.Type type = entryPresence.getType();
        Log.d(entry.getUser(), "bar jid");
        if(entry.getUser().lastIndexOf("@") == -1)
            continue;
        String username = entry.getUser().substring(0,
                entry.getUser().lastIndexOf("@"));      
        try {
            info = VCardManager.getInstanceFor(connection).loadVCard(entry.getUser());
            if(info.getMiddleName() != null)
            {

                uh.updateAvatar(username, info.getMiddleName());
            }
        } catch (NoResponseException | XMPPErrorException
                | NotConnectedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        }
    }

the logcat mentions this line as the source of problem:

        info = VCardManager.getInstanceFor(connection).loadVCard(entry.getUser());

This is what i get exactly before the crash:

07-19 12:38:06.030: D/SMACK(16307): SENT (0): <stream:stream xmlns='jabber:client' to='myserver.com' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>
07-19 12:38:06.665: D/SMACK(16307): RECV (0): <?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='184908447' from='myserver.com' version='1.0' xml:lang='en'><stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/><compression xmlns='http://jabber.org/features/compress'><method>zlib</method></compression><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism><mechanism>DIGEST-MD5</mechanism><mechanism>SCRAM-SHA-1</mechanism></mechanisms><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.process-one.net/en/ejabberd/' ver='wwrSvLFOLzC92POh074kJuEqYxE='/><register xmlns='http://jabber.org/features/iq-register'/></stream:features>
07-19 12:38:06.665: D/SMACK(16307): SENT (0): <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AG1laGRpMTIzADEyMzQ=</auth>
07-19 12:38:07.390: D/SMACK(16307): RECV (0): <success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
07-19 12:38:07.390: D/SMACK(16307): SENT (0): <stream:stream xmlns='jabber:client' to='myserver.com' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' id='184908447' xml:lang='en'>
07-19 12:38:08.005: D/SMACK(16307): RECV (0): <?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='1619836774' from='myserver.com' version='1.0' xml:lang='en'><stream:features><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.process-one.net/en/ejabberd/' ver='wwrSvLFOLzC92POh074kJuEqYxE='/><register xmlns='http://jabber.org/features/iq-register'/></stream:features>
07-19 12:38:08.005: D/SMACK(16307): SENT (0): <iq id='VSflA-4' type='set'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>roo</resource></bind></iq>
07-19 12:38:08.725: D/SMACK(16307): RECV (0): <iq id='VSflA-4' type='result'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><jid>[email protected]/roo</jid></bind></iq>
07-19 12:38:08.725: D/SMACK(16307): SENT (0): <iq id='VSflA-6' type='set'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>
07-19 12:38:09.245: D/SMACK(16307): RECV (0): <iq type='result' id='VSflA-6'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>
07-19 12:38:09.245: D/SMACK(16307): User logged (0): [email protected]:5222/roo
07-19 12:38:09.245: D/received from authenticated service(16307): connected: true
07-19 12:38:09.245: D/SMACK(16307): SENT (0): <iq id='VSflA-8' type='get'><query xmlns='jabber:iq:roster'></query></iq>
07-19 12:38:09.245: D/SMACK(16307): SENT (0): <iq id='VSflA-9' type='get'><vCard xmlns='vcard-temp'/></iq>
07-19 12:38:09.860: D/SMACK(16307): RECV (0): <iq from='[email protected]' to='[email protected]/roo' id='VSflA-9' type='result'><vCard xmlns='vcard-temp'><N><FAMILY/><GIVEN>gigi</GIVEN><MIDDLE>http://31.170.166.15/avatars/mehdi123.jpg</MIDDLE></N><FN>gigi http://31.170.166.15/avatars/mehdi123.jpg </FN><NICKNAME>gigi </NICKNAME><EMAIL><HOME/><INTERNET/><PREF/><USERID>iyi</USERID></EMAIL><TEL><HOME/><CELL/><NUMBER>hfu</NUMBER></TEL><ADR><HOME/><CTRY/><LOCALITY/><REGION/></ADR></vCard></iq><iq from='[email protected]' to='[email protected]/roo' id='VSflA-8' type='result'><query xmlns='jabber:iq:roster'><item subscription='from' jid='[email protected]'/></query></iq>
07-19 12:38:09.860: D/http://31.170.166.15/avatars/mehdi123.jpg(16307): http://31.170.166.15/avatars/mehdi123.jpg from chatservice
07-19 12:38:09.865: D/SMACK(16307): XMPPConnection authenticated (0)
07-19 12:38:09.865: I/XMPPChatDemoActivity(16307): connected & logged in
07-19 12:38:09.865: D/SMACK(16307): SENT (0): <presence id='VSflA-12'><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='os2Kusj3WEOivn5n4iFr/ZEO8ls='/></presence>
07-19 12:38:09.875: D/SMACK(16307): SENT (0): <presence to='[email protected]/mehdi123' id='VSflA-13'><x xmlns='http://jabber.org/protocol/muc'><password></password><history maxstanzas='0'/></x><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='os2Kusj3WEOivn5n4iFr/ZEO8ls='/></presence>
07-19 12:38:10.575: D/SMACK(16307): RECV (0): <presence from='[email protected]/roo' to='[email protected]/roo' xml:lang='en' id='VSflA-12'><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='os2Kusj3WEOivn5n4iFr/ZEO8ls='/></presence>
07-19 12:38:11.310: D/SMACK(16307): RECV (0): <message from='[email protected]' to='[email protected]/roo' type='groupchat'><body>This room is not anonymous</body><x xmlns='http://jabber.org/protocol/muc#user'><status code='100'/></x></message><message from='[email protected]' to='[email protected]/roo' type='groupchat'><body>This room is filtered by external service</body><x xmlns='http://jabber.org/protocol/muc#user'><status code='100'/></x></message><presence from='[email protected]/boy' to='[email protected]/roo' xml:lang='En' ver='2.3.1'><show>dnd</show><status>iN niZ BoGZaRaD ツ</status><c xmlns='http://jabber.org/protocol/caps' node='http://kopete.kde.org/jabber/capshttp://kopete.kde.org/jabber/caps' ver='xzah7XZzG6oCHvM2nNnG2hHNOBM=' hash='sha-1'/><x xmlns='http://jabber.org/protocol/muc#user'><item jid='[email protected]/SaM' affiliation='member' role='participant'/></x></presence><presence from='[email protected]/jafar123' to='[email protected]/roo' id='BYLNs-85'><x xmlns='http://jabber.org/protocol/muc#user'><item jid='[email protected]/Spark 2.6.3' affiliation='admin' role='moderator'/></x></presence>
07-19 12:38:11.895: D/SMACK(16307): RECV (0): <presence from='[email protected]/mehdi123' to='[email protected]/roo' xml:lang='en' id='VSflA-13'><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='os2Kusj3WEOivn5n4iFr/ZEO8ls='/><x xmlns='http://jabber.org/protocol/muc#user'><item jid='[email protected]/roo' affiliation='admin' role='moderator'/><status code='110'/><status code='100'/></x></presence><message from='[email protected]' to='[email protected]/roo' type='groupchat'><subject>be dalile barkhi masael va tamirat server named off mishe ta zamani ke barname  android kamel nashe on nemikonam ,  momkene yemah domah ya chand mah zaman bebare</subject><body>mahan has set the subject to: be dalile barkhi masael va tamirat server named off mishe ta zamani ke barname  android kamel nashe on nemikonam ,  momkene yemah domah ya chand mah zaman bebare</body></message>
07-19 12:38:11.895: D/SMACK(16307): SENT (0): <presence to='[email protected]/mehdi123' id='VSflA-21'><x xmlns='http://jabber.org/protocol/muc'><password></password><history maxstanzas='0'/></x><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='os2Kusj3WEOivn5n4iFr/ZEO8ls='/></presence>
07-19 12:38:14.790: D/SMACK(16307): RECV (0): <presence from='[email protected]/mehdi123' to='[email protected]/roo' xml:lang='en' id='VSflA-21'><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='os2Kusj3WEOivn5n4iFr/ZEO8ls='/><x xmlns='http://jabber.org/protocol/muc#user'><item jid='[email protected]/roo' affiliation='owner' role='moderator'/><status code='110'/><status code='201'/></x></presence>
07-19 12:38:14.790: D/[email protected](16307): bar jid
07-19 12:38:14.790: D/SMACK(16307): SENT (0): <presence id='VSflA-23'><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='os2Kusj3WEOivn5n4iFr/ZEO8ls='/></presence>
07-19 12:38:14.795: D/SMACK(16307): SENT (0): <iq to='[email protected]' id='VSflA-26' type='get'><vCard xmlns='vcard-temp'/></iq>
07-19 12:38:15.435: D/SMACK(16307): RECV (0): <presence from='[email protected]/roo' to='[email protected]/roo' xml:lang='en' id='VSflA-23'><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='os2Kusj3WEOivn5n4iFr/ZEO8ls='/></presence>
07-19 12:38:16.040: D/SMACK(16307): RECV (0): <iq from='[email protected]' to='[email protected]/roo' id='VSflA-26' type='result'/>

Solution

  • SENT: <iq to='[email protected]' id='VSflA-26' type='get'><vCard xmlns='vcard-temp'/></iq>
    RECV: <iq from='[email protected]' to='[email protected]/roo' id='VSflA-26' type='result'/>
    

    This appears to be a bug in the server implementation. XEP-54 § 3.2 makes it clear that the result to a vcard get must either be

    1. A valid vcard result IQ
    2. An error IQ

    If no vCard exists or the user does not exist, the server MUST return a stanza error...

    The server here does return an empty IQ result.

    I suggest reporting this to the server developers.