IllegalArgumentException on load VCard with VCardManager Smack Android

Hi there,

I got a problem with loading a VCard from another user in smack for android. For example I am loading this VCard like this:

vcard = manager.loadVCard("example@anotherxmpp.com");

This throws the following error:

Caused by: java.lang.IllegalArgumentException: Must have a local (user) JID set. Either you didn’t configure one or you where not connected at least once

at org.jivesoftware.smack.filter.IQReplyFilter.(IQReplyFilter.java:94)

at org.jivesoftware.smack.AbstractXMPPConnection.createPacketCollectorAndSend(Abst ractXMPPConnection.java:695)

at org.jivesoftware.smackx.vcardtemp.VCardManager.loadVCard(VCardManager.java:125)

at de.opiatefuchs.connection.Connection.loadVCard(Connection.java:1223)

at de.opiatefuchs.connection.Connection$5.doInBackground(Connection.java:1336)

at de.opiatefuchs.connection.Connection$5.doInBackground(Connection.java:1331)

at android.os.AsyncTask$2.call(AsyncTask.java:292)

at java.util.concurrent.FutureTask.run(FutureTask.java:237)

at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)

at java.lang.Thread.run(Thread.java:831)

I am definetely connected, that´s not the problem. At the old VCard a vcard was able to be loaded with vcard.load(connection,userJabberId); How should this be done via the VCardManager? Loading through VCard instead of VCardManager is deprecated, so how should I do this?

Which version of Smack is this?

I am definetely connected, that´s not the problem.
It should say there ‘authenticated’. If you look at the code you’ll find that it throws because the local xmpp address is not set, i.e. connection.getUser() returns null. Are you sure that you have login successfully? Otherwise have a look using a debugger.

I am using Smack 4.1.6, and yes I am 100% sure my connection is valid, sending and receiving messages working without problems. Also loading my own VCard is working like a charm. It´s only about loading a vcard from another user. And if I use vcard.load(connection,jid); it also works, but it´s the deprecated method. But from the source code of IQReplyFilter, I know there must be a problem that is server dependant:

    • For a discussion of the issues, see the thread "Spoofing of iq ids and
  •  * misbehaving servers" from 2014-01 on the jdev@jabber.org mailing list
    
  •  * and following discussion in February and March.
    

I followed the discussion and it seems that this happens on some servers, but I am not enough integrated in building xmpp servers on a
server side. So, my thought is, why it´s working with the old deprecated method vcard.load(connection,jid), but not with the current
method from vcardManager? I don´t want to get problems if some day the depracted method is not included anymore.

i had same problem.

connect method

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()

.setSocketFactory(SocketFactory.getDefault())

.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)

.setServiceName(Server.Server_IP)

.setHost(Server.Server_IP)

.setPort(Server.Server_Port)

.setConnectTimeout(timeout)

.setCompressionEnabled(false).build();

connection = new XMPPTCPConnection(config);

connection.connect();

login method

connection.login(userName, password);

solution was join connect and login methods like that

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration

.builder()

.setSocketFactory(SocketFactory.getDefault())

.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)

.setServiceName(Server.Server_IP)

.setHost(Server.Server_IP)

.setPort(Server.Server_Port)

.setConnectTimeout(timeout)

.setUsernameAndPassword(username,password)

.setCompressionEnabled(false).build();

connection = new XMPPTCPConnection(config);

connection.connect();

connection.login();

Thanks for reply…but do You where able to send and receive messages with that old connect method?

If you look at the code you will find that the deprecated method just maps to the new one https://github.com/igniterealtime/Smack/blob/4.1/smack-extensions/src/main/java/ org/jivesoftware/smackx/vcardtemp/packet…

Unbelievable…You are right yasin. I tried it in Your way and it worked. That leads me that there must be an issue at the interaction between connection and vcardmanager in the source code. Many thanks…

I still wonder why AbstractXMPPConnection.user, which is set by bindResourceAndEstablishSession, is null. Could you gather a trace of the XMPP connection from login to the exception when this happens (SmackConfiguration.DEBUG = true)?

Good Morning Flow, I will give it a try and will report, but I need a little bit time for that.