Search in sources :

Example 91 with LDAPMessage

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

the class ModifyRequest method processSync.

/**
 * Processes this modify 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 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.logModifyRequest(connection, messageID, this);
    }
    connection.getConnectionStatistics().incrementNumModifyRequests();
    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)

Example 92 with LDAPMessage

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

the class SASLBindRequest method sendBindRequest.

/**
 * Sends an LDAP message to the directory server and waits for the response.
 *
 * @param  connection       The connection to the directory server.
 * @param  bindDN           The bind DN to use for the request.  It should be
 *                          {@code null} for most types of SASL bind requests.
 * @param  saslCredentials  The SASL credentials to use for the bind request.
 *                          It may be {@code null} if no credentials are
 *                          required.
 * @param  controls         The set of controls to include in the request.  It
 *                          may be {@code null} if no controls are required.
 * @param  timeoutMillis    The maximum length of time in milliseconds to wait
 *                          for a response, or zero if it should wait forever.
 *
 * @return  The bind response message returned by the directory server.
 *
 * @throws  LDAPException  If a problem occurs while sending the request or
 *                         reading the response, or if a timeout occurred
 *                         while waiting for the response.
 */
@NotNull()
protected final BindResult sendBindRequest(@NotNull final LDAPConnection connection, @Nullable final String bindDN, @Nullable final ASN1OctetString saslCredentials, @Nullable final Control[] controls, final long timeoutMillis) throws LDAPException {
    messageID = connection.nextMessageID();
    final BindRequestProtocolOp protocolOp = new BindRequestProtocolOp(bindDN, getSASLMechanismName(), saslCredentials);
    final LDAPMessage requestMessage = new LDAPMessage(messageID, protocolOp, controls);
    return sendMessage(connection, requestMessage, timeoutMillis);
}
Also used : LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) BindRequestProtocolOp(com.unboundid.ldap.protocol.BindRequestProtocolOp) 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