Java-initiated Ldap connection is closed after some time - Websphere
This is a discussion on Java-initiated Ldap connection is closed after some time - Websphere ; Hi!
We have the following situation:
our code runs on WAS 5.1 as a webservice. When a client call comes, stateless session bean creates/calls an instance of java class, that has ssl ldap connection established (there is initial context reference ...
-
Java-initiated Ldap connection is closed after some time
Hi!
We have the following situation:
our code runs on WAS 5.1 as a webservice. When a client call comes, stateless session bean creates/calls an instance of java class, that has ssl ldap connection established (there is initial context reference that is not null). For the any number of consecutive calls, conection stays opened, but if there are no calls for about 2 minutes,
initial context reference is still valid (not null) but any method call on the initial context returns following error:
javax.naming.CommunicationException: connection closed. Root exception is
java.io.IOException: connection closed
at com.sun.jndi.ldap.LdapClient.ensureOpen(LdapClient .java:1664)
at com.sun.jndi.ldap.LdapClient.search(LdapClient.jav a:610)
at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:19 39)
at com.sun.jndi.ldap.LdapCtx.doSearchOnce(LdapCtx.jav a:1888)
at com.sun.jndi.ldap.LdapCtx.c_lookup(LdapCtx.java:98 5)
at com.sun.jndi.toolkit.ctx.ComponentContext.p_lookup (ComponentContext.java:539)
at com.sun.jndi.toolkit.ctx.PartialCompositeContext.l ookup(PartialCompositeContext.java:172).
Exacly the same application, if run as a standalone application, does not have connection closed, it stays opened for days.
My question is why is it happening and is there any standard way to prevent this behaviour?
Of corse, I can always add a connection retry block and reconnect, but isn't this behaviour strange?
Thank you very much, Inna
-
Re: Java-initiated Ldap connection is closed after some time
When you say "Exacly the same application, if run as a standalone
application, does not have connection closed, it stays opened for days",
does this mean on the same node and the same network configuration?! The
reason for asking is that firewalls sometimes kills connections, thus a
possible explanation could be that your "standalone" configuration has a
different firewall configuration than the WAS one.
Regards,
Matt
"logiccan1" wrote in message
news:818989796.1080842034701.JavaMail.wasadmin@swg 3ws006...
> Hi!
> We have the following situation:
> our code runs on WAS 5.1 as a webservice. When a client call comes,
stateless session bean creates/calls an instance of java class, that has ssl
ldap connection established (there is initial context reference that is not
null). For the any number of consecutive calls, conection stays opened, but
if there are no calls for about 2 minutes,
> initial context reference is still valid (not null) but any method call on
the initial context returns following error:
> javax.naming.CommunicationException: connection closed. Root exception is
> java.io.IOException: connection closed
> at com.sun.jndi.ldap.LdapClient.ensureOpen(LdapClient .java:1664)
> at com.sun.jndi.ldap.LdapClient.search(LdapClient.jav a:610)
> at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:19 39)
> at com.sun.jndi.ldap.LdapCtx.doSearchOnce(LdapCtx.jav a:1888)
> at com.sun.jndi.ldap.LdapCtx.c_lookup(LdapCtx.java:98 5)
> at
com.sun.jndi.toolkit.ctx.ComponentContext.p_lookup (ComponentContext.java:539
)
> at
com.sun.jndi.toolkit.ctx.PartialCompositeContext.l ookup(PartialCompositeCont
ext.java:172).
>
> Exacly the same application, if run as a standalone application, does not
have connection closed, it stays opened for days.
>
> My question is why is it happening and is there any standard way to
prevent this behaviour?
>
> Of corse, I can always add a connection retry block and reconnect, but
isn't this behaviour strange?
>
> Thank you very much, Inna
-
Re: Java-initiated Ldap connection is closed after some time
Hi,
I also encountered this problem, when I tried to connect to LDAP/MS Active Directory with tomcat. About 10 minuets after the first login, the connection was closed. When I tried to connect again I got the same message but I always succeeded to reconnect despite the error message.
I found out that it might be because we talking to a server that supports only the LDAP v2.
The solution is to specify the exact LDAP version.
Java Code:
// Set up the environment for creating the initial context
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");
env.put("java.naming.ldap.version", "2");
// Create the initial context
DirContext ctx = new InitialDirContext(env);
Or, add the following system property value:
-Djava.naming.ldap.version=2
For further information visit the following links:
http://java.sun.com/products/jndi/tu...q/context.html
http://java.sun.com/products/jndi/tu...c/version.html
Regards,
Eyal Kotler
-
Re: Java-initiated Ldap connection is closed after some time
Hi,
I also encountered this problem, when I tried to connect to LDAP/MS Active Directory with tomcat. About 10 minuets after the first login, the connection was closed. When I tried to connect again I got the same message but I always succeeded to reconnect despite the error message.
I found out that it might be because we talking to a server that supports only the LDAP v2.
The solution is to specify the exact LDAP version.
Java Code:
// Set up the environment for creating the initial context
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");
env.put("java.naming.ldap.version", "2");
// Create the initial context
DirContext ctx = new InitialDirContext(env);
Or, add the following system property value:
-Djava.naming.ldap.version=2
For further information visit the following links:
http://java.sun.com/products/jndi/tu...q/context.html
http://java.sun.com/products/jndi/tu...c/version.html
-
Re: Java-initiated Ldap connection is closed after some time
and how do i config the version at the JNDIRelam in tomcat?