简体   繁体   中英

Getting all users from Openfire server using smack 4.2.2

Well, I'm trying to get all users from Openfire server using Smack, unfortunately I don't know how - I'm using Smack 4.2.2.

UserSearchManager usm= new UserSearchManager(connection);
DomainBareJid domainJid = 
JidCreate.domainBareFrom(connection.getServiceName());
Form searchForm = usm.getSearchForm(domainJid);
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", "*");
ReportedData data = usm.getSearchResults(answerForm, domainJid);
if (data.getRows() != null) {
  for (ReportedData.Row row: data.getRows()) {
     for (String jid:row.getValues("jid")) {
        System.out.println(jid);
     }
  }
}

This code doesn't work because of:

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

You can't get all users through XEP-0055: Jabber Search , just can be used with a filter you sure that the users don't have it (like a special character). Only way I know is to use Rest API Plugin of openfire. You can read more about this plugin from the link. Good luck.

Error is obvious. Either you did not connect at least once (or got disconnected and did not reconnect) or your username is wrong.

Maybe you are trying to connect without local jid. Please check this explanation of XMPP address formats:

https://xmpp.org/rfcs/rfc6122.html#addressing-localpart

hope you have solved the problem. I got my code working with this little change

DomainBareJid domainJid = JidCreate.domainBareFrom("search." + connection.getServiceName());

in your openfire go to Plugins and select available-plugins > then choose rest Api > then you can use following url to Get All users in Group:

http://localhost:9090/plugins/restapi/v1/users

Note: All Rest EndPoints you can find in following link: https://www.igniterealtime.org/projects/openfire/plugins/1.2.1/restAPI/readme.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM