I am working on android chat application using ejabberd 2.1.11. For searching whether a particular user exists or not i'm using UserSearchManager
public boolean isUserExists(IrishContact ic) {
try {
UserSearchManager search = new UserSearchManager(connection);
Collection<String> services = search.getSearchServices();
if (services.isEmpty()) {
Log.v("IrishuserSearch ", "no service found");
}
Log.v("service name: ", connection.getServiceName());
Form searchForm = search.getSearchForm("vjud."
+ connection.getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", ic.getPhoneNumber());
org.jivesoftware.smackx.ReportedData data = search
.getSearchResults(answerForm,
"search." + connection.getServiceName());
if (data.getRows() != null) {
Iterator<Row> it = data.getRows();
if (it.hasNext()) {
return true;
} else
return false;
} else
return false;
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
On the basis on this answer
i'm using
Form searchForm = search.getSearchForm("vjud." + connection.getServiceName());
instead of
Form searchForm = search.getSearchForm("search."+connection.getServiceName());
the later part was giving 503 service not found exception so i changed my code and it got solved, but now the problem is I am getting IllegalArgumentException at
answerForm.setAnswer("Username", true);
I am using asmack-android-8-0.8.10.
STACK_TRACE=java.lang.IllegalArgumentException: Field not found for the specified variable name.
at org.jivesoftware.smackx.Form.setAnswer(Form.java:258)
at com.irishtalk.utilities.IrishUserSearch.isUserExists(IrishUserSearch.java:42)
at com.irishtalk.utilities.IrishContactsHelper.addContactToDefaultRoster(IrishContactsHelper.java:51)
at com.irishtalk.utilities.IrishContactsHelper.getRoster(IrishContactsHelper.java:32)
at com.irishtalk.service.IXmppAidlStub$1.run(IXmppAidlStub.java:221)
can anyone help me out why this is happening? Thanks