(a)Smack returns "service-unavailable (503)" error at login()
I'm trying to implement a simple jabber messenger on Android using asmack library. Here's the code:
public boolean login()
{
if (connection != null && connection.isConnected())
{
Log.i("XMPP", connection.getHost());
try
{
connection.login(USERNAME, PASSWORD);
}
catch (XMPPException e)
{
e.printStackTrace();
return false;
}
return true;
}
return false;
}
Exception I get after connection.login() (connection looks fine):
service-unavailable(503)
at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:77)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:239)
at org.jivesoftware.smack.Connection.login(Connection.java:353)
at com.someapp.networking.XMPPMessenger.login(XMPPMessenger.java:60)
at com.someapp.XMPPService.onCreate(XMPPService.java:33)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2780)
at android.app.ActivityThread.access$3200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1917)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.Zyg开发者_开发百科oteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
What could be the mistake?
Asmack is able to establish a new connection to the server, but it falls into Non-SASL mode for some reason ( The call of NonSASLAuthentication.authenticate(NonSASLAuthentication.java:77)
).
I think that's what the server is trying to tell you with the "service-unavailable(503)" response, is that it does not support Non-SASL authentication.
Try to debug why smack does not try SASL authentication.
Note: The lines in the smack source viewer are a bit off because off different versions and the patches from asmack.
It's working finally for me by this way :
ConnectionConfiguration connConfig = new ConnectionConfiguration(host,port,host);
connection = new XMPPConnection(connConfig);
connConfig.setSASLAuthenticationEnabled(true);
connection.connect();
connection.login(userID, password);
I have used Android using Asmack
library which I have downloaded from below URL:
https://code.google.com/p/asmack/downloads/detail?name=asmack-2010.05.07.jar
Be careful about the userID.
Instead of using
connection.login("username@ejabberdServerIP",password)
it's work for me only if I use connection.login("username",password);
Good luck...
精彩评论