java - How to use UserSearchManager to check user has registered or not in xmpp? -


i have started develop chat application. needed check user has registered or not in xmpp server.so when user trying register,i want check user has registered or not in xmpp server. after xmpp server connected successfully,tried search number using usersearchmanager.but getting error

java.lang.illegalargumentexception: must have local(user) jid set.either didn 't configure 1 or not connected @ least once  @ org.jivesoftware.smack.filter.iqreplyfilter. < init > (iqreplyfilter.java: 94)  @ org.jivesoftware.smack.abstractxmppconnection.createpacketcollectorandsend(abstractxmppconnection.java: 699)  @ org.jivesoftware.smackx.search.usersearch.getsearchform(usersearch.java: 73)  @ org.jivesoftware.smackx.search.usersearchmanager.getsearchform(usersearchmanager.java: 71)  @ com.techno.samplechat.myxmpp.searchusers(myxmpp.java: 335)  @ com.techno.samplechat.myxmpp$xmppconnectionlistener.connected(myxmpp.java: 284)  @ org.jivesoftware.smack.abstractxmppconnection.callconnectionconnectedlistener(abstractxmppconnection.java: 1162)  @ org.jivesoftware.smack.tcp.xmpptcpconnection.connectinternal(xmpptcpconnection.java: 850)  @ org.jivesoftware.smack.abstractxmppconnection.connect(abstractxmppconnection.java: 365)  @ com.techno.samplechat.myxmpp$1.run(myxmpp.java: 117)  @ java.lang.thread.run(thread.java: 818) 

code:

private void createaccount() {       org.jivesoftware.smackx.iqregister.accountmanager = org.jivesoftware.smackx.iqregister.accountmanager         .getinstance(connection);     am.sensitiveoperationoverinsecureconnection(true);     map < string, string > attributes = new hashmap < string, string > ();      attributes.put("username", loginuser);     attributes.put("email", "manikandan.s@technoduce.com");     attributes.put("password", passworduser);     attributes.put("name", username);     try {         if (am.supportsaccountcreation()) {               am.createaccount(                 loginuser,                 passworduser,                 attributes);              login();              }     } catch (smackexception.noresponseexception e) {         e.printstacktrace();     } catch (xmppexception.xmpperrorexception e) {         e.printstacktrace();     } catch (smackexception.notconnectedexception e) {         e.printstacktrace();     }   }  private void login() {     try {         connection.login(loginuser, passworduser);         log.i("login", "yey! we're connected xmpp server!");      } catch (xmppexception e) {         e.printstacktrace();     } catch (smackexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     }     chatmanager.getinstancefor(connection).addchatlistener(this);  }  @ override public void chatcreated(chat chat, boolean createdlocally) {     log.i("service", "chatcreated()");     system.out.println("+chatlist++" + chat.getparticipant());     chat.addmessagelistener(this); }  @ override public void entriesadded(collection < string > addresses) {  }  @ override public void entriesupdated(collection < string > addresses) {  }  @ override public void entriesdeleted(collection < string > addresses) {  }  @ override public void presencechanged(presence presence) {  }  @ override public void processmessage(chat chat, message message) {      if (message.gettype() == message.type.chat || message.gettype() == message.type.normal) {         if (message.getbody() != null) {             // toast.maketext(this,message.getfrom() + " : " + message.getbody(),toast.length_long).show();             system.out.println("++from++" + message.getfrom() + "++body++" + message.getbody());          }     }  }  @ override public void pingfailed() {  }  private class xmppconnectionlistener implements connectionlistener {      @     override     public void connected(xmppconnection connection) {         log.e("success", "connected");           try {             searchusers(loginuser);         } catch (smackexception.notconnectedexception e) {             e.printstacktrace();         } catch (xmppexception.xmpperrorexception e) {             e.printstacktrace();         } catch (smackexception.noresponseexception e) {             e.printstacktrace();         }         //  createaccount();        }         @     override     public void authenticated(xmppconnection connection, boolean resumed) {      }      @     override     public void connectionclosed() {      }      @     override     public void connectionclosedonerror(exception e) {         system.out.println("+_" + e.tostring());     }      @     override     public void reconnectionsuccessful() {      }      @     override     public void reconnectingin(int seconds) {      }      @     override     public void reconnectionfailed(exception e) {      } } public void searchusers(string username) throws smackexception.notconnectedexception, xmppexception.xmpperrorexception, smackexception.noresponseexception {     usersearchmanager search = new usersearchmanager(connection);     form searchform = search         .getsearchform("search." + connection.getservicename());      form answerform = searchform.createanswerform();     answerform.setanswer("username", true);     answerform.setanswer("search", username);     reporteddata data = search         .getsearchresults(answerform, "search." + connection.getservicename());      if (data.getrows() != null) {         (reporteddata.row row: data.getrows()) {             (string value: row.getvalues("jid")) {                 log.i("iteartor values......", " " + value);             }         }      } else {         createaccount();     } } 

string looking must jid, not username:

you need like:

user1@myserver 

and not

user1 

then, it's quite useless in usecase check jid.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -