Search in sources :

Example 11 with LDAPResponse

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

the class SimpleBindRequest method process.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
protected BindResult process(@NotNull final LDAPConnection connection, final int depth) throws LDAPException {
    // and this should not be allowed, then throw an exception.
    if (password != null) {
        if ((bindDN.getValue().length > 0) && (password.getValue().length == 0) && connection.getConnectionOptions().bindWithDNRequiresPassword()) {
            final LDAPException le = new LDAPException(ResultCode.PARAM_ERROR, ERR_SIMPLE_BIND_DN_WITHOUT_PASSWORD.get());
            Debug.debugCodingError(le);
            throw le;
        }
    }
    if (connection.synchronousMode()) {
        @SuppressWarnings("deprecation") final boolean autoReconnect = connection.getConnectionOptions().autoReconnect();
        return processSync(connection, autoReconnect);
    }
    // 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.logBindRequest(connection, messageID, this);
        }
        final long requestTime = System.nanoTime();
        connection.getConnectionStatistics().incrementNumBindRequests();
        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_BIND_INTERRUPTED.get(connection.getHostPort()), ie);
        }
        return handleResponse(connection, response, requestTime, false);
    } finally {
        connection.deregisterResponseAcceptor(messageID);
    }
}
Also used : LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) LDAPResponse(com.unboundid.ldap.protocol.LDAPResponse) NotNull(com.unboundid.util.NotNull)

Example 12 with LDAPResponse

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

the class AddRequest method processSync.

/**
 * Processes this add 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 add 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.logAddRequest(connection, messageID, this);
    }
    connection.getConnectionStatistics().incrementNumAddRequests();
    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 13 with LDAPResponse

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

the class LDAPConnection method readResponse.

/**
 * Reads a response from the server, blocking if necessary until the response
 * has been received.  This should only be used for connections operating in
 * synchronous mode.
 *
 * @param  messageID  The message ID for the response to be read.  Any
 *                    response read with a different message ID will be
 *                    discarded, unless it is an unsolicited notification in
 *                    which case it will be provided to any registered
 *                    unsolicited notification handler.
 *
 * @return  The response read from the server.
 *
 * @throws  LDAPException  If a problem occurs while reading the response.
 */
@NotNull()
LDAPResponse readResponse(final int messageID) throws LDAPException {
    final LDAPConnectionInternals internals = connectionInternals;
    if (internals != null) {
        final LDAPResponse response = internals.getConnectionReader().readResponse(messageID);
        Debug.debugLDAPResult(response, this);
        internals.getConnectionReader().logResponse(response);
        return response;
    } else {
        final DisconnectInfo di = disconnectInfo.get();
        if (di == null) {
            return new ConnectionClosedResponse(ResultCode.CONNECT_ERROR, ERR_CONN_READ_RESPONSE_NOT_ESTABLISHED.get());
        } else {
            return new ConnectionClosedResponse(di.getType().getResultCode(), di.getMessage());
        }
    }
}
Also used : LDAPResponse(com.unboundid.ldap.protocol.LDAPResponse) NotNull(com.unboundid.util.NotNull)

Example 14 with LDAPResponse

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

the class CompareRequest method process.

/**
 * Sends this delete 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 delete processing.
 *
 * @throws  LDAPException  If a problem occurs while sending the request or
 *                         reading the response.
 */
@Override()
@NotNull()
protected CompareResult process(@NotNull final LDAPConnection connection, final int depth) throws LDAPException {
    if (connection.synchronousMode()) {
        @SuppressWarnings("deprecation") final boolean autoReconnect = connection.getConnectionOptions().autoReconnect();
        return processSync(connection, depth, autoReconnect);
    }
    final long requestTime = System.nanoTime();
    processAsync(connection, null);
    try {
        // Wait for and process the response.
        final LDAPResponse response;
        try {
            final long responseTimeout = getResponseTimeoutMillis(connection);
            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_COMPARE_INTERRUPTED.get(connection.getHostPort()), ie);
        }
        return handleResponse(connection, response, requestTime, depth, false);
    } finally {
        connection.deregisterResponseAcceptor(messageID);
    }
}
Also used : LDAPResponse(com.unboundid.ldap.protocol.LDAPResponse) NotNull(com.unboundid.util.NotNull)

Example 15 with LDAPResponse

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

the class DeleteRequest method process.

/**
 * Sends this delete 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 delete processing.
 *
 * @throws  LDAPException  If a problem occurs while sending the request or
 *                         reading the response.
 */
@Override()
@NotNull()
protected LDAPResult process(@NotNull final LDAPConnection connection, final int depth) throws LDAPException {
    if (connection.synchronousMode()) {
        @SuppressWarnings("deprecation") final boolean autoReconnect = connection.getConnectionOptions().autoReconnect();
        return processSync(connection, depth, autoReconnect);
    }
    final long requestTime = System.nanoTime();
    processAsync(connection, null);
    try {
        // Wait for and process the response.
        final LDAPResponse response;
        try {
            final long responseTimeout = getResponseTimeoutMillis(connection);
            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_DELETE_INTERRUPTED.get(connection.getHostPort()), ie);
        }
        return handleResponse(connection, response, requestTime, depth, false);
    } finally {
        connection.deregisterResponseAcceptor(messageID);
    }
}
Also used : LDAPResponse(com.unboundid.ldap.protocol.LDAPResponse) NotNull(com.unboundid.util.NotNull)

Aggregations

LDAPResponse (com.unboundid.ldap.protocol.LDAPResponse)23 NotNull (com.unboundid.util.NotNull)21 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)10 ASN1Exception (com.unboundid.asn1.ASN1Exception)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)2 NoticeOfDisconnectionExtendedResult (com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult)2 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Level (java.util.logging.Level)2 ASN1StreamReader (com.unboundid.asn1.ASN1StreamReader)1 StartTLSExtendedRequest (com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest)1 BufferedInputStream (java.io.BufferedInputStream)1 Socket (java.net.Socket)1 HashSet (java.util.HashSet)1 SSLSocket (javax.net.ssl.SSLSocket)1