简体   繁体   English

使用smack在Ejabberd2上搜索用户,失败

[英]Search for users on Ejabberd2 using smack, fails

Server: ejabberd2 XMPP: smack 3.3.1 服务器:ejabberd2 XMPP:smack 3.3.1

The goal is to design a chat engine. 目标是设计聊天引擎。 The user, by entering a username should be able to find out if the entered username is registered on the server. 用户通过输入用户名应该能够确定输入的用户名是否已在服务器上注册。

The Smack Javadocs can be found here Smack Javadocs可以在这里找到

  • I am using UserSearch classes found in the Smack library. 我正在使用Smack库中的UserSearch类。
  • I can connect to the server. 我可以连接到服务器。
  • I can login using a username and password. 我可以使用用户名和密码登录。
  • I can add/sign up new users into the server. 我可以在服务器中添加/注册新用户。

I want to find if a username already exists on the server. 我想查找服务器上是否已存在用户名。 The code that I have used and its respective error that I got are given below. 我使用的代码及其得到的错误如下所示。

UserSearchManager search = new UserSearchManager(connection);
Form searchForm = search.getSearchForm("search."+connection.getServiceName());
Form answerForm = searchForm.createAnswerForm(); 
answerForm.setAnswer("Username", true);  
answerForm.setAnswer("search", name);

ReportedData data = search.getSearchResults(answerForm,"search."+connection.getServiceName());

The above code outputs the following error: 上面的代码输出以下错误:

service-unavailable(503)
at org.jivesoftware.smackx.search.UserSearch.getSearchForm(UserSearch.java:84)
at org.jivesoftware.smackx.search.UserSearchManager.getSearchForm(UserSearchManager.java:73)
at com.phanism.www.XmppConnect.searchUser(XmppConnect.java:74)
at com.phanism.www.XmppConnect.main(XmppConnect.java:97)

You have not set the username you want to search. 您尚未设置要搜索的用户名。

erSearchManager search = new UserSearchManager(connection);
Form searchForm = search.getSearchForm("search."+connection.getServiceName());
Form answerForm = searchForm.createAnswerForm(); 
answerForm.setAnswer("Username", true);  
answerForm.setAnswer("search", name);//Here username must be added name replace by "amith"

Then it will work.. :) 然后它会工作.. :)

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

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