Testing if a user exists and if not create (register) on the fly

Hello all,

I have a need allow a user to register on the fly. Currently here is what happens:

  1. JoeSchmoe tries to login (create a xmpp connection).

  2. JoeSchmoe does not exist (not a registered user).

  3. Throws a SASL authentication failed error

Now I need to allow JoeSchmoe to create (register) an account if he does not exist.

Currently I am attempting to do this in the catch block.

public XMPPConnection getConnx(String user, String pwd) throws XMPPException { XMPPConnection connx = new XMPPConnection(HOST,PORT); try {           //connx.DEBUG_ENABLED = true; PacketTypeFilter filter = new PacketTypeFilter(Message.class); connx.addPacketListener(messageListener,filter); connx.login(user,pwd); System.out.println(user+" IS CONNECTED via getConnx method"); } catch(XMPPException e) { createUserAccount(user,pwd); try { Thread.sleep(3000); } catch(InterruptedException ie){ie.printStackTrace();} getConnx(user,pwd); System.out.println("USER DOES NOT EXIST"); e.printStackTrace(); connx.close(); }

Is there a way to test if the user exists prior to calling the connection.login() method?


BTW, any page that I access under jivesoftware --> Smack take in excess of a few minutes to load. Does anyone else have this problem?

As far as I can tell there is no method that lets you query if a user already has an account. Probably because it isn’'t specified in the jabber specification.

In my code I do what you do – call login and if I get a XMPPException assume it is because the user doesn’'t have an account and create them one. Generally it is considered a bad practice to depend on recieving an exception to perform some important activity (like creating an account), but in this case it seems to be the only option…in practice it has worked out really well doing it this way.