Menu

ldapcompare throws excpetion on No Such object.

2015-12-16
2015-12-16
  • Brian Wolfe

    Brian Wolfe - 2015-12-16

    I would like to be able to do an ldap compare and then do different things based on the returned ResultCode, but everytime I get back a compare that isn't true it throws and LDAPException. Is this by design? I am using UnboundID SDK 3.0.0-se.

     
  • Neil Wilson

    Neil Wilson - 2015-12-16

    I assume that you're talking about the LDAPConnection.compare methods rather than the ldapcompare command-line tool that is included with the LDAP SDK.

    In general, the LDAPConnection methods used for processing operations throw an LDAPException if they receive a result that indicates that the operation did not complete successfully. For an LDAP compare operation, the only result codes that are expected from a successful completion are COMPARE_TRUE (meaning that the attribute value assertion contained in the compare request matched the target entry) or COMPARE_FALSE (meaning that the assertion did not match). Any other result will cause the compare method to throw an LDAPException. If you're getting an exception with a NO_SUCH_OBJECT result, then that indicates that the DN contained in the compare request references an entry that doesn't exist.

    If you would prefer to not get an exception based on the result code of the response returned by the server, then you can use the LDAPConnection.processOperation method. This method may throw an LDAPException if a problem is encountered while sending the request or reading the response (e.g., the connection is no longer valid, or the LDAP SDK didn't get a reply within the configured response timeout), but it won't throw an exception based on the result code contained in the response that it receives from the server.

    Another possibility would be to use the LDAPException.toLDAPResult method to get the result that was returned to trigger the exception.

     
  • Brian Wolfe

    Brian Wolfe - 2015-12-16

    Yes that is exactly what I am talking about. I will give you sugestion a try. Thank you so much for your quick response.

     

Log in to post a comment.