Search in sources :

Example 21 with LDAPResponse

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

the class ModifyRequest method process.

/**
 * Sends this modify 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 modify 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_MODIFY_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 22 with LDAPResponse

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

the class SASLBindRequest method sendMessage.

/**
 * Sends an LDAP message to the directory server and waits for the response.
 *
 * @param  connection      The connection to the directory server.
 * @param  requestMessage  The LDAP message to send to the directory server.
 * @param  timeoutMillis   The maximum length of time in milliseconds to wait
 *                         for a response, or zero if it should wait forever.
 *
 * @return  The response message received from the 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 sendMessage(@NotNull final LDAPConnection connection, @NotNull final LDAPMessage requestMessage, final long timeoutMillis) throws LDAPException {
    if (connection.synchronousMode()) {
        return sendMessageSync(connection, requestMessage, timeoutMillis);
    }
    final int msgID = requestMessage.getMessageID();
    connection.registerResponseAcceptor(msgID, this);
    try {
        Debug.debugLDAPRequest(Level.INFO, this, msgID, 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(requestMessage, timeoutMillis);
        // Wait for and process the response.
        final LDAPResponse response;
        try {
            if (timeoutMillis > 0) {
                response = responseQueue.poll(timeoutMillis, 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);
    } finally {
        connection.deregisterResponseAcceptor(msgID);
    }
}
Also used : LDAPResponse(com.unboundid.ldap.protocol.LDAPResponse) NotNull(com.unboundid.util.NotNull)

Example 23 with LDAPResponse

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

the class SASLBindRequest method sendMessageSync.

/**
 * Sends an LDAP message to the directory server and waits for the response.
 * This should only be used when the connection is operating in synchronous
 * mode.
 *
 * @param  connection      The connection to the directory server.
 * @param  requestMessage  The LDAP message to send to the directory server.
 * @param  timeoutMillis   The maximum length of time in milliseconds to wait
 *                         for a response, or zero if it should wait forever.
 *
 * @return  The response message received from the 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()
private BindResult sendMessageSync(@NotNull final LDAPConnection connection, @NotNull final LDAPMessage requestMessage, final long timeoutMillis) throws LDAPException {
    final int msgID = requestMessage.getMessageID();
    Debug.debugLDAPRequest(Level.INFO, this, msgID, 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(requestMessage, timeoutMillis);
    while (true) {
        final LDAPResponse response = connection.readResponse(messageID);
        if (response instanceof IntermediateResponse) {
            final IntermediateResponseListener listener = getIntermediateResponseListener();
            if (listener != null) {
                listener.intermediateResponseReturned((IntermediateResponse) response);
            }
        } else {
            return handleResponse(connection, response, requestTime);
        }
    }
}
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