Search for users on Ejabberd2 using smack, fails

这一生的挚爱 提交于 2019-12-12 11:49:43

问题


Server: 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

  • I am using UserSearch classes found in the Smack library.
  • 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)

回答1:


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.. :)



来源:https://stackoverflow.com/questions/19808663/search-for-users-on-ejabberd2-using-smack-fails

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