I'm getting this exception occasionally, while trying to connect Active Directory.
javax.naming.CommunicationException: <ServerIP>:<PORT>
[Root exception is java.net.ConnectException: Connection timed out: connect]
Here is my code:
DirContext ctx = null;
Properties env = new Properties();
env.put(Context.SECURITY_PRINCIPAL, <Bind_USER>);
env.put(Context.SECURITY_CREDENTIALS, <Bind_USER_PWD>);
env.put(Context.PROVIDER_URL, "ldap://<ServerIP>:<PORT>");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
ctx = new InitialDirContext(env);
Getting the connection timeout exception in this line ctx = new InitialDirContext(env);
.
It doesn't happen every-time, but happens quite often.
Please advise me, how to get rid of this issue?