Search in sources :

Example 1 with LDAPMessage

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

the class ExtendedRequest method processSync.

/**
 * Processes this extended 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.
 *
 * @return  An LDAP result object that provides information about the result
 *          of the extended processing.
 *
 * @throws  LDAPException  If a problem occurs while sending the request or
 *                         reading the response.
 */
@NotNull()
private ExtendedResult processSync(@NotNull final LDAPConnection connection) 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.logExtendedRequest(connection, messageID, this);
    }
    connection.getConnectionStatistics().incrementNumExtendedRequests();
    connection.sendMessage(message, getResponseTimeoutMillis(connection));
    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);
            }
            throw le;
        }
        if (response instanceof IntermediateResponse) {
            final IntermediateResponseListener listener = getIntermediateResponseListener();
            if (listener != null) {
                listener.intermediateResponseReturned((IntermediateResponse) response);
            }
        } else {
            return handleResponse(connection, response, requestTime);
        }
    }
}
Also used : LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) LDAPResponse(com.unboundid.ldap.protocol.LDAPResponse) NotNull(com.unboundid.util.NotNull)

Example 2 with LDAPMessage

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

the class ExtendedRequest method process.

/**
 * Sends this extended request to the directory server over the provided
 * connection and returns the associated 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.
 *
 * @return  An LDAP result object that provides information about the result
 *          of the extended operation processing.
 *
 * @throws  LDAPException  If a problem occurs while sending the request or
 *                         reading the response.
 */
@Override()
@NotNull()
protected ExtendedResult process(@NotNull final LDAPConnection connection, final int depth) throws LDAPException {
    if (connection.synchronousMode()) {
        return processSync(connection);
    }
    // Create the LDAP message.
    messageID = connection.nextMessageID();
    final LDAPMessage message = new LDAPMessage(messageID, this, getControls());
    // Register with the connection reader to be notified of responses for the
    // request that we've created.
    connection.registerResponseAcceptor(messageID, this);
    try {
        // Send the request to the server.
        final long responseTimeout = getResponseTimeoutMillis(connection);
        Debug.debugLDAPRequest(Level.INFO, this, messageID, connection);
        final LDAPConnectionLogger logger = connection.getConnectionOptions().getConnectionLogger();
        if (logger != null) {
            logger.logExtendedRequest(connection, messageID, this);
        }
        final long requestTime = System.nanoTime();
        connection.getConnectionStatistics().incrementNumExtendedRequests();
        if (this instanceof StartTLSExtendedRequest) {
            connection.sendMessage(message, 50L);
        } else {
            connection.sendMessage(message, responseTimeout);
        }
        // Wait for and process the response.
        final LDAPResponse response;
        try {
            if (responseTimeout > 0) {
                response = responseQueue.poll(responseTimeout, TimeUnit.MILLISECONDS);
            } else {
                response = responseQueue.take();
            }
        } catch (final InterruptedException ie) {
            Debug.debugException(ie);
            Thread.currentThread().interrupt();
            throw new LDAPException(ResultCode.LOCAL_ERROR, ERR_EXTOP_INTERRUPTED.get(connection.getHostPort()), ie);
        }
        return handleResponse(connection, response, requestTime);
    } finally {
        connection.deregisterResponseAcceptor(messageID);
    }
}
Also used : LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) StartTLSExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest) LDAPResponse(com.unboundid.ldap.protocol.LDAPResponse) NotNull(com.unboundid.util.NotNull)

Example 3 with LDAPMessage

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

the class LDAPConnection method abandon.

/**
 * Sends an abandon request with the provided information.
 *
 * @param  messageID  The message 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.
 */
void abandon(final int messageID, @Nullable final Control... controls) throws LDAPException {
    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 4 with LDAPMessage

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

the class DeleteRequest method processAsync.

/**
 * Sends this delete 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 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.DELETE, 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.logDeleteRequest(connection, messageID, this);
        }
        connection.getConnectionStatistics().incrementNumDeleteRequests();
        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 5 with LDAPMessage

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

the class DeleteRequest method processSync.

/**
 * Processes this delete 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 delete 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.logDeleteRequest(connection, messageID, this);
    }
    connection.getConnectionStatistics().incrementNumDeleteRequests();
    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