I am using asmack library to develop a whatsapp style chat application.I am able to connect and create accounts.I wanted to implement the "Add chat" functionality of whatsapp,where we select friends from a list of phone numbers which are registered.For this,i wanted to do a usersearch on my server for those numbers that i had in my phone,and then add them to my roster once i clicked them. I can login and register users on my ejabberd 2.11 server easily. But i cannot retrieve the list of already registered users from it. I used this code for searching:
UserSearchManager search = new UserSearchManager(conn);
try {
Form searchForm = search.getSearchForm("search."+conn.getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username",true);
answerForm.setAnswer("search",user);
System.out.println("search form");
ReportedData data = search.getSearchResults(answerForm,"search."+conn.getServiceName());
This worked PERFECTLY on my OPENFIRE server..but for my ejabberd2 server..i had to modify it to:
UserSearchManager search = new UserSearchManager(conn);
try {
Form searchForm = search.getSearchForm("vjud."+conn.getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("user",username);//passed my jid in username i.e example@mydomain
System.out.println("search form");
ReportedData data = search.getSearchResults(answerForm,"vjud."+conn.getServiceName());
if(!data.getRows().isEmpty())
{
List<Row> hue = data.getRows();Iterator<Row> it=hue.iterator();
while(it.hasNext())
{
Row row = it.next();
List<String> hue2 = row.getValues("jid");Iterator<String> iterator=hue2.iterator();
if(iterator.hasNext())
{
String value = iterator.next().toString();
System.out.println(value);
}
}
}
else{
System.out.println("its null");
}
The above code always returned a null form.So what arguments should i pass in answerForm.setAnswer(); for ejabberd? Please see that "answerForm.setAnswer("Username",true); answerForm.setAnswer("search",user);" worked for openfire.. but ejabberd doesnt have a boolean type Username field..so what should i pass?