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);
}
}
}
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);
}
}
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));
}
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;
}
}
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);
}
}
}
Aggregations