简体   繁体   English

使用 smack 4.2.2 从 Openfire 服务器获取所有用户

[英]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.好吧,我正在尝试使用 Smack 从 Openfire 服务器获取所有用户,不幸的是我不知道如何 - 我使用的是 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). 您无法通过XEP-0055: Jabber Search吸引所有用户,只能与过滤器一起使用,以确保用户没有该过滤器(如特殊字符)。 Only way I know is to use Rest API Plugin of openfire. 我知道的唯一方法是使用Rest API Plugin 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. 也许您正在尝试在没有本地jid的情况下进行连接。 Please check this explanation of XMPP address formats: 请检查以下有关XMPP地址格式的说明:

https://xmpp.org/rfcs/rfc6122.html#addressing-localpart 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()); 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:在您的 openfire 中,转到 Plugins 并选择 available-plugins > 然后选择 rest Api > 然后您可以使用以下 url 来获取组中的所有用户:

http://localhost:9090/plugins/restapi/v1/users 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注意:您可以在以下链接中找到所有 Rest EndPoint: https : //www.igniterealtime.org/projects/openfire/plugins/1.2.1/restAPI/readme.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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