Class LdapException

All Implemented Interfaces:
Serializable, LocalizableException
Direct Known Subclasses:
AssertionFailureException, AuthenticationException, AuthorizationException, CancelledResultException, ConnectionException, ConstraintViolationException, EntryNotFoundException, MultipleEntriesFoundException, TimeoutResultException

public class LdapException extends IOException implements LocalizableException
Thrown when the result code returned in a Result indicates that the Request was unsuccessful. This class can be sub-classed in order to implement application specific exceptions.
See Also:
  • Constructor Details

    • LdapException

      protected LdapException(Result result)
      Creates a new LDAP exception using the provided result.
      Parameters:
      result - The error result.
  • Method Details

    • invalidCredentials

      public static LdapException invalidCredentials()
      Returns a new LdapException with the INVALID_CREDENTIALS error code with no message.
      Returns:
      a new LdapException
    • invalidCredentials

      public static LdapException invalidCredentials(CharSequence message)
      Returns a new LdapException with the INVALID_CREDENTIALS error code using the provided message.
      Parameters:
      message - the error message to use
      Returns:
      a new LdapException
    • constraintViolation

      public static LdapException constraintViolation(CharSequence message)
      Returns a new LdapException with the CONSTRAINT_VIOLATION error code using the provided message.
      Parameters:
      message - the error message to use
      Returns:
      a new LdapException
    • constraintViolation

      public static LdapException constraintViolation(CharSequence message, Throwable cause)
      Returns a new LdapException with the CONSTRAINT_VIOLATION error code using the provided message.
      Parameters:
      message - the error message to use
      cause - the cause of the exception
      Returns:
      a new LdapException
    • noSuchObject

      public static LdapException noSuchObject()
      Returns a new LdapException with the NO_SUCH_OBJECT error code using the provided message.
      Returns:
      a new LdapException
    • noSuchObject

      public static LdapException noSuchObject(CharSequence message)
      Returns a new LdapException with the NO_SUCH_OBJECT error code using the provided message.
      Parameters:
      message - the error message to use
      Returns:
      a new LdapException
    • noSuchObject

      public static LdapException noSuchObject(CharSequence message, Dn matchedDn)
      Returns a new LdapException with the NO_SUCH_OBJECT error code using the provided message.
      Parameters:
      message - the error message to use
      matchedDn - The matched DN associated, which may be empty or null indicating that none was provided.
      Returns:
      a new LdapException
    • protocolError

      public static LdapException protocolError(CharSequence message)
      Returns a new LdapException with the PROTOCOL_ERROR error code using the provided message.
      Parameters:
      message - the error message to use
      Returns:
      a new LdapException
    • protocolError

      public static LdapException protocolError(Throwable cause)
      Returns a new LdapException with the PROTOCOL_ERROR error code using the provided message.
      Parameters:
      cause - the cause of the exception
      Returns:
      a new LdapException
    • unwillingToPerform

      public static LdapException unwillingToPerform(CharSequence message)
      Returns a new LdapException with the UNWILLING_TO_PERFORM error code using the provided message.
      Parameters:
      message - the error message to use
      Returns:
      a new LdapException
    • newLdapException

      public static LdapException newLdapException(ResultCode resultCode)
      Creates a new LDAP exception with the provided result code and an empty diagnostic message.
      Parameters:
      resultCode - The result code.
      Returns:
      The new LDAP exception.
      Throws:
      IllegalArgumentException - If the provided result code does not represent a failure.
      NullPointerException - If resultCode was null.
    • newLdapException

      public static LdapException newLdapException(ResultCode resultCode, CharSequence diagnosticMessage)
      Creates a new LDAP exception with the provided result code and diagnostic message.
      Parameters:
      resultCode - The result code.
      diagnosticMessage - The diagnostic message, which may be empty or null indicating that none was provided.
      Returns:
      The new LDAP exception.
      Throws:
      IllegalArgumentException - If the provided result code does not represent a failure.
      NullPointerException - If resultCode was null.
    • newLdapException

      public static LdapException newLdapException(ResultCode resultCode, Throwable cause)
      Creates a new LDAP exception with the provided result code and cause. The diagnostic message will be taken from the cause, if provided.
      Parameters:
      resultCode - The result code.
      cause - The throwable cause, which may be null indicating that none was provided.
      Returns:
      The new LDAP exception.
      Throws:
      IllegalArgumentException - If the provided result code does not represent a failure.
      NullPointerException - If resultCode was null.
    • newLdapException

      public static LdapException newLdapException(ResultCode resultCode, CharSequence diagnosticMessage, Throwable cause)
      Creates a new LDAP exception with the provided result code, diagnostic message, and cause.
      Parameters:
      resultCode - The result code.
      diagnosticMessage - The diagnostic message, which may be empty or null indicating that none was provided.
      cause - The throwable cause, which may be null indicating that none was provided.
      Returns:
      The new LDAP exception.
      Throws:
      IllegalArgumentException - If the provided result code does not represent a failure.
      NullPointerException - If resultCode was null.
    • newLdapException

      public static LdapException newLdapException(ResultCode resultCode, CharSequence diagnosticMessage, Dn matchedDn)
      Creates a new LDAP exception with the provided resultCode, diagnosticMessage, matched DN and cause.
      Parameters:
      resultCode - The result code.
      diagnosticMessage - The diagnostic message, which may be empty or null.
      matchedDn - The matched DN associated, which may be empty or null indicating that none was provided.
      Returns:
      The new LDAP exception.
      Throws:
      IllegalArgumentException - If the provided result code does not represent a failure.
      NullPointerException - If resultCode was null.
    • newLdapException

      public static LdapException newLdapException(ResultCode resultCode, CharSequence diagnosticMessage, Dn matchedDn, Throwable cause)
      Creates a new LDAP exception with the provided resultCode, diagnosticMessage, matched DN and cause.
      Parameters:
      resultCode - The result code.
      diagnosticMessage - The diagnostic message, which may be empty or null.
      matchedDn - The matched DN associated, which may be empty or null indicating that none was provided.
      cause - The throwable cause, which may be null indicating that none was provided.
      Returns:
      The new LDAP exception.
      Throws:
      IllegalArgumentException - If the provided result code does not represent a failure.
      NullPointerException - If resultCode was null.
    • newLdapException

      public static LdapException newLdapException(Throwable cause)
      Creates a new LDAP exception with the provided cause and a result code depending on the class cause original cause. If no cause is provided, or there is no specific result code defined for the cause, ResultCode.OTHER will be used.
      Parameters:
      cause - The throwable cause, may be {code null}.
      Returns:
      The new LDAP exception
    • newLdapClientException

      public static LdapException newLdapClientException(Throwable cause)
      Creates a new LDAP client exception with the provided cause and a result code depending on the class cause original cause. If no cause is provided, or there is no specific result code defined for the cause, ResultCode.CLIENT_SIDE_LOCAL_ERROR will be used.
      Parameters:
      cause - The throwable cause, may be {code null}.
      Returns:
      The new LDAP exception
    • newLdapException

      public static LdapException newLdapException(Result result)
      Creates a new LDAP exception using the provided result.
      Parameters:
      result - The result whose result code indicates a failure.
      Returns:
      The LDAP exception wrapping the provided result.
      Throws:
      IllegalArgumentException - If the provided result does not represent a failure.
      NullPointerException - If result was null.
    • fillInStackTrace

      public final Throwable fillInStackTrace()
      Prevent costly stack traces from being created because they are not useful for this type of exception.
      Overrides:
      fillInStackTrace in class Throwable
    • getResult

      public final Result getResult()
      Returns the error result which caused this exception to be thrown. The type of result returned corresponds to the expected result type of the original request.
      Returns:
      The error result which caused this exception to be thrown.
    • getResultCode

      public final ResultCode getResultCode()
      Returns the result code associated with this result.
      Returns:
      The result code.
    • getMessageObject

      public final LocalizableMessage getMessageObject()
      Description copied from interface: LocalizableException
      Returns the localizable message that explains the problem that occurred.
      Specified by:
      getMessageObject in interface LocalizableException
      Returns:
      The localizable message that explains the problem that occurred.
    • getMessage

      public final String getMessage()
      Overrides:
      getMessage in class Throwable
    • toString

      public final String toString()
      Overrides:
      toString in class Throwable