use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class ModifyDNRequest method processAsync.
/**
* Sends this modify DN 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.MODIFY_DN, 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.logModifyDNRequest(connection, messageID, this);
}
connection.getConnectionStatistics().incrementNumModifyDNRequests();
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 ModifyRequest method processAsync.
/**
* Sends this modify 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.MODIFY, 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.logModifyRequest(connection, messageID, this);
}
connection.getConnectionStatistics().incrementNumModifyRequests();
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 SearchRequest method processAsync.
/**
* Sends this search 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 AsyncSearchResultListener 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 AsyncSearchHelper helper = new AsyncSearchHelper(connection, 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.logSearchRequest(connection, messageID, this);
}
connection.getConnectionStatistics().incrementNumSearchRequests();
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 SearchRequest method processSync.
/**
* Processes this search 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 search processing.
*
* @throws LDAPException If a problem occurs while sending the request or
* reading the response.
*/
@NotNull()
private SearchResult 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 responseTimeout = getResponseTimeoutMillis(connection);
final long requestTime = System.nanoTime();
Debug.debugLDAPRequest(Level.INFO, this, messageID, connection);
final LDAPConnectionLogger logger = connection.getConnectionOptions().getConnectionLogger();
if (logger != null) {
logger.logSearchRequest(connection, messageID, this);
}
connection.getConnectionStatistics().incrementNumSearchRequests();
try {
connection.sendMessage(message, responseTimeout);
} catch (final LDAPException le) {
Debug.debugException(le);
if (allowRetry) {
final SearchResult retryResult = reconnectAndRetry(connection, depth, le.getResultCode(), 0, 0);
if (retryResult != null) {
return retryResult;
}
}
throw le;
}
final ArrayList<SearchResultEntry> entryList;
final ArrayList<SearchResultReference> referenceList;
if (searchResultListener == null) {
entryList = new ArrayList<>(5);
referenceList = new ArrayList<>(5);
} else {
entryList = null;
referenceList = null;
}
int numEntries = 0;
int numReferences = 0;
ResultCode intermediateResultCode = ResultCode.SUCCESS;
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 SearchResult retryResult = reconnectAndRetry(connection, depth, le.getResultCode(), numEntries, numReferences);
if (retryResult != null) {
return retryResult;
}
}
throw le;
}
if (response == null) {
if (connection.getConnectionOptions().abandonOnTimeout()) {
connection.abandon(messageID);
}
throw new LDAPException(ResultCode.TIMEOUT, ERR_SEARCH_CLIENT_TIMEOUT.get(responseTimeout, messageID, baseDN, scope.getName(), filter.toString(), connection.getHostPort()));
} else if (response instanceof ConnectionClosedResponse) {
if (allowRetry) {
final SearchResult retryResult = reconnectAndRetry(connection, depth, ResultCode.SERVER_DOWN, numEntries, numReferences);
if (retryResult != null) {
return retryResult;
}
}
final ConnectionClosedResponse ccr = (ConnectionClosedResponse) response;
final String msg = ccr.getMessage();
if (msg == null) {
// The connection was closed while waiting for the response.
final SearchResult searchResult = new SearchResult(messageID, ccr.getResultCode(), ERR_CONN_CLOSED_WAITING_FOR_SEARCH_RESPONSE.get(connection.getHostPort(), toString()), null, null, entryList, referenceList, numEntries, numReferences, null);
throw new LDAPSearchException(searchResult);
} else {
// The connection was closed while waiting for the response.
final SearchResult searchResult = new SearchResult(messageID, ccr.getResultCode(), ERR_CONN_CLOSED_WAITING_FOR_SEARCH_RESPONSE_WITH_MESSAGE.get(connection.getHostPort(), toString(), msg), null, null, entryList, referenceList, numEntries, numReferences, null);
throw new LDAPSearchException(searchResult);
}
} else if (response instanceof IntermediateResponse) {
final IntermediateResponseListener listener = getIntermediateResponseListener();
if (listener != null) {
listener.intermediateResponseReturned((IntermediateResponse) response);
}
} else if (response instanceof SearchResultEntry) {
final SearchResultEntry searchEntry = (SearchResultEntry) response;
numEntries++;
if (searchResultListener == null) {
entryList.add(searchEntry);
} else {
searchResultListener.searchEntryReturned(searchEntry);
}
} else if (response instanceof SearchResultReference) {
final SearchResultReference searchReference = (SearchResultReference) response;
if (followReferrals(connection)) {
final LDAPResult result = followSearchReference(messageID, searchReference, connection, depth);
if (!result.getResultCode().equals(ResultCode.SUCCESS)) {
// We couldn't follow the reference. We don't want to fail the
// entire search because of this right now, so treat it as if
// referral following had not been enabled. Also, set the
// intermediate result code to match that of the result.
numReferences++;
if (searchResultListener == null) {
referenceList.add(searchReference);
} else {
searchResultListener.searchReferenceReturned(searchReference);
}
if (intermediateResultCode.equals(ResultCode.SUCCESS) && (result.getResultCode() != ResultCode.REFERRAL)) {
intermediateResultCode = result.getResultCode();
}
} else if (result instanceof SearchResult) {
final SearchResult searchResult = (SearchResult) result;
numEntries += searchResult.getEntryCount();
if (searchResultListener == null) {
entryList.addAll(searchResult.getSearchEntries());
}
}
} else {
numReferences++;
if (searchResultListener == null) {
referenceList.add(searchReference);
} else {
searchResultListener.searchReferenceReturned(searchReference);
}
}
} else {
final SearchResult result = (SearchResult) response;
if (allowRetry) {
final SearchResult retryResult = reconnectAndRetry(connection, depth, result.getResultCode(), numEntries, numReferences);
if (retryResult != null) {
return retryResult;
}
}
return handleResponse(connection, response, requestTime, depth, numEntries, numReferences, entryList, referenceList, intermediateResultCode);
}
}
}
use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class SimpleBindRequest method processSync.
/**
* Processes this bind 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 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 bind processing.
*
* @throws LDAPException If a problem occurs while sending the request or
* reading the response.
*/
@NotNull()
private BindResult processSync(@NotNull final LDAPConnection connection, 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.logBindRequest(connection, messageID, this);
}
connection.getConnectionStatistics().incrementNumBindRequests();
try {
connection.sendMessage(message, getResponseTimeoutMillis(connection));
} catch (final LDAPException le) {
Debug.debugException(le);
if (allowRetry) {
final BindResult bindResult = reconnectAndRetry(connection, le.getResultCode());
if (bindResult != null) {
return bindResult;
}
}
throw le;
}
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, allowRetry);
}
}
}
Aggregations