I’‘m attempting to write some code that would automatically log a user into a XMPP server. Here is what I’‘ve figured out I have to do using Smack. Could someone take a look and let me know if I’'m doing something wrong
xmppConnection = connect(properties);
saslAuthentication = xmppConnection.getSASLAuthentication();
if (saslAuthentication.hasNonAnonymousAuthentication()){
try{
saslAuthentication.authenticate(username, password, resource);
}catch(XMPPException xmppException){
xmppConnection.close();
xmppConnection = connect(properties);
AccountMgr.createAccount(xmppConnection, properties);
}
} else {
try{
xmppConnection.login(username,password,resource);
}catch(XMPPException xmppException){
if (xmppException.getXMPPError().getCode() == 401){
AccountMgr.createAccount(xmppConnection, properties);
} else {
throw xmppException;
}
}
}
xmppConnection.close();
xmppConnection = connect(properties);
xmppConnection.login(username,password,resource);
/i
Thanks - AYAL