Search in sources :

Example 86 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class InMemoryOperationInterceptorRequestHandler method processCompareRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processCompareRequest(final int messageID, @NotNull final CompareRequestProtocolOp request, @NotNull final List<Control> controls) {
    final InterceptedCompareOperation op = new InterceptedCompareOperation(connection, messageID, request, toArray(controls));
    activeOperations.put(messageID, op);
    try {
        for (final InMemoryOperationInterceptor i : interceptors) {
            try {
                i.processCompareRequest(op);
            } catch (final LDAPException le) {
                Debug.debugException(le);
                return new LDAPMessage(messageID, new CompareResponseProtocolOp(le.toLDAPResult()), le.getResponseControls());
            } catch (final Exception e) {
                Debug.debugException(e);
                return new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_REQUEST_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null));
            }
        }
        final LDAPMessage resultMessage = wrappedHandler.processCompareRequest(messageID, new CompareRequestProtocolOp((CompareRequest) op.getRequest()), op.getRequest().getControlList());
        op.setResult(resultMessage.getCompareResponseProtocolOp().toLDAPResult(toArray(resultMessage.getControls())));
        for (final InMemoryOperationInterceptor i : interceptors) {
            try {
                i.processCompareResult(op);
            } catch (final Exception e) {
                Debug.debugException(e);
                return new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_RESULT_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null));
            }
        }
        return new LDAPMessage(messageID, new CompareResponseProtocolOp(op.getResult()), op.getResult().getResponseControls());
    } finally {
        activeOperations.remove(messageID);
    }
}
Also used : CompareRequest(com.unboundid.ldap.sdk.CompareRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) CompareRequestProtocolOp(com.unboundid.ldap.protocol.CompareRequestProtocolOp) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) NotNull(com.unboundid.util.NotNull)

Example 87 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class LDAPConnection method abandon.

/**
 * Processes an abandon request with the provided information.
 *
 * @param  requestID  The async request ID for the request to abandon.
 * @param  controls   The set of controls to include in the abandon request.
 *                    It may be {@code null} or empty if there are no
 *                    controls.
 *
 * @throws  LDAPException  If a problem occurs while sending the request to
 *                         the server.
 */
public void abandon(@NotNull final AsyncRequestID requestID, @Nullable final Control[] controls) throws LDAPException {
    if (synchronousMode()) {
        throw new LDAPException(ResultCode.NOT_SUPPORTED, ERR_ABANDON_NOT_SUPPORTED_IN_SYNCHRONOUS_MODE.get());
    }
    final int messageID = requestID.getMessageID();
    try {
        connectionInternals.getConnectionReader().deregisterResponseAcceptor(messageID);
    } catch (final Exception e) {
        Debug.debugException(e);
    }
    connectionStatistics.incrementNumAbandonRequests();
    final int abandonMessageID = nextMessageID();
    if (Debug.debugEnabled(DebugType.LDAP)) {
        Debug.debugLDAPRequest(Level.INFO, createAbandonRequestString(messageID, controls), abandonMessageID, this);
    }
    final LDAPConnectionLogger logger = connectionOptions.getConnectionLogger();
    if (logger != null) {
        final List<Control> controlList;
        if (controls == null) {
            controlList = Collections.emptyList();
        } else {
            controlList = Arrays.asList(controls);
        }
        logger.logAbandonRequest(this, abandonMessageID, messageID, controlList);
    }
    sendMessage(new LDAPMessage(abandonMessageID, new AbandonRequestProtocolOp(messageID), controls), connectionOptions.getResponseTimeoutMillis(OperationType.ABANDON));
}
Also used : RetainIdentityRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.RetainIdentityRequestControl) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) AbandonRequestProtocolOp(com.unboundid.ldap.protocol.AbandonRequestProtocolOp) LDIFException(com.unboundid.ldif.LDIFException)

Example 88 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class LDAPConnection method terminate.

/**
 * Unbinds from the server and closes the connection, optionally including the
 * provided set of controls in the unbind request.  This method is only
 * intended for internal use, since it does not make any attempt to release
 * the connection back to its associated connection pool, if there is one.
 *
 * @param  controls  The set of controls to include in the unbind request.  It
 *                   may be {@code null} if there are not to be any controls
 *                   sent in the unbind request.
 */
void terminate(@Nullable final Control[] controls) {
    if (isConnected() && (!unbindRequestSent)) {
        try {
            unbindRequestSent = true;
            setDisconnectInfo(DisconnectType.UNBIND, null, null);
            final int messageID = nextMessageID();
            if (Debug.debugEnabled(DebugType.LDAP)) {
                Debug.debugLDAPRequest(Level.INFO, createUnbindRequestString(controls), messageID, this);
            }
            final LDAPConnectionLogger logger = connectionOptions.getConnectionLogger();
            if (logger != null) {
                final List<Control> controlList;
                if (controls == null) {
                    controlList = Collections.emptyList();
                } else {
                    controlList = Arrays.asList(controls);
                }
                logger.logUnbindRequest(this, messageID, controlList);
            }
            connectionStatistics.incrementNumUnbindRequests();
            sendMessage(new LDAPMessage(messageID, new UnbindRequestProtocolOp(), controls), connectionOptions.getResponseTimeoutMillis(OperationType.UNBIND));
        } catch (final Exception e) {
            Debug.debugException(e);
        }
    }
    setClosed();
}
Also used : RetainIdentityRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.RetainIdentityRequestControl) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) UnbindRequestProtocolOp(com.unboundid.ldap.protocol.UnbindRequestProtocolOp) LDIFException(com.unboundid.ldif.LDIFException)

Example 89 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class InternalSDKHelper method cancel.

