Smack's FileTransferManager.createOutgoingFileTransfer only accepts full JIDs. How can I determine the full JID of a user in Smack?

旧街凉风 提交于 2019-12-10 10:13:07

问题


After hours of debugging and trying to find out why the file transfer was not working using aSmack, while normal messaging was, I finally managed to pin it down to this.

The Openfire server is sending the Rosters' JID missing the / at the end when I follow the method given in the Smack documentation to get a user's Roster list.

Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry r : entries) {
    Log.v("Gabriel","Receiving: " + r.getUser());
}      

For example if I receive a message from the user gabriel, I get the "From" as:

gabriel@dragonov/Smack

But the r.getUser() returns to the user as

gabriel@dragonov

Even

connection.getRoster().getPresence(contactName).getFrom()

is returning is as "gabriel@dragonov".

This is causing the File transfer to fail, but oddly not the regular messaging. However when I manually add the /Smack at the end of

 OutgoingFileTransfer transferr = manager.createOutgoingFileTransfer(contactJID+"/Smack");

it works.

My question is, how can I receive the full JID with the resource part included or configure the file transfer so that it doesn't fail when using a bare JID?


Edit:

I have tried the following method:

 Log.v("Gabriel", entries.size() + " buddy(ies):");
    for (RosterEntry r : entries) {
        Log.v("Pat","adding: " + r.getType() + "  " + r.getName());
        contacts.add(r.getUser());
    }      

    for (String contact : contacts){
        Iterator<org.jivesoftware.smack.packet.Presence> presences = connection.getRoster().getPresences(contact);
        Log.v("Gabriel", contact+" has: ");
        while(presences.hasNext()){
            Log.v("Gabriel",presences.next().getFrom());
        }           
    }

But I am still getting the bare ID.

The output: gabriel@dragonov has: gabriel@dragonov


回答1:


Use Iterator<Presence> Roster.getPresences(String user) to get the presence information from all known resources of a user. For this Presence instances getFrom() should return a full JID which you can use in FileTransferManager.createOutgoingFileTransfer().

I have created SMACK-430, regarding the use of a full JID in createOutgoingFileTranfer(). It really should throw an exception so that smack users don't have to debug hours to find the reason (although it's stated in the method javadoc). SMACK-430 also explains why FileTransferManager needs a full JID and can not be used with a bare JID.



来源:https://stackoverflow.com/questions/15518440/smacks-filetransfermanager-createoutgoingfiletransfer-only-accepts-full-jids-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!