android - Remote-server-error(502) when there is no network connection -
android - Remote-server-error(502) when there is no network connection -
this how found connection between xmpp client , server , log in background service:
public class messageservice extends service { private string tag = "messageservice"; private xmppconnection connection; private final ibinder mbinder = new mybinder(); @override public ibinder onbind(intent arg0) { // todo auto-generated method stub homecoming mbinder; } public int onstartcommand(intent intent, int flags, int startid) { log.d(tag, "started"); new connect().execute(""); homecoming start_sticky; } private class connect extends asynctask<string, void, string> { @override protected string doinbackground(string... params) { connectionconfiguration connectionconfiguration = new connectionconfiguration( settingsdm.ip_address, settingsdm.port); xmppconnection connection = new xmppconnection( connectionconfiguration); log.i(tag, "getting ready connect..."); seek { connection.connect(); log.i(tag, "connected " + connection.gethost()); } grab (xmppexception ex) { log.e(tag, "failed connect " + connection.gethost()); log.e(tag, ex.tostring()); setconnection(null); } seek { connection.login(settingsdm.test_username, settingsdm.test_password); log.i(tag, "logged in " + connection.getuser()); //setconnection(connection); } grab (xmppexception ex) { log.e(tag, "failed log in " + settingsdm.test_username); log.e(tag, ex.tostring()); setconnection(null); } homecoming null; } } }
this works okay when there network connection. when there's no network connection however, i'd expect exception caught in catch(xmppexception e)
. doesn't caught , app crashes. background service crashes , attempts restart couple of times keeps crashing.
below error log:
11-10 16:14:20.909: e/messageservice(32759): failed connect 192.168.1.4 11-10 16:14:20.910: e/messageservice(32759): xmpperror connecting 192.168.1.4:5222.: remote-server-error(502) xmpperror connecting 192.168.1.4:5222. 11-10 16:14:20.910: e/messageservice(32759): -- caused by: java.net.connectexception: failed connect /192.168.1.4 (port 5222): connect failed: enetunreach (network unreachable) 11-10 16:14:20.956: e/androidruntime(32759): fatal exception: asynctask #1 11-10 16:14:20.956: e/androidruntime(32759): java.lang.runtimeexception: error occured while executing doinbackground() 11-10 16:14:20.956: e/androidruntime(32759): @ android.os.asynctask$3.done(asynctask.java:278) 11-10 16:14:20.956: e/androidruntime(32759): @ java.util.concurrent.futuretask$sync.innersetexception(futuretask.java:273) 11-10 16:14:20.956: e/androidruntime(32759): @ java.util.concurrent.futuretask.setexception(futuretask.java:124) 11-10 16:14:20.956: e/androidruntime(32759): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:307) 11-10 16:14:20.956: e/androidruntime(32759): @ java.util.concurrent.futuretask.run(futuretask.java:137) 11-10 16:14:20.956: e/androidruntime(32759): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:208) 11-10 16:14:20.956: e/androidruntime(32759): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076) 11-10 16:14:20.956: e/androidruntime(32759): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569) 11-10 16:14:20.956: e/androidruntime(32759): @ java.lang.thread.run(thread.java:856) 11-10 16:14:20.956: e/androidruntime(32759): caused by: java.lang.illegalstateexception: not connected server. 11-10 16:14:20.956: e/androidruntime(32759): @ org.jivesoftware.smack.xmppconnection.login(xmppconnection.java:217) 11-10 16:14:20.956: e/androidruntime(32759): @ org.jivesoftware.smack.connection.login(connection.java:353) 11-10 16:14:20.956: e/androidruntime(32759): @ com.niilaryea.android.service.messageservice$connect.doinbackground(messageservice.java:77) 11-10 16:14:20.956: e/androidruntime(32759): @ com.niilaryea.android.service.messageservice$connect.doinbackground(messageservice.java:1) 11-10 16:14:20.956: e/androidruntime(32759): @ android.os.asynctask$2.call(asynctask.java:264) 11-10 16:14:20.956: e/androidruntime(32759): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305) 11-10 16:14:20.956: e/androidruntime(32759): ... 5 more 11-10 16:14:21.969: e/graphicbufferallocator(32759): fatal: can't find mmumapper module
how prevent background service , app crashing when there's no network connection available, rather maintain checking until there's active network connection available?
you have java.net.connectexception , should utilize exception instead of xmppexception
android xmpp smack asmack background-service
Comments
Post a Comment