Search in sources :

Example 1 with ModifyNoDResponse

use of org.apache.directory.api.ldap.model.message.extended.ModifyNoDResponse in project directory-ldap-api by apache.

the class LdapNetworkConnection method modify.

/**
 * {@inheritDoc}
 */
@Override
public ModifyResponse modify(ModifyRequest modRequest) throws LdapException {
    if (modRequest == null) {
        String msg = "Cannot process a null modifyRequest";
        LOG.debug(msg);
        throw new IllegalArgumentException(msg);
    }
    ModifyFuture modifyFuture = modifyAsync(modRequest);
    // Get the result from the future
    try {
        // Read the response, waiting for it if not available immediately
        // Get the response, blocking
        ModifyResponse modifyResponse = modifyFuture.get(timeout, TimeUnit.MILLISECONDS);
        if (modifyResponse == null) {
            // We didn't received anything : this is an error
            if (LOG.isErrorEnabled()) {
                LOG.error(I18n.err(I18n.ERR_03203_OP_FAILED_TIMEOUT, "Modify"));
            }
            throw new LdapException(TIME_OUT_ERROR);
        }
        if (modifyResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
            // Everything is fine, return the response
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03224_MODIFY_SUCCESSFUL, modifyResponse));
            }
        } else {
            if (modifyResponse instanceof ModifyNoDResponse) {
                // A NoticeOfDisconnect : deserves a special treatment
                throw new LdapException(modifyResponse.getLdapResult().getDiagnosticMessage());
            }
            // We have had an error
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03223_MODIFY_FAILED, modifyResponse));
            }
        }
        return modifyResponse;
    } catch (Exception ie) {
        // Catch all other exceptions
        LOG.error(NO_RESPONSE_ERROR, ie);
        // Send an abandon request
        if (!modifyFuture.isCancelled()) {
            abandon(modRequest.getMessageId());
        }
        throw new LdapException(ie.getMessage(), ie);
    }
}
Also used : ModifyFuture(org.apache.directory.ldap.client.api.future.ModifyFuture) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) InvalidConnectionException(org.apache.directory.ldap.client.api.exception.InvalidConnectionException) LdapOperationException(org.apache.directory.api.ldap.model.exception.LdapOperationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) MessageEncoderException(org.apache.directory.api.ldap.codec.api.MessageEncoderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) ProtocolEncoderException(org.apache.mina.filter.codec.ProtocolEncoderException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) ModifyNoDResponse(org.apache.directory.api.ldap.model.message.extended.ModifyNoDResponse)

Aggregations

IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)1 DecoderException (org.apache.directory.api.asn1.DecoderException)1 MessageEncoderException (org.apache.directory.api.ldap.codec.api.MessageEncoderException)1 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)1 LdapNoPermissionException (org.apache.directory.api.ldap.model.exception.LdapNoPermissionException)1 LdapOperationException (org.apache.directory.api.ldap.model.exception.LdapOperationException)1 LdapOtherException (org.apache.directory.api.ldap.model.exception.LdapOtherException)1 ModifyResponse (org.apache.directory.api.ldap.model.message.ModifyResponse)1 ModifyNoDResponse (org.apache.directory.api.ldap.model.message.extended.ModifyNoDResponse)1 InvalidConnectionException (org.apache.directory.ldap.client.api.exception.InvalidConnectionException)1 ModifyFuture (org.apache.directory.ldap.client.api.future.ModifyFuture)1 ProtocolEncoderException (org.apache.mina.filter.codec.ProtocolEncoderException)1