/**
 * Sends an LDAP cancel extended request to the server over the provided
 * connection without waiting for the response.  This is intended for use when
 * it is necessary to send a cancel request over a connection operating in
 * synchronous mode.
 *
 * @param  connection       The connection over which to send the cancel
 *                          request.
 * @param  targetMessageID  The message ID of the request to cancel.
 * @param  controls         The set of controls to include in the request.
 *
 * @throws  LDAPException  If a problem occurs while sending the cancel
 *                         request.
 */
@InternalUseOnly()
public static void cancel(@NotNull final LDAPConnection connection, final int targetMessageID, @Nullable final Control... controls) throws LDAPException {
    final int messageID = connection.nextMessageID();
    final CancelExtendedRequest cancelRequest = new CancelExtendedRequest(targetMessageID);
    Debug.debugLDAPRequest(Level.INFO, cancelRequest, messageID, connection);
    final LDAPConnectionLogger logger = connection.getConnectionOptions().getConnectionLogger();
    if (logger != null) {
        logger.logExtendedRequest(connection, messageID, cancelRequest);
    }
    connection.sendMessage(new LDAPMessage(messageID, new ExtendedRequest(cancelRequest), controls), connection.getConnectionOptions().getExtendedOperationResponseTimeoutMillis(CancelExtendedRequest.CANCEL_REQUEST_OID));
}
Also used : CancelExtendedRequest(com.unboundid.ldap.sdk.extensions.CancelExtendedRequest) CancelExtendedRequest(com.unboundid.ldap.sdk.extensions.CancelExtendedRequest) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) InternalUseOnly(com.unboundid.util.InternalUseOnly)

Example 90 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class ModifyDNRequest method processSync.

/**
 * Processes this modify DN operation in synchronous mode, in which the same
 * thread will send the request and read the response.
 *
 * @param  connection  The connection to use to communicate with the directory
 *                     server.
 * @param  depth       The current referral depth for this request.  It should
 *                     always be one for the initial request, and should only
 *                     be incremented when following referrals.
 * @param  allowRetry  Indicates whether the request may be re-tried on a
 *                     re-established connection if the initial attempt fails
 *                     in a way that indicates the connection is no longer
 *                     valid and autoReconnect is true.
 *
 * @return  An LDAP result object that provides information about the result
 *          of the modify DN processing.
 *
 * @throws  LDAPException  If a problem occurs while sending the request or
 *                         reading the response.
 */
@NotNull()
private LDAPResult processSync(@NotNull final LDAPConnection connection, final int depth, final boolean allowRetry) throws LDAPException {
    // Create the LDAP message.
    messageID = connection.nextMessageID();
    final LDAPMessage message = new LDAPMessage(messageID, this, getControls());
    // Send the request to the server.
    final long requestTime = System.nanoTime();
    Debug.debugLDAPRequest(Level.INFO, this, messageID, connection);
    final LDAPConnectionLogger logger = connection.getConnectionOptions().getConnectionLogger();
    if (logger != null) {
        logger.logModifyDNRequest(connection, messageID, this);
    }
    connection.getConnectionStatistics().incrementNumModifyDNRequests();
    try {
        connection.sendMessage(message, getResponseTimeoutMillis(connection));
    } catch (final LDAPException le) {
        Debug.debugException(le);
        if (allowRetry) {
            final LDAPResult retryResult = reconnectAndRetry(connection, depth, le.getResultCode());
            if (retryResult != null) {
                return retryResult;
            }
        }
        throw le;
    }
    while (true) {
        final LDAPResponse response;
        try {
            response = connection.readResponse(messageID);
        } catch (final LDAPException le) {
            Debug.debugException(le);
            if ((le.getResultCode() == ResultCode.TIMEOUT) && connection.getConnectionOptions().abandonOnTimeout()) {
                connection.abandon(messageID);
            }
            if (allowRetry) {
                final LDAPResult retryResult = reconnectAndRetry(connection, depth, le.getResultCode());
                if (retryResult != null) {
                    return retryResult;
                }
            }
            throw le;
        }
        if (response instanceof IntermediateResponse) {
            final IntermediateResponseListener listener = getIntermediateResponseListener();
            if (listener != null) {
                listener.intermediateResponseReturned((IntermediateResponse) response);
            }
        } else {
            return handleResponse(connection, response, requestTime, depth, allowRetry);
        }
    }
}
Also used : LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) LDAPResponse(com.unboundid.ldap.protocol.LDAPResponse) NotNull(com.unboundid.util.NotNull)

Aggregations

LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)92 NotNull (com.unboundid.util.NotNull)72 LDAPException (com.unboundid.ldap.sdk.LDAPException)42 Control (com.unboundid.ldap.sdk.Control)25 LogRecord (java.util.logging.LogRecord)24 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)23 ArrayList (java.util.ArrayList)19 TransactionSpecificationRequestControl (com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl)14 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)13 AssertionRequestControl (com.unboundid.ldap.sdk.controls.AssertionRequestControl)13 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)13 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)13 DontUseCopyRequestControl (com.unboundid.ldap.sdk.controls.DontUseCopyRequestControl)13 DraftLDUPSubentriesRequestControl (com.unboundid.ldap.sdk.controls.DraftLDUPSubentriesRequestControl)13 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)13 PermissiveModifyRequestControl (com.unboundid.ldap.sdk.controls.PermissiveModifyRequestControl)13 PostReadRequestControl (com.unboundid.ldap.sdk.controls.PostReadRequestControl)13 PostReadResponseControl (com.unboundid.ldap.sdk.controls.PostReadResponseControl)13 PreReadRequestControl (com.unboundid.ldap.sdk.controls.PreReadRequestControl)13 PreReadResponseControl (com.unboundid.ldap.sdk.controls.PreReadResponseControl)13