Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Ldap problem

Thread view: 
Brzi - 14 Dec 2005 08:01 GMT
Hello !!!
I have a big problem related to ldap protocol. Can someone tell me how
to handle search timeout. My thread (one of 50) come to search and
never leave this search. It freezes!!!
It should be possible to set search timeout, but that does not work!!!!
I use novell's library. I slso tryed javax.naming....etc...it is even
worse!!!

Please help meeeee....
iksrazal@gmail.com - 14 Dec 2005 13:49 GMT
> Hello !!!
> I have a big problem related to ldap protocol. Can someone tell me how
[quoted text clipped - 5 lines]
>
> Please help meeeee....

Set timeouts on the connection:

http://java.sun.com/products/jndi/tutorial/ldap/connect/create.html

Set timeouts on the search:

http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/directory/DirContext.html
http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/directory/SearchControls.ht
ml#setTimeLimit(int
)

HTH,
iksrazal
http://www.braziloutsource.com/
Brzi - 14 Dec 2005 14:44 GMT
Here is a part of code:
env.put("com.sun.jndi.ldap.connect.timeout", "500");
env.put("com.sun.jndi.ldap.read.timeout", "500");

DirContext ctx = new InitialDirContext(env);
SearchControls ctls = new SearchControls();
ctls.setTimeLimit(5);

......no effect
iksrazal@gmail.com - 14 Dec 2005 19:57 GMT
> Here is a part of code:
> env.put("com.sun.jndi.ldap.connect.timeout", "500");
[quoted text clipped - 5 lines]
>
> ......no effect

Are you passing this object into search() ?

http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/directory/DirContext.html#s
earch(javax.naming.Name,%20java.lang.String,%20java.lang.Object[],%20javax.namin
g.directory.SearchControls
)

HTH,
iksrazal
http://www.braziloutsource.com/
Brzi - 15 Dec 2005 06:46 GMT
Yes...I forgot to tell, im using java 1.50.04. I realy don't know the
solution

DirContext ctx = new InitialDirContext(env);
SearchControls ctls = new SearchControls();

ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
try{
    NamingEnumeration answer = ctx.search("ou=su,O=F,C=P","M=9",ctls);
    while (answer.hasMore()) {
        SearchResult sr = (SearchResult)answer.next();
        DoSomethingWithAttributes(sr.getAttributes());
}
}catch (NamingException nex) {
    System.err.println("OOOps search timeout: " + nex.getMessage());
}
JScoobyCed - 15 Dec 2005 09:03 GMT
> Yes...I forgot to tell, im using java 1.50.04. I realy don't know the
> solution
[quoted text clipped - 12 lines]
>     System.err.println("OOOps search timeout: " + nex.getMessage());
> }

Would it be possible that you have a deadlock in the
DoSomethingWithAttributes() method. You said you have about 50 Threads.
Maybe some synchronization problem. Do the attributes values go to a
database? Could it be a mutual lock between Java and database (a Thread
locking a Java code block waiting for a value from a DB table locked by
another Thread that in turns needs the locked Java code block... ARG...)

Signature

JSC

Brzi - 15 Dec 2005 10:55 GMT
No.  "DoSomethingWithAttributes" simply use the attributes and make new
class.
Then that class is returned. So I don't have anything like accessing a
database.
My guess is that it is to much to handle for ldap server. I'm using one
connection for every search attempt. Maybe that is not preferable....
iksrazal@gmail.com - 15 Dec 2005 11:52 GMT
> No.  "DoSomethingWithAttributes" simply use the attributes and make new
> class.
> Then that class is returned. So I don't have anything like accessing a
> database.
> My guess is that it is to much to handle for ldap server. I'm using one
> connection for every search attempt. Maybe that is not preferable....

There is of course a limit of the number of active connections
available, regardless of which ldap your using. Try using a pool whose
size matches or is less than your max limit of your ldap server:

http://java.sun.com/products/jndi/tutorial/ldap/connect/pool.html

HTH,
iksrazal
http://www.braziloutsource.com/
iksrazal@gmail.com - 15 Dec 2005 11:46 GMT
Where's ctls.setTimeLimit(5); ?  That's 5 milliseconds - is that what
you really want? Your doSomething() could be really something like my
doLookup() - proven to work for me:

private Object doLookup (NamingEnumeration results, String type) throws
WSSecurityException
 {
   try
   {
     Fwlog.debug(this, Fwlog.DB, "doLookup...");
     if (results.hasMore())
     {
       SearchResult sr = (SearchResult) results.next();
       javax.naming.directory.Attributes xanswer = sr.getAttributes();
       javax.naming.directory.Attribute attribute = xanswer.get(type);
       // check if attribute missing
       if (null==attribute)
       {
         throw new IllegalStateException("\nERROR: Attribute type not
found: " + type);
       }

       // retrieve attribute as object and return
       Object o = attribute.get();
       if (null == o)
       {
         throw new IllegalStateException("Recieved null object for
attribute type: " + type);
       }

       return o;
     }
     else
     {
       throw new IllegalStateException("Empty Subject recieved");
     }
   }//end try
   catch ( Exception e )
   {
     Fwlog.error(this, Fwlog.DB, "doLookup() failed for for type: " +
type);
     Fwlog.error(this, Fwlog.DB, e);
     throw new WSSecurityException(e.toString(), e);
   }
 }

HTH,
iksrazal
http://www.braziloutsource.com/
Brzi - 15 Dec 2005 14:27 GMT
Well ctls.setTimeLimit(5) is not 5, its bigger....my mistake...
I will try your doLookup , but  I don't think that is the case. My
function is only iterating through the attributes... thats all..

Ok..


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.