无法通过mesosphere dc/os中的java程序连接到ldap服务器

2izufjch  于 2021-05-27  发布在  Spark
关注(0)|答案(0)|浏览(251)

我正在尝试在中间层dc/os环境中运行sparkjob。这个作业是一个非常简单的java程序,试图连接到ldap服务器。但是,它无法从此dc/os环境进行连接。同一个程序在本地和非dc/os环境中都能完美地运行。谢谢你的帮助。程序在这里

package com.abc.ldap;
import netscape.ldap.*;
import java.io.*;
import java.util.*;

public class LDAPTest {

    public static void main(String args[])
    {
        /* Declarations */

        /* ldap server information */
        /* for a production system, this info should be loaded via a config file */
        String host = "ldapserver.abc.net";
        int port = 389;
        String base = "o=abc.com";
        int scope = LDAPConnection.SCOPE_SUB;

        String user_filter="(mail=xyz.abc@abc.com)";
        //String getAttrs[] = {"cn", "sn","givenname"};
        String getAttrs[] = {"uid", "sn"};
        LDAPConnection ld = null;

        /*Begin processing */
        try
        {
            /*Create a new connection*/
            ld =new LDAPConnection();

            /*Connect and bind to the directory anonymously */
            System.out.println("Attempting to bind to the directory anonymously ");
            ld.connect(host,port);
            System.out.println("Connected \n");

            /* Perform search - Get user DN and other attributes from the directory 
            based on value in   user_filter*/
            System.out.println("Retrieving user's information from the directory");
            LDAPSearchResults res = ld.search(base,scope,user_filter,getAttrs,false);

            /*Get individual results*/
            while (res.hasMoreElements())
            {
                LDAPEntry findEntry = null;
                findEntry = (LDAPEntry) res.next();
                String user_dn = findEntry.getDN();
                System.out.println("User DN: " + user_dn + "\n");

                LDAPAttributeSet attributeSet = findEntry.getAttributeSet();

                for(int i=0;i<attributeSet.size();i++)
                {
                    LDAPAttribute  attribute  =  (LDAPAttribute) attributeSet.elementAt(i);
                    String attrName = attribute.getName();
                    Enumeration enumVals = attribute.getStringValues();
                    if (enumVals != null) 
                    {
                        while (enumVals.hasMoreElements()) 
                        {
                            String nextValue = (String)enumVals.nextElement();
                            System.out.println(attrName + ":" + nextValue);
                        }  /* end while*/
                    } /* end if*/               

                }/* end for*/

            } /*end while*/

            if ( ld!=null)
            {
                ld.disconnect();
                System.out.println("\nDisconnected");
            }/*end if*/             

        } catch(LDAPException e)        
        {
            e.printStackTrace();
        }

    }/*end main*/
}

获取以下错误

netscape.ldap.LDAPException: failed to connect to server ldapserver.abc.net:389 (91); Cannot connect to the LDAP server
    at netscape.ldap.LDAPConnSetupMgr.connectServer(LDAPConnSetupMgr.java:415)
    at netscape.ldap.LDAPConnSetupMgr.openSerial(LDAPConnSetupMgr.java:343)
    at netscape.ldap.LDAPConnSetupMgr.connect(LDAPConnSetupMgr.java:237)
    at netscape.ldap.LDAPConnSetupMgr.openConnection(LDAPConnSetupMgr.java:163)
    at netscape.ldap.LDAPConnection.connect(LDAPConnection.java:1033)
    at netscape.ldap.LDAPConnection.connect(LDAPConnection.java:915)
    at netscape.ldap.LDAPConnection.connect(LDAPConnection.java:759)
    at com.abc.ldap.LDAPTest.main(LDAPTest.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
    at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:849)
    at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:167)
    at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:195)
    at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:86)
    at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:924)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:933)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
20/06/29 15:06:54 INFO ShutdownHookManager: Shutdown hook called
20/06/29 15:06:54 INFO ShutdownHookManager: Deleting directory /tmp/spark-7b8171f1-5228-49f1-ad60-6714d7909dd3

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题