javax.naming.CommunicationException: Connection reset [Root exception is java.net.SocketException: Connection reset]; remaining name
Asked Answered
W

0

9

I am getting socket exception when I try to connect LDAP. Here is my sample code. I am seeing this issue in java 8. I never observed this issue in the earlier java versions.

public static DirContext getDirectoryContext() throws NamingException {

        Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                Common.getProperty("ldap.context.factory"));
        env.put(Context.PROVIDER_URL,
                Common.getProperty("ldap.provider.url"));
        env.put(Context.SECURITY_AUTHENTICATION,
                Common.getProperty("ldap.security.authentication"));
        env.put(Context.SECURITY_PRINCIPAL,
                Common.getProperty("ldap.security.principal"));
        env.put(Context.SECURITY_CREDENTIALS,
                Common.getProperty("ldap.security.credential"));
        context = new InitialDirContext(env);
        log.debug("NamingContext Initialized");
    return context;
}
context = getDirectoryContext();

I am using the same context for all LDAP calls.

private NamingEnumeration getResultsFromLdap(String searchFilter) {
    NamingEnumeration results = null;
    try {
        // Getting the list from LDAP matching the given filter
        SearchControls sControls = new SearchControls();
        sControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        String baseContext = Common.getProperty("ldap.base.context");
        results = context.search(baseContext, searchFilter, sControls);
        } catch (Exception e) {
        log.error("EXCEPTION IN getLDAPConnection METHOD, searchFilter : "
            + searchFilter + " : Exception Message : " + e.getMessage());
        }
        return results;
} // End of getLDAPConnection_SearchResults

Can someone help?

Windowlight answered 22/12, 2015 at 2:18 Comment(4)
Please provide the full stack trace in your question.Munch
EXCEPTION IN getLDAPConnection METHOD javax.naming.CommunicationException: Connection reset [Root exception is java.net.SocketException: Connection reset]; remaining name 'cn=users,dc=xxxxxxx,dc=ad,dc=xxxxxxxxxxx,dc=com'Windowlight
I am also facing similar issue.were you able to identify the root cause? what did you do to fix itMallina
I am also facing similar issue. Any idea how to fix itGraffito

© 2022 - 2024 — McMap. All rights reserved.