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("ResourseD irectory.t xt")));
String line = "";
String record = "";
while((line = bReader.readLine()) != null) {
record = record + line;
}
Hashtable resourse = new Hashtable( );
resourse.put(Context.INITI AL_CONTEXT _FACTORY, record);
DirContext context = new InitialDirContext(resourse );
SearchControls scope = new SearchControls();
scope.setSearchScope(Searc hControls. SUBTREE_SC OPE);
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.NoInitialCont extExcepti on: Cannot instantiate class: dn:
Please HELP! Ready appreicate any help !
bReader = new BufferedReader(new InputStreamReader(new FileInputStream("ResourseD
String line = "";
String record = "";
while((line = bReader.readLine()) != null) {
record = record + line;
}
Hashtable resourse = new Hashtable( );
resourse.put(Context.INITI
DirContext context = new InitialDirContext(resourse
SearchControls scope = new SearchControls();
scope.setSearchScope(Searc
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.NoInitialCont
Please HELP! Ready appreicate any help !
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.