Java LDAPException(resultCode=91 (connect error), errorMessage='尝试连接服务器时发生错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23860077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LDAPException(resultCode=91 (connect error), errorMessage='An error occurred while attempting to connect to server
提问by user3674507
I am tring to make an android app to connect at an LDAP server. I am using UnboundId library so my app to be able to establish an LDAP connection. The problem is the resultCode 91-connection error and I don't know how to resolve it. The LDAP server is up and running because my desktop app can establish a connection. I will attach the code:
我正在尝试制作一个 android 应用程序以连接到 LDAP 服务器。我正在使用 UnboundId 库,因此我的应用程序能够建立 LDAP 连接。问题是 resultCode 91-connection 错误,我不知道如何解决。LDAP 服务器已启动并正在运行,因为我的桌面应用程序可以建立连接。我将附上代码:
TextView tv = (TextView)findViewById(R.id.textView);
try {
LDAPConnection c = new LDAPConnection("192.168.106.131",389,"cn=admin,dc=test,dc=com","haha");
if(c.isConnected())
{
tv.setText("good");
}
else
{
tv.setText("bad");
}
} catch (LDAPException e) {
tv.setText("error");
e.printStackTrace();
}
And the log from LogCat:
以及来自 LogCat 的日志:
05-25 22:56:49.653: E/SELinux(21849): selinux_android_seapp_context_reload: seapp_contexts file is loaded from /data/security/spota/seapp_contexts
05-25 22:56:49.663: D/dalvikvm(21849): Late-enabling CheckJNI
05-25 22:56:50.184: W/dalvikvm(21849): VFY: unable to find class referenced in signature (Ljavax/security/sasl/SaslClient;)
05-25 22:56:50.184: W/dalvikvm(21849): VFY: unable to find class referenced in signature (Ljavax/security/sasl/SaslClient;)
05-25 22:56:50.194: I/dalvikvm(21849): Could not find method javax.security.sasl.SaslClient.dispose, referenced from method com.unboundid.ldap.sdk.LDAPConnectionInternals.close
05-25 22:56:50.194: W/dalvikvm(21849): VFY: unable to resolve interface method 12795: Ljavax/security/sasl/SaslClient;.dispose ()V
05-25 22:56:50.194: D/dalvikvm(21849): VFY: replacing opcode 0x72 at 0x0040
05-25 22:56:50.214: I/dalvikvm(21849): Could not find method javax.security.sasl.SaslClient.wrap, referenced from method com.unboundid.ldap.sdk.LDAPConnectionInternals.sendMessage
05-25 22:56:50.214: W/dalvikvm(21849): VFY: unable to resolve interface method 12801: Ljavax/security/sasl/SaslClient;.wrap ([BII)[B
05-25 22:56:50.214: D/dalvikvm(21849): VFY: replacing opcode 0x72 at 0x005c
05-25 22:57:50.448: W/System.err(21849): LDAPException(resultCode=91 (connect error), errorMessage='An error occurred while attempting to connect to server 192.168.106.131:389: java.io.IOException: Unable to establish a connection to server 192.168.106.131:389 within the configured timeout of 60000 milliseconds.')
05-25 22:57:50.448: W/System.err(21849): at com.unboundid.ldap.sdk.LDAPConnection.connect(LDAPConnection.java:755)
05-25 22:57:50.448: W/System.err(21849): at com.unboundid.ldap.sdk.LDAPConnection.connect(LDAPConnection.java:687)
05-25 22:57:50.448: W/System.err(21849): at com.example.aaa.MainActivity.onCreate(MainActivity.java:29)
05-25 22:57:50.448: W/System.err(21849): at android.app.Activity.performCreate(Activity.java:5255)
05-25 22:57:50.448: W/System.err(21849): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
05-25 22:57:50.448: W/System.err(21849): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2213)
05-25 22:57:50.448: W/System.err(21849): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
05-25 22:57:50.448: W/System.err(21849): at android.app.ActivityThread.access0(ActivityThread.java:154)
05-25 22:57:50.448: W/System.err(21849): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
05-25 22:57:50.448: W/System.err(21849): at android.os.Handler.dispatchMessage(Handler.java:99)
05-25 22:57:50.458: W/System.err(21849): at android.os.Looper.loop(Looper.java:137)
05-25 22:57:50.458: W/System.err(21849): at android.app.ActivityThread.main(ActivityThread.java:5306)
05-25 22:57:50.458: W/System.err(21849): at java.lang.reflect.Method.invokeNative(Native Method)
05-25 22:57:50.458: W/System.err(21849): at java.lang.reflect.Method.invoke(Method.java:511)
05-25 22:57:50.458: W/System.err(21849): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-25 22:57:50.458: W/System.err(21849): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-25 22:57:50.458: W/System.err(21849): at dalvik.system.NativeStart.main(Native Method)
05-25 22:57:50.458: W/System.err(21849): Caused by: java.io.IOException: Unable to establish a connection to server 192.168.106.131:389 within the configured timeout of 60000 milliseconds.
05-25 22:57:50.458: W/System.err(21849): at com.unboundid.ldap.sdk.LDAPConnectionInternals.<init>(LDAPConnectionInternals.java:143)
05-25 22:57:50.458: W/System.err(21849): at com.unboundid.ldap.sdk.LDAPConnection.connect(LDAPConnection.java:745)
05-25 22:57:50.458: W/System.err(21849): ... 16 more
05-25 22:57:50.468: W/System.err(21849): LDAPException(resultCode=81 (server down), errorMessage='The connection is not established.')
05-25 22:57:50.468: W/System.err(21849): at com.unboundid.ldap.sdk.LDAPConnection.registerResponseAcceptor(LDAPConnection.java:4228)
05-25 22:57:50.468: W/System.err(21849): at com.unboundid.ldap.sdk.SimpleBindRequest.process(SimpleBindRequest.java:538)
05-25 22:57:50.468: W/System.err(21849): at com.unboundid.ldap.sdk.LDAPConnection.bind(LDAPConnection.java:1893)
05-25 22:57:50.468: W/System.err(21849): at com.unboundid.ldap.sdk.LDAPConnection.bind(LDAPConnection.java:1855)
05-25 22:57:50.468: W/System.err(21849): at com.example.aaa.MainActivity.onCreate(MainActivity.java:46)
05-25 22:57:50.468: W/System.err(21849): at android.app.Activity.performCreate(Activity.java:5255)
05-25 22:57:50.468: W/System.err(21849): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
05-25 22:57:50.468: W/System.err(21849): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2213)
05-25 22:57:50.468: W/System.err(21849): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
05-25 22:57:50.468: W/System.err(21849): at android.app.ActivityThread.access0(ActivityThread.java:154)
05-25 22:57:50.468: W/System.err(21849): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
05-25 22:57:50.468: W/System.err(21849): at android.os.Handler.dispatchMessage(Handler.java:99)
05-25 22:57:50.478: W/System.err(21849): at android.os.Looper.loop(Looper.java:137)
05-25 22:57:50.478: W/System.err(21849): at android.app.ActivityThread.main(ActivityThread.java:5306)
05-25 22:57:50.478: W/System.err(21849): at java.lang.reflect.Method.invokeNative(Native Method)
05-25 22:57:50.478: W/System.err(21849): at java.lang.reflect.Method.invoke(Method.java:511)
05-25 22:57:50.478: W/System.err(21849): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-25 22:57:50.478: W/System.err(21849): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-25 22:57:50.478: W/System.err(21849): at dalvik.system.NativeStart.main(Native Method)
05-25 22:57:50.548: D/libEGL(21849): loaded /system/lib/egl/libEGL_adreno200.so
05-25 22:57:50.548: D/libEGL(21849): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
05-25 22:57:50.558: D/libEGL(21849): loaded /system/lib/egl/libGLESv2_adreno200.so
05-25 22:57:50.568: I/Adreno200-EGL(21849): <qeglDrvAPI_eglInitialize:265>: EGL 1.4 QUALCOMM build: AYELDER_AU_LINUX_ANDROID_JB_2.5.5.04.02.02.092.023+PATCH[ES]_msm8960_JB_2.5.5_CL3556704_rel ease_ENGG (CL3556704)
05-25 22:57:50.568: I/Adreno200-EGL(21849): Build Date: 05/17/13 Fri
05-25 22:57:50.568: I/Adreno200-EGL(21849): Local Branch:
05-25 22:57:50.568: I/Adreno200-EGL(21849): Remote Branch: quic/jb_2.5.5
05-25 22:57:50.568: I/Adreno200-EGL(21849): Local Patches: 34c9e193f12610d3e68dabd6198d2c4bfbc66974 RB: Update the master timestamp of the hw_image in rb_texture_update_aliased
05-25 22:57:50.568: I/Adreno200-EGL(21849): Reconstruct Branch: AU_LINUX_ANDROID_JB_2.5.5.04.02.02.092.023 + 01d3c78 + e6f0547 + LOCAL_PATCH[ES]
05-25 22:57:50.618: D/OpenGLRenderer(21849): Enabling debug mode 0
05-25 22:57:50.618: D/OpenGLRenderer(21849): 启用调试模式 0
回答by Neil Wilson
The error message indicates that the device can't establish a connection to the specified IP address. 192.168..is a private LAN network, so if you're using your carrier's mobile network then it wouldn't have access to it. If the device is on WiFi, then it's possible that you still might need to have some VPN tunnel.
该错误消息表明设备无法与指定的 IP 地址建立连接。192.168。. 是专用 LAN 网络,因此如果您使用的是运营商的移动网络,则它无法访问它。如果设备在 WiFi 上,那么您可能仍然需要一些 VPN 隧道。
If you know of a web server running on that same network, then you could use a web browser to test connectivity to that network. Alternately, you could try the LDAP client with a public directory server (for example, you could try directory.verisign.com on port 389 for unencrypted communication).
如果您知道在同一网络上运行的 Web 服务器,那么您可以使用 Web 浏览器来测试与该网络的连接性。或者,您可以尝试使用公共目录服务器的 LDAP 客户端(例如,您可以尝试在端口 389 上使用 directory.verisign.com 进行未加密的通信)。
回答by C.M.
I also received this error when debugging some code that was trying to do LDAP operations without calling Connect() first.
在调试一些尝试执行 LDAP 操作而不先调用 Connect() 的代码时,我也收到了这个错误。