Link to home
Start Free TrialLog in
Avatar of Wonder19
Wonder19

asked on

beginner need help on javax.naming.directory

I minic the structure of a LDIF file and prepared a directory file named directory.txt - I read the whole file and pretend the file is a LDAP file. I want to use InitialDirContext object to search the file ...

bReader = new BufferedReader(new InputStreamReader(new FileInputStream("ResourseDirectory.txt")));
String line = "";
String record = "";
while((line = bReader.readLine()) != null) {
      record = record + line;
}
Hashtable resourse = new Hashtable( );
resourse.put(Context.INITIAL_CONTEXT_FACTORY, record);
DirContext context = new InitialDirContext(resourse);
SearchControls scope = new SearchControls();
scope.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration result = context.search(BASE, FILTER, scope);
SearchResult  srchresult = (SearchResult) result.next();
System.out.println("dn: " +  srchresult.getName() + ","  + BASE + "\n");
Attributes attrs = srchresult.getAttributes();
NamingEnumeration ne = attrs.getAll();
while (ne.hasMoreElements())
{
      Attribute attr = (Attribute) ne.next();
      String attrname =  attr.getID() + ": ";
      Enumeration values = attr.getAll();
      while ( values.hasMoreElements()) {
            System.out.println( attrname + values.nextElement() );
      }
}

But I have this error when I compiled the file:
Note: MRDSServer.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Then I have the following erroir when I ran the file:
Exception: javax.naming.NoInitialContextException: Cannot instantiate class: dn:

Please HELP!  Ready appreicate any help !
ASKER CERTIFIED SOLUTION
Avatar of basicinstinct
basicinstinct
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial