android - java.net.SocketException: socket failed: EACCES (Permission denied) MongoDB connection -
i trying setup direct connection mongodb within android application, can't figure out why error:
caused by: android.system.errnoexception: socket failed: eacces (permission denied)
my code: dbconnect()
import com.mongodb.db; import com.mongodb.mongoclient; import com.mongodb.mongocredential; import com.mongodb.serveraddress; import java.util.arrays; public class dbconnect { public static db mongoconnect(){ mongocredential credential = mongocredential.createcredential("user", "database", "password".tochararray()); mongoclient mongoclient = new mongoclient(new serveraddress(), arrays.aslist(credential)); //mongoclient mongoclient = null; try { mongoclient = new mongoclient("xxx.xxx.xxx.xxx", 27017); } catch (exception e) { e.printstacktrace(); } db database = mongoclient.getdb("rotterdamhaven"); return database; } }
dbcollections()
import com.mongodb.db; import com.mongodb.dbcollection; public class dbcollections { public static dbcollection connecttomongocollection(string collectionname){ db database = dbconnect.mongoconnect(); dbcollection mongocollection = database.getcollection(collectionname); return mongocollection; } }
my manifest file:
<application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.access_wifi_state" /> </application>
mainactivity file
package com.example.bebo.connection; import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.view.menu; import android.view.menuitem; public class mainactivity extends actionbaractivity { dbcollection collection = dbcollections.connecttomongocollection("bolderbedrijfsnaam"); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } }
i added mongo-java-driver-3.0.0.jar file project. please help. need simple connection.
edit 1: changed manifest file , put permissions outside . getting error:
caused by: java.net.connectexception: failed connect /127.0.0.1 (port 27017) after 20000ms: isconnected failed: econnrefused (connection refused) 05-11 22:50:45.493 3465-3484/com.example.bebo.connection w/egl_emulation﹕ eglsurfaceattrib not implemented 05-11 22:50:45.493 3465-3484/com.example.bebo.connection w/openglrenderer﹕ failed set egl_swap_behavior on surface 0xa6ccf760, error=egl_success 05-11 22:51:05.216 3465-3482/com.example.bebo.connection i/cluster﹕ exception in monitor thread while connecting server 145.24.222.221:27017 com.mongodb.mongosocketopenexception: exception opening socket caused by: java.net.sockettimeoutexception: failed connect /145.24.222.221 (port 27017) after 20000ms
edit 2:
05-12 09:44:33.434 24339-24339/? v/zygote﹕ switching descriptor 32 /dev/null 05-12 09:44:33.434 24339-24339/? v/zygote﹕ switching descriptor 9 /dev/null 05-12 09:44:33.439 24339-24339/com.example.bebo.connection d/dalvikvm﹕ late-enabling checkjni 05-12 09:44:33.479 24339-24339/com.example.bebo.connection d/activitythread﹕ handlebindapplication:com.example.bebo.connection 05-12 09:44:33.479 24339-24339/com.example.bebo.connection d/activitythread﹕ settargetheaputilization:0.75 05-12 09:44:33.479 24339-24339/com.example.bebo.connection d/activitythread﹕ settargetheapminfree:2097152 05-12 09:44:33.524 24339-24339/com.example.bebo.connection i/dalvikvm﹕ not find method javax.management.objectname.quote, referenced method com.mongodb.management.jmxconnectionpoollistener.ensurevalidvalue 05-12 09:44:33.524 24339-24339/com.example.bebo.connection w/dalvikvm﹕ vfy: unable resolve static method 19259: ljavax/management/objectname;.quote (ljava/lang/string;)ljava/lang/string; 05-12 09:44:33.524 24339-24339/com.example.bebo.connection d/dalvikvm﹕ vfy: replacing opcode 0x71 @ 0x0006 05-12 09:44:33.524 24339-24339/com.example.bebo.connection i/dalvikvm﹕ not find method java.lang.management.managementfactory.getruntimemxbean, referenced method org.bson.types.objectid.createprocessidentifier 05-12 09:44:33.524 24339-24339/com.example.bebo.connection w/dalvikvm﹕ vfy: unable resolve static method 18843: ljava/lang/management/managementfactory;.getruntimemxbean ()ljava/lang/management/runtimemxbean; 05-12 09:44:33.524 24339-24339/com.example.bebo.connection d/dalvikvm﹕ vfy: replacing opcode 0x71 @ 0x0000 05-12 09:44:33.549 24339-24339/com.example.bebo.connection w/org.bson.objectid﹕ failed process identifier jmx, using random number instead java.lang.noclassdeffounderror: java.lang.management.managementfactory @ org.bson.types.objectid.createprocessidentifier(objectid.java:510) @ org.bson.types.objectid.<clinit>(objectid.java:468) @ com.mongodb.connection.clusterid.<init>(clusterid.java:47) @ com.mongodb.connection.defaultclusterfactory.create(defaultclusterfactory.java:40) @ com.mongodb.mongo.createcluster(mongo.java:658) @ com.mongodb.mongo.createcluster(mongo.java:644) @ com.mongodb.mongo.<init>(mongo.java:275) @ com.mongodb.mongoclient.<init>(mongoclient.java:184) @ com.mongodb.mongoclient.<init>(mongoclient.java:160) @ com.example.bebo.connection.dbconnect.mongoconnect(dbconnect.java:19) @ com.example.bebo.connection.dbcollections.connecttomongocollection(dbcollections.java:14) @ com.example.bebo.connection.mainactivity.<init>(mainactivity.java:13) @ java.lang.class.newinstanceimpl(native method) @ java.lang.class.newinstance(class.java:1208) @ android.app.instrumentation.newactivity(instrumentation.java:1061) @ android.app.activitythread.performlaunchactivity(activitythread.java:2122) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2271) @ android.app.activitythread.access$800(activitythread.java:144) @ android.app.activitythread$h.handlemessage(activitythread.java:1205) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5146) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:732) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:566) @ dalvik.system.nativestart.main(native method) 05-12 09:44:33.554 24339-24339/com.example.bebo.connection i/cluster﹕ cluster created settings {hosts=[127.0.0.1:27017], mode=single, requiredclustertype=unknown, serverselectiontimeout='30000 ms', maxwaitqueuesize=500} 05-12 09:44:33.554 24339-24339/com.example.bebo.connection i/dalvikvm﹕ not find method java.lang.management.managementfactory.getplatformmbeanserver, referenced method com.mongodb.internal.management.jmx.jmxmbeanserver.<init> 05-12 09:44:33.554 24339-24339/com.example.bebo.connection w/dalvikvm﹕ vfy: unable resolve static method 18842: ljava/lang/management/managementfactory;.getplatformmbeanserver ()ljavax/management/mbeanserver; 05-12 09:44:33.554 24339-24339/com.example.bebo.connection d/dalvikvm﹕ vfy: replacing opcode 0x71 @ 0x0003 05-12 09:44:33.554 24339-24339/com.example.bebo.connection e/dalvikvm﹕ not find class 'javax.management.objectname', referenced method com.mongodb.internal.management.jmx.jmxmbeanserver.registermbean 05-12 09:44:33.554 24339-24339/com.example.bebo.connection w/dalvikvm﹕ vfy: unable resolve new-instance 2540 (ljavax/management/objectname;) in lcom/mongodb/internal/management/jmx/jmxmbeanserver; 05-12 09:44:33.554 24339-24339/com.example.bebo.connection d/dalvikvm﹕ vfy: replacing opcode 0x22 @ 0x0002 05-12 09:44:33.554 24339-24339/com.example.bebo.connection e/dalvikvm﹕ not find class 'javax.management.objectname', referenced method com.mongodb.internal.management.jmx.jmxmbeanserver.unregistermbean 05-12 09:44:33.554 24339-24339/com.example.bebo.connection w/dalvikvm﹕ vfy: unable resolve new-instance 2540 (ljavax/management/objectname;) in lcom/mongodb/internal/management/jmx/jmxmbeanserver; 05-12 09:44:33.554 24339-24339/com.example.bebo.connection d/dalvikvm﹕ vfy: replacing opcode 0x22 @ 0x0000 05-12 09:44:33.554 24339-24339/com.example.bebo.connection d/dalvikvm﹕ dexopt: unable opt direct call 0x4b3a @ 0x04 in lcom/mongodb/internal/management/jmx/jmxmbeanserver;.registermbean 05-12 09:44:33.559 24339-24339/com.example.bebo.connection d/dalvikvm﹕ dexopt: unable opt direct call 0x4b3a @ 0x02 in lcom/mongodb/internal/management/jmx/jmxmbeanserver;.unregistermbean 05-12 09:44:33.564 24339-24339/com.example.bebo.connection i/cluster﹕ cluster created settings {hosts=[145.24.222.221:27017], mode=single, requiredclustertype=unknown, serverselectiontimeout='30000 ms', maxwaitqueuesize=500} 05-12 09:44:33.564 24339-24352/com.example.bebo.connection i/cluster﹕ exception in monitor thread while connecting server 127.0.0.1:27017 com.mongodb.mongosocketopenexception: exception opening socket @ com.mongodb.connection.socketstream.open(socketstream.java:63) @ com.mongodb.connection.internalstreamconnection.open(internalstreamconnection.java:114) @ com.mongodb.connection.defaultservermonitor$servermonitorrunnable.run(defaultservermonitor.java:127) @ java.lang.thread.run(thread.java:841) caused by: java.net.connectexception: failed connect /127.0.0.1 (port 27017) after 20000ms: isconnected failed: econnrefused (connection refused) @ libcore.io.iobridge.isconnected(iobridge.java:223) @ libcore.io.iobridge.connecterrno(iobridge.java:161) @ libcore.io.iobridge.connect(iobridge.java:112) @ java.net.plainsocketimpl.connect(plainsocketimpl.java:192) @ java.net.plainsocketimpl.connect(plainsocketimpl.java:460) @ java.net.socket.connect(socket.java:833) @ com.mongodb.connection.socketstreamhelper.initialize(socketstreamhelper.java:50) @ com.mongodb.connection.socketstream.open(socketstream.java:58) at com.mongodb.connection.internalstreamconnection.open(internalstreamconnection.java:114) at com.mongodb.connection.defaultservermonitor$servermonitorrunnable.run(defaultservermonitor.java:127) at java.lang.thread.run(thread.java:841) caused by: libcore.io.errnoexception: isconnected failed: econnrefused (connection refused) @ libcore.io.iobridge.isconnected(iobridge.java:208) at libcore.io.iobridge.connecterrno(iobridge.java:161) at libcore.io.iobridge.connect(iobridge.java:112) at java.net.plainsocketimpl.connect(plainsocketimpl.java:192) at java.net.plainsocketimpl.connect(plainsocketimpl.java:460) at java.net.socket.connect(socket.java:833) at com.mongodb.connection.socketstreamhelper.initialize(socketstreamhelper.java:50) at com.mongodb.connection.socketstream.open(socketstream.java:58) at com.mongodb.connection.internalstreamconnection.open(internalstreamconnection.java:114) at com.mongodb.connection.defaultservermonitor$servermonitorrunnable.run(defaultservermonitor.java:127) at java.lang.thread.run(thread.java:841) 05-12 09:44:33.589 24339-24339/com.example.bebo.connection i/dalvikvm﹕ not find method android.view.viewgroup.onnestedscrollaccepted, referenced method android.support.v7.internal.widget.actionbaroverlaylayout.onnestedscrollaccepted 05-12 09:44:33.589 24339-24339/com.example.bebo.connection w/dalvikvm﹕ vfy: unable resolve virtual method 12208: landroid/view/viewgroup;.onnestedscrollaccepted (landroid/view/view;landroid/view/view;i)v 05-12 09:44:33.589 24339-24339/com.example.bebo.connection d/dalvikvm﹕ vfy: replacing opcode 0x6f @ 0x0000 05-12 09:44:33.589 24339-24339/com.example.bebo.connection i/dalvikvm﹕ not find method android.view.viewgroup.onstopnestedscroll, referenced method android.support.v7.internal.widget.actionbaroverlaylayout.onstopnestedscroll 05-12 09:44:33.589 24339-24339/com.example.bebo.connection w/dalvikvm﹕ vfy: unable resolve virtual method 12214: landroid/view/viewgroup;.onstopnestedscroll (landroid/view/view;)v 05-12 09:44:33.589 24339-24339/com.example.bebo.connection d/dalvikvm﹕ vfy: replacing opcode 0x6f @ 0x0000 05-12 09:44:33.594 24339-24339/com.example.bebo.connection i/dalvikvm﹕ not find method android.support.v7.internal.widget.actionbaroverlaylayout.stopnestedscroll, referenced method android.support.v7.internal.widget.actionbaroverlaylayout.sethideoncontentscrollenabled 05-12 09:44:33.594 24339-24339/com.example.bebo.connection w/dalvikvm﹕ vfy: unable resolve virtual method 9779: landroid/support/v7/internal/widget/actionbaroverlaylayout;.stopnestedscroll ()v 05-12 09:44:33.594 24339-24339/com.example.bebo.connection d/dalvikvm﹕ vfy: replacing opcode 0x6e @ 0x000e 05-12 09:44:33.599 24339-24339/com.example.bebo.connection i/dalvikvm﹕ not find method android.content.res.typedarray.getchangingconfigurations, referenced method android.support.v7.internal.widget.tinttypedarray.getchangingconfigurations 05-12 09:44:33.599 24339-24339/com.example.bebo.connection w/dalvikvm﹕ vfy: unable resolve virtual method 392: landroid/content/res/typedarray;.getchangingconfigurations ()i 05-12 09:44:33.599 24339-24339/com.example.bebo.connection d/dalvikvm﹕ vfy: replacing opcode 0x6e @ 0x0002 05-12 09:44:33.599 24339-24339/com.example.bebo.connection i/dalvikvm﹕ not find method android.content.res.typedarray.gettype, referenced method android.support.v7.internal.widget.tinttypedarray.gettype 05-12 09:44:33.599 24339-24339/com.example.bebo.connection w/dalvikvm﹕ vfy: unable resolve virtual method 414: landroid/content/res/typedarray;.gettype (i)i 05-12 09:44:33.599 24339-24339/com.example.bebo.connection d/dalvikvm﹕ vfy: replacing opcode 0x6e @ 0x0002 05-12 09:44:33.599 24339-24339/com.example.bebo.connection i/dalvikvm﹕ not find method android.content.res.resources.getdrawable, referenced method android.support.v7.internal.widget.resourceswrapper.getdrawable 05-12 09:44:33.604 24339-24339/com.example.bebo.connection w/dalvikvm﹕ vfy: unable resolve virtual method 355: landroid/content/res/resources;.getdrawable (ilandroid/content/res/resources$theme;)landroid/graphics/drawable/drawable; 05-12 09:44:33.604 24339-24339/com.example.bebo.connection d/dalvikvm﹕ vfy: replacing opcode 0x6e @ 0x0002 05-12 09:44:33.604 24339-24339/com.example.bebo.connection i/dalvikvm﹕ not find method android.content.res.resources.getdrawablefordensity, referenced method android.support.v7.internal.widget.resourceswrapper.getdrawablefordensity 05-12 09:44:33.604 24339-24339/com.example.bebo.connection w/dalvikvm﹕ vfy: unable resolve virtual method 357: landroid/content/res/resources;.getdrawablefordensity (iilandroid/content/res/resources$theme;)landroid/graphics/drawable/drawable; 05-12 09:44:33.604 24339-24339/com.example.bebo.connection d/dalvikvm﹕ vfy: replacing opcode 0x6e @ 0x0002 05-12 09:44:33.664 24339-24339/com.example.bebo.connection d/libegl﹕ loaded /system/lib/egl/libegl_mali.so 05-12 09:44:33.664 24339-24339/com.example.bebo.connection d/libegl﹕ loaded /system/lib/egl/libglesv1_cm_mali.so 05-12 09:44:33.669 24339-24339/com.example.bebo.connection d/libegl﹕ loaded /system/lib/egl/libglesv2_mali.so 05-12 09:44:33.679 24339-24339/com.example.bebo.connection e/﹕ device driver api match device driver api version: 23 user space api version: 23 05-12 09:44:33.679 24339-24339/com.example.bebo.connection e/﹕ mali: revision=linux-r3p2-01rel3 build_date=fri mar 21 13:52:50 kst 2014 05-12 09:44:33.749 24339-24339/com.example.bebo.connection d/openglrenderer﹕ enabling debug mode 0 05-12 09:44:33.869 24339-24339/com.example.bebo.connection i/timeline﹕ timeline: activity_idle id: android.os.binderproxy@41caee28 time:61772438 05-12 09:44:53.574 24339-24354/com.example.bebo.connection i/cluster﹕ exception in monitor thread while connecting server 145.24.222.221:27017 com.mongodb.mongosocketopenexception: exception opening socket @ com.mongodb.connection.socketstream.open(socketstream.java:63) @ com.mongodb.connection.internalstreamconnection.open(internalstreamconnection.java:114) @ com.mongodb.connection.defaultservermonitor$servermonitorrunnable.run(defaultservermonitor.java:127) @ java.lang.thread.run(thread.java:841) caused by: java.net.sockettimeoutexception: failed connect /145.24.222.221 (port 27017) after 20000ms @ libcore.io.iobridge.connecterrno(iobridge.java:159) @ libcore.io.iobridge.connect(iobridge.java:112) @ java.net.plainsocketimpl.connect(plainsocketimpl.java:192) @ java.net.plainsocketimpl.connect(plainsocketimpl.java:460) @ java.net.socket.connect(socket.java:833) @ com.mongodb.connection.socketstreamhelper.initialize(socketstreamhelper.java:50) @ com.mongodb.connection.socketstream.open(socketstream.java:58) at com.mongodb.connection.internalstreamconnection.open(internalstreamconnection.java:114) at com.mongodb.connection.defaultservermonitor$servermonitorrunnable.run(defaultservermonitor.java:127) at java.lang.thread.run(thread.java:841)
<uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.access_wifi_state" />
take outside <application></application>
Comments
Post a Comment