Search in sources :

Example 36 with LDAPMessage

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

the class InMemoryOperationInterceptorRequestHandler method processDeleteRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processDeleteRequest(final int messageID, @NotNull final DeleteRequestProtocolOp request, @NotNull final List<Control> controls) {
    final InterceptedDeleteOperation op = new InterceptedDeleteOperation(connection, messageID, request, toArray(controls));
    activeOperations.put(messageID, op);
    try {
        for (final InMemoryOperationInterceptor i : interceptors) {
            try {
                i.processDeleteRequest(op);
            } catch (final LDAPException le) {
                Debug.debugException(le);
                return new LDAPMessage(messageID, new DeleteResponseProtocolOp(le.toLDAPResult()), le.getResponseControls());
            } catch (final Exception e) {
                Debug.debugException(e);
                return new LDAPMessage(messageID, new DeleteResponseProtocolOp(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.processDeleteRequest(messageID, new DeleteRequestProtocolOp((DeleteRequest) op.getRequest()), op.getRequest().getControlList());
        op.setResult(resultMessage.getDeleteResponseProtocolOp().toLDAPResult(toArray(resultMessage.getControls())));
        for (final InMemoryOperationInterceptor i : interceptors) {
            try {
                i.processDeleteResult(op);
            } catch (final Exception e) {
                Debug.debugException(e);
                return new LDAPMessage(messageID, new DeleteResponseProtocolOp(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 DeleteResponseProtocolOp(op.getResult()), op.getResult().getResponseControls());
    } finally {
        activeOperations.remove(messageID);
    }
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) DeleteResponseProtocolOp(com.unboundid.ldap.protocol.DeleteResponseProtocolOp) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) DeleteRequest(com.unboundid.ldap.sdk.DeleteRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) DeleteRequestProtocolOp(com.unboundid.ldap.protocol.DeleteRequestProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 37 with LDAPMessage

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

the class AddRequest method processAsync.

/**
 * Sends this add request to the directory server over the provided connection
 * and returns the message ID for the request.
 *
 * @param  connection      The connection to use to communicate with the
 *                         directory server.
 * @param  resultListener  The async result listener that is to be notified
 *                         when the response is received.  It may be
 *                         {@code null} only if the result is to be processed
 *                         by this class.
 *
 * @return  The async request ID created for the operation, or {@code null} if
 *          the provided {@code resultListener} is {@code null} and the
 *          operation will not actually be processed asynchronously.
 *
 * @throws  LDAPException  If a problem occurs while sending the request.
 */
@NotNull()
AsyncRequestID processAsync(@NotNull final LDAPConnection connection, @Nullable final AsyncResultListener resultListener) throws LDAPException {
    // Create the LDAP message.
    messageID = connection.nextMessageID();
    final LDAPMessage message = new LDAPMessage(messageID, this, getControls());
    // If the provided async result listener is {@code null}, then we'll use
    // this class as the message acceptor.  Otherwise, create an async helper
    // and use it as the message acceptor.
    final AsyncRequestID asyncRequestID;
    final long timeout = getResponseTimeoutMillis(connection);
    if (resultListener == null) {
        asyncRequestID = null;
        connection.registerResponseAcceptor(messageID, this);
    } else {
        final AsyncHelper helper = new AsyncHelper(connection, OperationType.ADD, messageID, resultListener, getIntermediateResponseListener());
        connection.registerResponseAcceptor(messageID, helper);
        asyncRequestID = helper.getAsyncRequestID();
        if (timeout > 0L) {
            final Timer timer = connection.getTimer();
            final AsyncTimeoutTimerTask timerTask = new AsyncTimeoutTimerTask(helper);
            timer.schedule(timerTask, timeout);
            asyncRequestID.setTimerTask(timerTask);
        }
    }
    // Send the request to the server.
    try {
        Debug.debugLDAPRequest(Level.INFO, this, messageID, connection);
        final LDAPConnectionLogger logger = connection.getConnectionOptions().getConnectionLogger();
        if (logger != null) {
            logger.logAddRequest(connection, messageID, this);
        }
        connection.getConnectionStatistics().incrementNumAddRequests();
        connection.sendMessage(message, timeout);
        return asyncRequestID;
    } catch (final LDAPException le) {
        Debug.debugException(le);
        connection.deregisterResponseAcceptor(messageID);
        throw le;
    }
}
Also used : Timer(java.util.Timer) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) NotNull(com.unboundid.util.NotNull)

Example 38 with LDAPMessage

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

the class CompareRequest method processSync.

/**
 * Processes this compare 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 compare processing.
 *
 * @throws  LDAPException  If a problem occurs while sending the request or
 *                         reading the response.
 */
@NotNull()
private CompareResult 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.logCompareRequest(connection, messageID, this);
    }
    connection.getConnectionStatistics().incrementNumCompareRequests();
    try {
        connection.sendMessage(message, getResponseTimeoutMillis(connection));
    } catch (final LDAPException le) {
        Debug.debugException(le);
        if (allowRetry) {
            final CompareResult 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 CompareResult 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)

Example 39 with LDAPMessage

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

the class CompareRequest method processAsync.

/**
 * Sends this compare request to the directory server over the provided
 * connection and returns the message ID for the request.
 *
 * @param  connection      The connection to use to communicate with the
 *                         directory server.
 * @param  resultListener  The async result listener that is to be notified
 *                         when the response is received.  It may be
 *                         {@code null} only if the result is to be processed
 *                         by this class.
 *
 * @return  The async request ID created for the operation, or {@code null} if
 *          the provided {@code resultListener} is {@code null} and the
 *          operation will not actually be processed asynchronously.
 *
 * @throws  LDAPException  If a problem occurs while sending the request.
 */
@Nullable()
AsyncRequestID processAsync(@NotNull final LDAPConnection connection, @Nullable final AsyncCompareResultListener resultListener) throws LDAPException {
    // Create the LDAP message.
    messageID = connection.nextMessageID();
    final LDAPMessage message = new LDAPMessage(messageID, this, getControls());
    // If the provided async result listener is {@code null}, then we'll use
    // this class as the message acceptor.  Otherwise, create an async helper
    // and use it as the message acceptor.
    final AsyncRequestID asyncRequestID;
    final long timeout = getResponseTimeoutMillis(connection);
    if (resultListener == null) {
        asyncRequestID = null;
        connection.registerResponseAcceptor(messageID, this);
    } else {
        final AsyncCompareHelper compareHelper = new AsyncCompareHelper(connection, messageID, resultListener, getIntermediateResponseListener());
        connection.registerResponseAcceptor(messageID, compareHelper);
        asyncRequestID = compareHelper.getAsyncRequestID();
        if (timeout > 0L) {
            final Timer timer = connection.getTimer();
            final AsyncTimeoutTimerTask timerTask = new AsyncTimeoutTimerTask(compareHelper);
            timer.schedule(timerTask, timeout);
            asyncRequestID.setTimerTask(timerTask);
        }
    }
    // Send the request to the server.
    try {
        Debug.debugLDAPRequest(Level.INFO, this, messageID, connection);
        final LDAPConnectionLogger logger = connection.getConnectionOptions().getConnectionLogger();
        if (logger != null) {
            logger.logCompareRequest(connection, messageID, this);
        }
        connection.getConnectionStatistics().incrementNumCompareRequests();
        connection.sendMessage(message, timeout);
        return asyncRequestID;
    } catch (final LDAPException le) {
        Debug.debugException(le);
        connection.deregisterResponseAcceptor(messageID);
        throw le;
    }
}
Also used : Timer(java.util.Timer) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) Nullable(com.unboundid.util.Nullable)

Example 40 with LDAPMessage

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

the class AccessLogRequestHandler method processDeleteRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processDeleteRequest(final int messageID, @NotNull final DeleteRequestProtocolOp request, @NotNull final List<Control> controls) {
    final long opID = nextOperationID.getAndIncrement();
    final StringBuilder b = getRequestHeader("DELETE", opID, messageID);
    b.append(" dn=\"");
    b.append(request.getDN());
    b.append('"');
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    final long startTimeNanos = System.nanoTime();
    final LDAPMessage responseMessage = requestHandler.processDeleteRequest(messageID, request, controls);
    final long eTimeNanos = System.nanoTime() - startTimeNanos;
    final DeleteResponseProtocolOp protocolOp = responseMessage.getDeleteResponseProtocolOp();
    generateResponse(b, "DELETE", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    return responseMessage;
}
Also used : LogRecord(java.util.logging.LogRecord) DeleteResponseProtocolOp(com.unboundid.ldap.protocol.DeleteResponseProtocolOp) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) 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