OPENDJ-1666 CR-7647 forgerock-util 2.0.0 migration
* Note that this migration just solved compilation issues, it does not try to take benefits from the apis enhancements.
* The major change is that org.forgerock.opendj.ldap.ResultHandler has been renamed to org.forgerock.opendj.ldap.LdapResultHandler.java to prevent conflicts with the org.forgerock.util.promise.ResultHandler
1 files renamed
81 files modified
| | |
| | | */ |
| | | package com.forgerock.opendj.cli; |
| | | |
| | | import static org.forgerock.util.Utils.*; |
| | | |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | |
| | | import org.forgerock.opendj.ldap.AbstractConnectionWrapper; |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LdapPromise; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.requests.BindRequest; |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.AsyncFunction; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | |
| | | import static org.forgerock.util.Utils.*; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | /** |
| | | * An authenticated connection factory can be used to create pre-authenticated |
| | | * connections to a Directory Server. |
| | |
| | | } |
| | | |
| | | return connection.bindAsync(request) |
| | | .onSuccess(new SuccessHandler<BindResult>() { |
| | | @Override |
| | | public void handleResult(final BindResult result) { |
| | | // Save the result. |
| | | AuthenticatedConnection.this.result = result; |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | /* |
| | | * This connection is now unauthenticated so prevent further use. |
| | | */ |
| | | connection.close(); |
| | | } |
| | | }); |
| | | .thenOnResult(new ResultHandler<BindResult>() { |
| | | @Override |
| | | public void handleResult(final BindResult result) { |
| | | // Save the result. |
| | | AuthenticatedConnection.this.result = result; |
| | | } |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleException(final LdapException exception) { |
| | | /* |
| | | * This connection is now unauthenticated so prevent further use. |
| | | */ |
| | | connection.close(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | |
| | | Note: waiting on https://jira.codehaus.org/browse/MCLIRR-62 to be resolved to avoid the need to use \s* in the '<to>' tags. |
| | | --> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>LDAPConnectionFactory(java.net.SocketAddress)</method> |
| | | <justification>Moving from inetSocketAddress to host+port constructors</justification> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>LDAPConnectionFactory(java.net.SocketAddress)</method> |
| | | <justification>Moving from inetSocketAddress to host+port constructors</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>LDAPConnectionFactory(java.net.SocketAddress, org.forgerock.opendj.ldap.LDAPOptions)</method> |
| | | <justification>Moving from inetSocketAddress to host+port constructors</justification> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>LDAPConnectionFactory(java.net.SocketAddress, org.forgerock.opendj.ldap.LDAPOptions)</method> |
| | | <justification>Moving from inetSocketAddress to host+port constructors</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>java.net.InetAddress getAddress()</method> |
| | | <justification>Moving from inetSocketAddress to host+port constructors</justification> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>java.net.InetAddress getAddress()</method> |
| | | <justification>Moving from inetSocketAddress to host+port constructors</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>java.net.SocketAddress getSocketAddress()</method> |
| | | <justification>Moving from inetSocketAddress to host+port constructors</justification> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>java.net.SocketAddress getSocketAddress()</method> |
| | | <justification>Moving from inetSocketAddress to host+port constructors</justification> |
| | | </difference> |
| | | |
| | | <difference> |
| | |
| | | <className>org/forgerock/opendj/ldap/AttributeParser</className> |
| | | <differenceType>7005</differenceType> |
| | | <method>*as*(org.forgerock.opendj.ldap.Function*)</method> |
| | | <to>*as*(org.forgerock.util.promise.Function*)</to> |
| | | <justification>OPENDJ-1550 Replace SDK Function with Function from forgerock-util</justification> |
| | | <to>*as*(org.forgerock.util.Function*)</to> |
| | | <justification> |
| | | OPENDJ-1550 Replace SDK Function with Function from forgerock-util |
| | | OPENDJ-1666 Update sdk to forgerock-util 2.0.0 |
| | | </justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/Functions</className> |
| | | <differenceType>7005</differenceType> |
| | | <method>*compose(org.forgerock.opendj.ldap.Function, org.forgerock.opendj.ldap.Function)</method> |
| | | <to>*compose(org.forgerock.util.promise.Function, org.forgerock.util.promise.Function)</to> |
| | | <justification>OPENDJ-1550 Replace SDK Function with Function from forgerock-util</justification> |
| | | <to>*compose(org.forgerock.util.Function, org.forgerock.util.Function)</to> |
| | | <justification> |
| | | OPENDJ-1550 Replace SDK Function with Function from forgerock-util |
| | | OPENDJ-1666 Update sdk to forgerock-util 2.0.0 |
| | | </justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/Functions</className> |
| | |
| | | <justification>Lack of startsWith() forced to re-implement it multiple times at different location</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/ByteString</className> |
| | | <differenceType>7005</differenceType> |
| | | <method>org.forgerock.opendj.ldap.ByteString valueOf(java.lang.String)</method> |
| | | <from>org.forgerock.opendj.ldap.ByteString valueOf(java.lang.String)</from> |
| | | <to>org.forgerock.opendj.ldap.ByteString valueOf(java.lang.CharSequence)</to> |
| | | <justification>Using CharSequence instead of String allows to reduce memory copy.</justification> |
| | | <className>org/forgerock/opendj/ldap/ByteString</className> |
| | | <differenceType>7005</differenceType> |
| | | <method>org.forgerock.opendj.ldap.ByteString valueOf(java.lang.String)</method> |
| | | <from>org.forgerock.opendj.ldap.ByteString valueOf(java.lang.String)</from> |
| | | <to>org.forgerock.opendj.ldap.ByteString valueOf(java.lang.CharSequence)</to> |
| | | <justification>Using CharSequence instead of String allows to reduce memory copy.</justification> |
| | | </difference> |
| | | |
| | | <!-- OPENDJ-1666 Migration to forgerock-util 2.0.0 --> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/Functions</className> |
| | | <differenceType>7006</differenceType> |
| | | <method>*</method> |
| | | <to>org.forgerock.util.Function</to> |
| | | <justification>OPENDJ-1666 Update sdk to forgerock-util 2.0.0</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LdapResultHandler</className> |
| | | <differenceType>8000</differenceType> |
| | | <justification>OPENDJ-1666 Update sdk to forgerock-util 2.0.0</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>%regex[org/forgerock/opendj/ldap/(RequestHandler|MemoryBackend)]</className> |
| | | <differenceType>7005</differenceType> |
| | | <method>%regex[(.)* handle*(.)*org\.forgerock\.opendj\.ldap\.ResultHandler(.)*]</method> |
| | | <to>%regex[(.)* handle*(.)*org\.forgerock\.opendj\.ldap\.LdapResultHandler(.)*]</to> |
| | | <justification>OPENDJ-1666 Update sdk to forgerock-util 2.0.0</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>%regex[org/forgerock/opendj/ldap/responses/(Abstract)?ExtendedResultDecoder]</className> |
| | | <differenceType>7006</differenceType> |
| | | <method>org.forgerock.opendj.ldap.ResultHandler adaptExtendedResultHandler(org.forgerock.opendj.ldap.requests.ExtendedRequest, org.forgerock.opendj.ldap.ResultHandler, org.forgerock.opendj.ldap.DecodeOptions)</method> |
| | | <to>org.forgerock.opendj.ldap.LdapResultHandler</to> |
| | | <justification>OPENDJ-1666 Update sdk to forgerock-util 2.0.0</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>%regex[org/forgerock/opendj/ldap/responses/(Abstract)?ExtendedResultDecoder]</className> |
| | | <differenceType>7005</differenceType> |
| | | <method>org.forgerock.opendj.ldap.ResultHandler adaptExtendedResultHandler(org.forgerock.opendj.ldap.requests.ExtendedRequest, org.forgerock.opendj.ldap.ResultHandler, org.forgerock.opendj.ldap.DecodeOptions)</method> |
| | | <to>org.forgerock.opendj.ldap.ResultHandler adaptExtendedResultHandler(org.forgerock.opendj.ldap.requests.ExtendedRequest, org.forgerock.opendj.ldap.LdapResultHandler, org.forgerock.opendj.ldap.DecodeOptions)</to> |
| | | <justification>OPENDJ-1666 Update sdk to forgerock-util 2.0.0</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/RootDSE</className> |
| | | <differenceType>7005</differenceType> |
| | | <method>*readRootDSEAsync(org.forgerock.opendj.ldap.Connection, org.forgerock.opendj.ldap.ResultHandler)</method> |
| | | <to>*readRootDSEAsync(org.forgerock.opendj.ldap.Connection, org.forgerock.opendj.ldap.LdapResultHandler)</to> |
| | | <justification>OPENDJ-1666 Update sdk to forgerock-util 2.0.0</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/AuthenticatedConnectionFactory$AuthenticatedConnection</className> |
| | | <differenceType>7005</differenceType> |
| | | <method>*bindAsync(org.forgerock.opendj.ldap.requests.BindRequest, org.forgerock.opendj.ldap.IntermediateResponseHandler, org.forgerock.opendj.ldap.ResultHandler)</method> |
| | | <to>*bindAsync(org.forgerock.opendj.ldap.requests.BindRequest*org.forgerock.opendj.ldap.IntermediateResponseHandler*org.forgerock.opendj.ldap.LdapResultHandler)</to> |
| | | <justification>OPENDJ-1666 Update sdk to forgerock-util 2.0.0</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/ResultHandler</className> |
| | | <differenceType>8001</differenceType> |
| | | <justification>OPENDJ-1666 Update sdk to forgerock-util 2.0.0</justification> |
| | | </difference> |
| | | |
| | | </differences> |
| | |
| | | import java.util.List; |
| | | import java.util.ListIterator; |
| | | |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | /** |
| | |
| | | import java.util.Collection; |
| | | import java.util.Iterator; |
| | | |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | /** |
| | |
| | | import java.util.Iterator; |
| | | import java.util.NoSuchElementException; |
| | | |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | /** |
| | |
| | | import org.forgerock.opendj.ldif.ChangeRecordVisitor; |
| | | import org.forgerock.opendj.ldif.ConnectionEntryReader; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.AsyncFunction; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.promise.Promise; |
| | | |
| | | import com.forgerock.opendj.util.ReferenceCountedObject; |
| | |
| | | */ |
| | | abstract class AbstractLoadBalancingAlgorithm implements LoadBalancingAlgorithm { |
| | | private final class MonitoredConnectionFactory implements ConnectionFactory, |
| | | ResultHandler<Connection> { |
| | | LdapResultHandler<Connection> { |
| | | |
| | | private final ConnectionFactory factory; |
| | | private final AtomicBoolean isOperational = new AtomicBoolean(true); |
| | |
| | | @Override |
| | | public Promise<Connection, LdapException> apply(Connection value) throws LdapException { |
| | | notifyOnline(); |
| | | return newSuccessfulPromise(value); |
| | | return newResultPromise(value); |
| | | } |
| | | }, |
| | | new AsyncFunction<LdapException, Connection, LdapException>() { |
| | |
| | | * Handle monitoring connection request failure. |
| | | */ |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | notifyOffline(error); |
| | | public void handleException(final LdapException exception) { |
| | | notifyOffline(exception); |
| | | } |
| | | |
| | | /** |
| | |
| | | private synchronized void checkIfAvailable() { |
| | | if (!isOperational.get() && (pendingConnectPromise == null || pendingConnectPromise.isDone())) { |
| | | logger.debug(LocalizableMessage.raw("Attempting reconnect to offline factory '%s'", this)); |
| | | pendingConnectPromise = factory.getConnectionAsync().onSuccess(this).onFailure(this); |
| | | pendingConnectPromise = factory.getConnectionAsync().thenOnResult(this).thenOnException(this); |
| | | } |
| | | } |
| | | |
| | |
| | | public LdapPromise<Result> addAsync(final AddRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(add(request)); |
| | | return thenOnResult(add(request)); |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | return onException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | public LdapPromise<BindResult> bindAsync(final BindRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(bind(request)); |
| | | return thenOnResult(bind(request)); |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | return onException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | public LdapPromise<CompareResult> compareAsync(final CompareRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(compare(request)); |
| | | return thenOnResult(compare(request)); |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | return onException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | public LdapPromise<Result> deleteAsync(final DeleteRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(delete(request)); |
| | | return thenOnResult(delete(request)); |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | return onException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | public <R extends ExtendedResult> LdapPromise<R> extendedRequestAsync(final ExtendedRequest<R> request, |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(extendedRequest(request, intermediateResponseHandler)); |
| | | return thenOnResult(extendedRequest(request, intermediateResponseHandler)); |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | return onException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | public LdapPromise<Result> modifyAsync(final ModifyRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(modify(request)); |
| | | return thenOnResult(modify(request)); |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | return onException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | public LdapPromise<Result> modifyDNAsync(final ModifyDNRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(modifyDN(request)); |
| | | return thenOnResult(modifyDN(request)); |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | return onException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | public LdapPromise<Result> searchAsync(final SearchRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final SearchResultHandler entryHandler) { |
| | | try { |
| | | return onSuccess(search(request, entryHandler)); |
| | | return thenOnResult(search(request, entryHandler)); |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | return onException(e); |
| | | } |
| | | } |
| | | |
| | | private <R extends Result> LdapPromise<R> onFailure(final LdapException e) { |
| | | private <R extends Result> LdapPromise<R> onException(final LdapException e) { |
| | | return newFailedLdapPromise(e); |
| | | } |
| | | |
| | | private <R extends Result> LdapPromise<R> onSuccess(final R result) { |
| | | private <R extends Result> LdapPromise<R> thenOnResult(final R result) { |
| | | return newSuccessfulLdapPromise(result); |
| | | } |
| | | |
| | |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | import static com.forgerock.opendj.util.Collections2.*; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.requests.BindRequest; |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | import org.forgerock.util.promise.AsyncFunction; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.Promise; |
| | | |
| | | import static org.forgerock.util.Utils.*; |
| | |
| | | */ |
| | | public LdapPromise<BindResult> bindAsync(final BindRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<? super BindResult> resultHandler) { |
| | | final LdapResultHandler<? super BindResult> resultHandler) { |
| | | throw new UnsupportedOperationException(); |
| | | } |
| | | |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.util.promise.Promises.*; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.*; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | |
| | | import org.forgerock.opendj.ldif.ChangeRecord; |
| | | import org.forgerock.opendj.ldif.ConnectionEntryReader; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.PromiseImpl; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | |
| | | import com.forgerock.opendj.util.ReferenceCountedObject; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | import org.forgerock.util.time.TimeService; |
| | | |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.util.promise.Promises.*; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.*; |
| | | import com.forgerock.opendj.util.ReferenceCountedObject; |
| | | |
| | | /** |
| | | * A connection pool implementation which maintains a cache of pooled |
| | |
| | | * This success handler is invoked when an attempt to add a new connection |
| | | * to the pool completes. |
| | | */ |
| | | private final class ConnectionSuccessHandler implements SuccessHandler<Connection> { |
| | | private final class ConnectionResultHandler implements ResultHandler<Connection> { |
| | | @Override |
| | | public void handleResult(final Connection connection) { |
| | | logger.debug(LocalizableMessage.raw( |
| | |
| | | * This failure handler is invoked when an attempt to add a new connection |
| | | * to the pool ended in error. |
| | | */ |
| | | private final class ConnectionFailureHandler implements FailureHandler<LdapException> { |
| | | private final class ConnectionFailureHandler implements ExceptionHandler<LdapException> { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException exception) { |
| | | // Connection attempt failed, so decrease the pool size. |
| | | pendingConnectionAttempts.decrementAndGet(); |
| | | availableConnections.release(); |
| | | |
| | | logger.debug(LocalizableMessage.raw( |
| | | "Connection attempt failed: availableConnections=%d, maxPoolSize=%d", |
| | | currentPoolSize(), maxPoolSize, error)); |
| | | currentPoolSize(), maxPoolSize, exception)); |
| | | |
| | | /* |
| | | * There may be many pending promises waiting for a connection |
| | |
| | | } |
| | | } |
| | | for (QueueElement waitingPromise : waitingPromises) { |
| | | waitingPromise.getWaitingPromise().handleError(error); |
| | | waitingPromise.getWaitingPromise().handleException(exception); |
| | | } |
| | | } |
| | | } |
| | |
| | | */ |
| | | connection.close(); |
| | | pendingConnectionAttempts.incrementAndGet(); |
| | | factory.getConnectionAsync().onSuccess(connectionSuccessHandler).onFailure(connectionFailureHandler); |
| | | factory.getConnectionAsync().thenOnResult(connectionResultHandler) |
| | | .thenOnException(connectionFailureHandler); |
| | | |
| | | logger.debug(LocalizableMessage.raw( |
| | | "Connection no longer valid: availableConnections=%d, maxPoolSize=%d", |
| | |
| | | TimeService timeService = TimeService.SYSTEM; |
| | | |
| | | private final Semaphore availableConnections; |
| | | private final SuccessHandler<Connection> connectionSuccessHandler = new ConnectionSuccessHandler(); |
| | | private final FailureHandler<LdapException> connectionFailureHandler = new ConnectionFailureHandler(); |
| | | private final ResultHandler<Connection> connectionResultHandler = new ConnectionResultHandler(); |
| | | private final ExceptionHandler<LdapException> connectionFailureHandler = new ConnectionFailureHandler(); |
| | | private final int corePoolSize; |
| | | private final ConnectionFactory factory; |
| | | private boolean isClosed; |
| | |
| | | final Promise<Connection, LdapException> promise = holder.getWaitingPromise(); |
| | | if (!promise.isDone() && availableConnections.tryAcquire()) { |
| | | pendingConnectionAttempts.incrementAndGet(); |
| | | factory.getConnectionAsync().onSuccess(connectionSuccessHandler) |
| | | .onFailure(connectionFailureHandler); |
| | | factory.getConnectionAsync().thenOnResult(connectionResultHandler) |
| | | .thenOnException(connectionFailureHandler); |
| | | } |
| | | return promise; |
| | | } |
| | |
| | | final Connection connection = holder.getWaitingConnection(); |
| | | if (connection.isValid()) { |
| | | final Connection pooledConnection = newPooledConnection(connection, getStackTraceIfDebugEnabled()); |
| | | return newSuccessfulPromise(pooledConnection); |
| | | return newResultPromise(pooledConnection); |
| | | } else { |
| | | // Close the stale connection and try again. |
| | | connection.close(); |
| | |
| | | final LdapException e = |
| | | newLdapException(ResultCode.CLIENT_SIDE_USER_CANCELLED, |
| | | ERR_CONNECTION_POOL_CLOSING.get(toString()).toString()); |
| | | holder.getWaitingPromise().handleError(e); |
| | | holder.getWaitingPromise().handleException(e); |
| | | |
| | | logger.debug(LocalizableMessage.raw( |
| | | "Connection attempt failed: availableConnections=%d, maxPoolSize=%d", |
| | |
| | | * {@link LdapPromise#get()} method throwing an {@link LdapException}. |
| | | * <p> |
| | | * In addition to returning a {@link LdapPromise}, all asynchronous methods |
| | | * accept a {@link ResultHandler} which will be notified upon completion of the |
| | | * accept a {@link LdapResultHandler} which will be notified upon completion of the |
| | | * operation. |
| | | * <p> |
| | | * Synchronous operations are easily simulated by immediately getting the |
| | |
| | | * </pre> |
| | | * |
| | | * More complex client applications can take advantage of a fully asynchronous |
| | | * event driven design using {@link ResultHandler}s: |
| | | * event driven design using {@link LdapResultHandler}s: |
| | | * |
| | | * <pre> |
| | | * Connection connection = ...; |
| | |
| | | import org.forgerock.opendj.ldap.schema.UnknownSchemaElementException; |
| | | import org.forgerock.opendj.ldif.LDIF; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | import com.forgerock.opendj.util.Iterables; |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | |
| | | import org.forgerock.opendj.ldap.spi.ConnectionState; |
| | | import org.forgerock.opendj.ldap.spi.LdapPromiseImpl; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.AsyncFunction; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.PromiseImpl; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | |
| | | import com.forgerock.opendj.util.ReferenceCountedObject; |
| | | import org.forgerock.util.time.TimeService; |
| | |
| | | * List of pending responses for all active operations. These will be |
| | | * signaled if no heart beat is detected within the permitted timeout period. |
| | | */ |
| | | private final Queue<ResultHandler<?>> pendingResults = new ConcurrentLinkedQueue<>(); |
| | | private final Queue<LdapResultHandler<?>> pendingResults = new ConcurrentLinkedQueue<>(); |
| | | |
| | | /** Internal connection state. */ |
| | | private final ConnectionState state = new ConnectionState(); |
| | |
| | | }; |
| | | |
| | | return timestampPromise(connection.searchAsync(request, |
| | | intermediateResponseHandler, entryHandler).onSuccessOrFailure(new Runnable() { |
| | | intermediateResponseHandler, entryHandler).thenOnResultOrException(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | searchDone.getAndSet(true); |
| | |
| | | * Peek instead of pool because notification is responsible for |
| | | * removing the element from the queue. |
| | | */ |
| | | ResultHandler<?> pendingResult; |
| | | LdapResultHandler<?> pendingResult; |
| | | while ((pendingResult = pendingResults.peek()) != null) { |
| | | pendingResult.handleError(error); |
| | | pendingResult.handleException(error); |
| | | } |
| | | } |
| | | |
| | |
| | | timestamp(reference); |
| | | return true; |
| | | } |
| | | }).onSuccess(new SuccessHandler<Result>() { |
| | | }).thenOnResult(new org.forgerock.util.promise.ResultHandler<Result>() { |
| | | @Override |
| | | public void handleResult(Result result) { |
| | | timestamp(result); |
| | | releaseHeartBeatLock(); |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(LdapException error) { |
| | | public void handleException(LdapException exception) { |
| | | /* |
| | | * Connection failure will be handled by connection |
| | | * event listener. Ignore cancellation errors since |
| | | * these indicate that the heart beat was aborted by |
| | | * a client-side close. |
| | | */ |
| | | if (!(error instanceof CancelledResultException)) { |
| | | if (!(exception instanceof CancelledResultException)) { |
| | | /* |
| | | * Log at debug level to avoid polluting the |
| | | * logs with benign password policy related |
| | | * errors. See OPENDJ-1168 and OPENDJ-1167. |
| | | */ |
| | | logger.debug(LocalizableMessage.raw("Heartbeat failed for connection factory '%s'", |
| | | factory, error)); |
| | | timestamp(error); |
| | | factory, exception)); |
| | | timestamp(exception); |
| | | } |
| | | releaseHeartBeatLock(); |
| | | } |
| | |
| | | private <R extends Result> LdapPromise<R> timestampPromise(LdapPromise<R> wrappedPromise) { |
| | | final LdapPromiseImpl<R> outerPromise = new LdapPromiseImplWrapper<>(wrappedPromise); |
| | | pendingResults.add(outerPromise); |
| | | wrappedPromise.onSuccess(new SuccessHandler<R>() { |
| | | wrappedPromise.thenOnResult(new ResultHandler<R>() { |
| | | @Override |
| | | public void handleResult(R result) { |
| | | outerPromise.handleResult(result); |
| | | timestamp(result); |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(LdapException error) { |
| | | outerPromise.handleError(error); |
| | | timestamp(error); |
| | | public void handleException(LdapException exception) { |
| | | outerPromise.handleException(exception); |
| | | timestamp(exception); |
| | | } |
| | | }); |
| | | outerPromise.onSuccessOrFailure(new Runnable() { |
| | | outerPromise.thenOnResultOrException(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pendingResults.remove(outerPromise); |
| | | } |
| | | }); |
| | | if (!checkState()) { |
| | | outerPromise.handleError(state.getConnectionError()); |
| | | outerPromise.handleException(state.getConnectionError()); |
| | | } |
| | | return outerPromise; |
| | | } |
| | | |
| | | private <R extends Result> LdapPromise<R> timestampBindOrStartTLSPromise(LdapPromise<R> wrappedPromise) { |
| | | return timestampPromise(wrappedPromise).onSuccessOrFailure(new Runnable() { |
| | | return timestampPromise(wrappedPromise).thenOnResultOrException(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | releaseBindOrStartTLSLock(); |
| | |
| | | scheduler.get().schedule(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (promise.tryHandleError(newHeartBeatTimeoutError())) { |
| | | if (promise.tryHandleException(newHeartBeatTimeoutError())) { |
| | | closeSilently(connectionHolder.get()); |
| | | releaseScheduler(); |
| | | } |
| | |
| | | }, timeoutMS, TimeUnit.MILLISECONDS); |
| | | return connection.searchAsync(heartBeatRequest, null); |
| | | } |
| | | }).onSuccess(new SuccessHandler<Result>() { |
| | | }).thenOnResult(new ResultHandler<Result>() { |
| | | @Override |
| | | public void handleResult(Result result) { |
| | | final Connection connection = connectionHolder.get(); |
| | |
| | | connectionImpl.close(); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(LdapException error) { |
| | | if (promise.tryHandleError(adaptHeartBeatError(error))) { |
| | | public void handleException(LdapException exception) { |
| | | if (promise.tryHandleException(adaptHeartBeatError(exception))) { |
| | | closeSilently(connectionHolder.get()); |
| | | releaseScheduler(); |
| | | } |
| | |
| | | return newFailedLdapPromise(e); |
| | | } |
| | | |
| | | return newSuccessfulPromise((Connection) new InternalConnection(serverConnection)); |
| | | return newResultPromise((Connection) new InternalConnection(serverConnection)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS |
| | | * Portions copyright 2014-2015 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import org.forgerock.util.promise.AsyncFunction; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | |
| | | /** |
| | | * A handle which can be used to retrieve the Result of an asynchronous Request. |
| | |
| | | int getRequestID(); |
| | | |
| | | @Override |
| | | LdapPromise<S> onSuccess(SuccessHandler<? super S> onSuccess); |
| | | LdapPromise<S> thenOnResult(ResultHandler<? super S> onResult); |
| | | |
| | | @Override |
| | | LdapPromise<S> onFailure(FailureHandler<? super LdapException> onFailure); |
| | | LdapPromise<S> thenOnException(ExceptionHandler<? super LdapException> onException); |
| | | |
| | | @Override |
| | | LdapPromise<S> onSuccessOrFailure(Runnable onSuccessOrFailure); |
| | | LdapPromise<S> thenOnResultOrException(Runnable onResultOrException); |
| | | |
| | | @Override |
| | | // @Checkstyle:ignore |
| | | <VOUT> LdapPromise<VOUT> then(Function<? super S, VOUT, LdapException> onSuccess); |
| | | <VOUT> LdapPromise<VOUT> then(Function<? super S, VOUT, LdapException> onResult); |
| | | |
| | | @Override |
| | | LdapPromise<S> then(SuccessHandler<? super S> onSuccess); |
| | | LdapPromise<S> thenOnResultOrException(ResultHandler<? super S> onResult, |
| | | ExceptionHandler<? super LdapException> onException); |
| | | |
| | | @Override |
| | | LdapPromise<S> then(SuccessHandler<? super S> onSuccess, FailureHandler<? super LdapException> onFailure); |
| | | |
| | | @Override |
| | | LdapPromise<S> thenAlways(Runnable onSuccessOrFailure); |
| | | LdapPromise<S> thenAlways(Runnable onResultOrException); |
| | | |
| | | @Override |
| | | // @Checkstyle:ignore |
| | | <VOUT> LdapPromise<VOUT> thenAsync(AsyncFunction<? super S, VOUT, LdapException> onSuccess); |
| | | <VOUT> LdapPromise<VOUT> thenAsync(AsyncFunction<? super S, VOUT, LdapException> onResult); |
| | | } |
| File was renamed from opendj-core/src/main/java/org/forgerock/opendj/ldap/ResultHandler.java |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | |
| | | /** |
| | | * A completion handler for consuming the result of an asynchronous operation or |
| | |
| | | * asynchronously to a remote Directory Server using an |
| | | * {@link ConnectionFactory}. The {@link #handleResult} method is invoked when |
| | | * the operation or connection attempt completes successfully. The |
| | | * {@link #handleError(LdapException)} method is invoked if the operation or connection |
| | | * {@link #handleException(LdapException)} method is invoked if the operation or connection |
| | | * attempt fails. |
| | | * <p> |
| | | * Implementations of these methods should complete in a timely manner so as to |
| | |
| | | * @param <S> |
| | | * The type of result handled by this result handler. |
| | | */ |
| | | public interface ResultHandler<S> extends SuccessHandler<S>, FailureHandler<LdapException> { |
| | | public interface LdapResultHandler<S> extends ResultHandler<S>, ExceptionHandler<LdapException> { |
| | | /** |
| | | * Invoked when the asynchronous operation has failed. |
| | | * |
| | | * @param error |
| | | * @param exception |
| | | * The error result exception indicating why the asynchronous |
| | | * operation has failed. |
| | | */ |
| | | void handleError(LdapException error); |
| | | @Override |
| | | void handleException(LdapException exception); |
| | | |
| | | /** |
| | | * Invoked when the asynchronous operation has completed successfully. |
| | |
| | | * @param result |
| | | * The result of the asynchronous operation. |
| | | */ |
| | | @Override |
| | | void handleResult(S result); |
| | | } |
| | |
| | | try { |
| | | factory = algorithm.getConnectionFactory(); |
| | | } catch (final LdapException e) { |
| | | return newFailedPromise(e); |
| | | return newExceptionPromise(e); |
| | | } |
| | | |
| | | return factory.getConnectionAsync(); |
| | |
| | | @Override |
| | | public void handleAdd(final RequestContext requestContext, final AddRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | try { |
| | | synchronized (writeLock) { |
| | | final DN dn = request.getName(); |
| | |
| | | } |
| | | resultHandler.handleResult(getResult(request, null, request)); |
| | | } catch (final LdapException e) { |
| | | resultHandler.handleError(e); |
| | | resultHandler.handleException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | public void handleBind(final RequestContext requestContext, final int version, |
| | | final BindRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<BindResult> resultHandler) { |
| | | final LdapResultHandler<BindResult> resultHandler) { |
| | | try { |
| | | final Entry entry; |
| | | synchronized (writeLock) { |
| | |
| | | } |
| | | resultHandler.handleResult(getBindResult(request, entry, entry)); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | resultHandler.handleError(newLdapException(ResultCode.PROTOCOL_ERROR, e)); |
| | | resultHandler.handleException(newLdapException(ResultCode.PROTOCOL_ERROR, e)); |
| | | } catch (final EntryNotFoundException e) { |
| | | /* |
| | | * Usually you would not include a diagnostic message, but we'll add |
| | | * one here because the memory back-end is not intended for |
| | | * production use. |
| | | */ |
| | | resultHandler.handleError(newLdapException(ResultCode.INVALID_CREDENTIALS, "Unknown user")); |
| | | resultHandler.handleException(newLdapException(ResultCode.INVALID_CREDENTIALS, "Unknown user")); |
| | | } catch (final LdapException e) { |
| | | resultHandler.handleError(e); |
| | | resultHandler.handleException(e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void handleCompare(final RequestContext requestContext, final CompareRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<CompareResult> resultHandler) { |
| | | final LdapResultHandler<CompareResult> resultHandler) { |
| | | try { |
| | | final Entry entry; |
| | | final Attribute assertion; |
| | |
| | | resultHandler.handleResult(getCompareResult(request, entry, entry.containsAttribute( |
| | | assertion, null))); |
| | | } catch (final LdapException e) { |
| | | resultHandler.handleError(e); |
| | | resultHandler.handleException(e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void handleDelete(final RequestContext requestContext, final DeleteRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | try { |
| | | final Entry entry; |
| | | synchronized (writeLock) { |
| | |
| | | } |
| | | resultHandler.handleResult(getResult(request, entry, null)); |
| | | } catch (final DecodeException e) { |
| | | resultHandler.handleError(newLdapException(ResultCode.PROTOCOL_ERROR, e)); |
| | | resultHandler.handleException(newLdapException(ResultCode.PROTOCOL_ERROR, e)); |
| | | } catch (final LdapException e) { |
| | | resultHandler.handleError(e); |
| | | resultHandler.handleException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | public <R extends ExtendedResult> void handleExtendedRequest( |
| | | final RequestContext requestContext, final ExtendedRequest<R> request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<R> resultHandler) { |
| | | resultHandler.handleError(newLdapException(ResultCode.UNWILLING_TO_PERFORM, |
| | | final LdapResultHandler<R> resultHandler) { |
| | | resultHandler.handleException(newLdapException(ResultCode.UNWILLING_TO_PERFORM, |
| | | "Extended request operation not supported")); |
| | | } |
| | | |
| | | @Override |
| | | public void handleModify(final RequestContext requestContext, final ModifyRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | try { |
| | | final Entry entry; |
| | | final Entry newEntry; |
| | |
| | | } |
| | | resultHandler.handleResult(getResult(request, entry, newEntry)); |
| | | } catch (final LdapException e) { |
| | | resultHandler.handleError(e); |
| | | resultHandler.handleException(e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void handleModifyDN(final RequestContext requestContext, final ModifyDNRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | resultHandler.handleError(newLdapException(ResultCode.UNWILLING_TO_PERFORM, |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | resultHandler.handleException(newLdapException(ResultCode.UNWILLING_TO_PERFORM, |
| | | "ModifyDN request operation not supported")); |
| | | } |
| | | |
| | | @Override |
| | | public void handleSearch(final RequestContext requestContext, final SearchRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final SearchResultHandler entryHandler, |
| | | ResultHandler<Result> resultHandler) { |
| | | LdapResultHandler<Result> resultHandler) { |
| | | try { |
| | | final DN dn = request.getName(); |
| | | final SearchScope scope = request.getScope(); |
| | |
| | | "Search request contains an unsupported search scope"); |
| | | } |
| | | } catch (DecodeException e) { |
| | | resultHandler.handleError(newLdapException(ResultCode.PROTOCOL_ERROR, e.getMessage(), e)); |
| | | resultHandler.handleException(newLdapException(ResultCode.PROTOCOL_ERROR, e.getMessage(), e)); |
| | | } catch (final LdapException e) { |
| | | resultHandler.handleError(e); |
| | | resultHandler.handleException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | * If the request is unsuccessful. |
| | | */ |
| | | private void searchWithSubordinates(final RequestContext requestContext, final SearchResultHandler entryHandler, |
| | | final ResultHandler<Result> resultHandler, final DN dn, final Matcher matcher, |
| | | final LdapResultHandler<Result> resultHandler, final DN dn, final Matcher matcher, |
| | | final AttributeFilter attributeFilter, final int sizeLimit, SearchScope scope, |
| | | SimplePagedResultsControl pagedResults) throws CancelledResultException, LdapException { |
| | | final int pageSize = pagedResults != null ? pagedResults.getSize() : 0; |
| | |
| | | * A handler interface for processing client requests. |
| | | * <p> |
| | | * Implementations must always return results using the provided |
| | | * {@link ResultHandler} unless explicitly permitted. |
| | | * {@link LdapResultHandler} unless explicitly permitted. |
| | | * <p> |
| | | * For example, an {@link LDAPListener} does not require {@code RequestHandler} |
| | | * implementations to return results, which may be useful when implementing |
| | |
| | | */ |
| | | void handleAdd(C requestContext, AddRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<Result> resultHandler); |
| | | LdapResultHandler<Result> resultHandler); |
| | | |
| | | /** |
| | | * Invoked when a bind request is received from a client. |
| | |
| | | */ |
| | | void handleBind(C requestContext, int version, BindRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<BindResult> resultHandler); |
| | | LdapResultHandler<BindResult> resultHandler); |
| | | |
| | | /** |
| | | * Invoked when a compare request is received from a client. |
| | |
| | | */ |
| | | void handleCompare(C requestContext, CompareRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<CompareResult> resultHandler); |
| | | LdapResultHandler<CompareResult> resultHandler); |
| | | |
| | | /** |
| | | * Invoked when a delete request is received from a client. |
| | |
| | | */ |
| | | void handleDelete(C requestContext, DeleteRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<Result> resultHandler); |
| | | LdapResultHandler<Result> resultHandler); |
| | | |
| | | /** |
| | | * Invoked when an extended request is received from a client. |
| | |
| | | */ |
| | | <R extends ExtendedResult> void handleExtendedRequest(C requestContext, |
| | | ExtendedRequest<R> request, IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<R> resultHandler); |
| | | LdapResultHandler<R> resultHandler); |
| | | |
| | | /** |
| | | * Invoked when a modify request is received from a client. |
| | |
| | | */ |
| | | void handleModify(C requestContext, ModifyRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<Result> resultHandler); |
| | | LdapResultHandler<Result> resultHandler); |
| | | |
| | | /** |
| | | * Invoked when a modify DN request is received from a client. |
| | |
| | | */ |
| | | void handleModifyDN(C requestContext, ModifyDNRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<Result> resultHandler); |
| | | LdapResultHandler<Result> resultHandler); |
| | | |
| | | /** |
| | | * Invoked when a search request is received from a client. |
| | |
| | | */ |
| | | void handleSearch(C requestContext, SearchRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, SearchResultHandler entryHandler, |
| | | ResultHandler<Result> resultHandler); |
| | | LdapResultHandler<Result> resultHandler); |
| | | } |
| | |
| | | /** |
| | | * Request context implementation. |
| | | */ |
| | | private static class RequestContextImpl<S extends Result, H extends ResultHandler<S>> |
| | | implements RequestContext, ResultHandler<S> { |
| | | private static class RequestContextImpl<S extends Result, H extends LdapResultHandler<S>> |
| | | implements RequestContext, LdapResultHandler<S> { |
| | | |
| | | /** |
| | | * Adapter class which invokes cancel result handlers with correct |
| | |
| | | */ |
| | | private static final class ExtendedResultHandlerHolder<R extends ExtendedResult> { |
| | | private final ExtendedRequest<R> request; |
| | | private final ResultHandler<R> resultHandler; |
| | | private final LdapResultHandler<R> resultHandler; |
| | | |
| | | private ExtendedResultHandlerHolder(final ExtendedRequest<R> request, |
| | | final ResultHandler<R> resultHandler) { |
| | | final LdapResultHandler<R> resultHandler) { |
| | | this.request = request; |
| | | this.resultHandler = resultHandler; |
| | | } |
| | |
| | | final R cancelResult = |
| | | request.getResultDecoder().newExtendedErrorResult(ResultCode.TOO_LATE, "", |
| | | ""); |
| | | resultHandler.handleError(newLdapException(cancelResult)); |
| | | resultHandler.handleException(newLdapException(cancelResult)); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException error) { |
| | | if (clientConnection.removePendingRequest(this)) { |
| | | if (setResult(error.getResult())) { |
| | | /* |
| | |
| | | * not be sent to the client. |
| | | */ |
| | | } |
| | | resultHandler.handleError(error); |
| | | resultHandler.handleException(error); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | private <R extends ExtendedResult> void cancel(final LocalizableMessage reason, |
| | | final ExtendedRequest<R> cancelRequest, final ResultHandler<R> cancelResultHandler, |
| | | final ExtendedRequest<R> cancelRequest, final LdapResultHandler<R> cancelResultHandler, |
| | | final boolean sendResult) { |
| | | Reject.ifNull(reason); |
| | | |
| | |
| | | if (cancelResultHandler != null) { |
| | | final Result result = |
| | | Responses.newGenericExtendedResult(ResultCode.CANNOT_CANCEL); |
| | | cancelResultHandler.handleError(newLdapException(result)); |
| | | cancelResultHandler.handleException(newLdapException(result)); |
| | | } |
| | | return; |
| | | } |
| | |
| | | cancelResultHandler.handleResult(result); |
| | | } else { |
| | | final Result result = Responses.newGenericExtendedResult(ResultCode.TOO_LATE); |
| | | cancelResultHandler.handleError(newLdapException(result)); |
| | | cancelResultHandler.handleException(newLdapException(result)); |
| | | } |
| | | } |
| | | } |
| | |
| | | /** |
| | | * Search request context implementation. |
| | | */ |
| | | private static final class SearchRequestContextImpl extends RequestContextImpl<Result, ResultHandler<Result>> |
| | | private static final class SearchRequestContextImpl extends RequestContextImpl<Result, LdapResultHandler<Result>> |
| | | implements SearchResultHandler { |
| | | |
| | | private final SearchResultHandler entryHandler; |
| | | |
| | | private SearchRequestContextImpl(final ServerConnectionImpl clientConnection, |
| | | final SearchResultHandler entryHandler, final ResultHandler<Result> resultHandler, final int messageID, |
| | | final SearchResultHandler entryHandler, final LdapResultHandler<Result> resultHandler, final int messageID, |
| | | final boolean isCancelSupported) { |
| | | super(clientConnection, resultHandler, messageID, isCancelSupported); |
| | | this.entryHandler = entryHandler; |
| | |
| | | @Override |
| | | public void handleAdd(final Integer messageID, final AddRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final RequestContextImpl<Result, ResultHandler<Result>> requestContext = |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | final RequestContextImpl<Result, LdapResultHandler<Result>> requestContext = |
| | | new RequestContextImpl<>(this, resultHandler, messageID, true); |
| | | if (addPendingRequest(requestContext)) { |
| | | requestHandler.handleAdd(requestContext, request, intermediateResponseHandler, |
| | |
| | | public void handleBind(final Integer messageID, final int version, |
| | | final BindRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<BindResult> resultHandler) { |
| | | final RequestContextImpl<BindResult, ResultHandler<BindResult>> requestContext = |
| | | final LdapResultHandler<BindResult> resultHandler) { |
| | | final RequestContextImpl<BindResult, LdapResultHandler<BindResult>> requestContext = |
| | | new RequestContextImpl<>(this, resultHandler, messageID, false); |
| | | if (addPendingRequest(requestContext)) { |
| | | requestHandler.handleBind(requestContext, version, request, |
| | |
| | | @Override |
| | | public void handleCompare(final Integer messageID, final CompareRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<CompareResult> resultHandler) { |
| | | final RequestContextImpl<CompareResult, ResultHandler<CompareResult>> requestContext = |
| | | final LdapResultHandler<CompareResult> resultHandler) { |
| | | final RequestContextImpl<CompareResult, LdapResultHandler<CompareResult>> requestContext = |
| | | new RequestContextImpl<>(this, resultHandler, messageID, true); |
| | | if (addPendingRequest(requestContext)) { |
| | | requestHandler.handleCompare(requestContext, request, intermediateResponseHandler, |
| | |
| | | @Override |
| | | public void handleDelete(final Integer messageID, final DeleteRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final RequestContextImpl<Result, ResultHandler<Result>> requestContext = |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | final RequestContextImpl<Result, LdapResultHandler<Result>> requestContext = |
| | | new RequestContextImpl<>(this, resultHandler, messageID, true); |
| | | if (addPendingRequest(requestContext)) { |
| | | requestHandler.handleDelete(requestContext, request, intermediateResponseHandler, |
| | |
| | | public <R extends ExtendedResult> void handleExtendedRequest(final Integer messageID, |
| | | final ExtendedRequest<R> request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<R> resultHandler) { |
| | | final LdapResultHandler<R> resultHandler) { |
| | | if (request.getOID().equals(CancelExtendedRequest.OID)) { |
| | | // Decode the request as a cancel request. |
| | | CancelExtendedRequest cancelRequest; |
| | |
| | | new DecodeOptions()); |
| | | } catch (final DecodeException e) { |
| | | // Couldn't decode a cancel request. |
| | | resultHandler.handleError(newLdapException(ResultCode.PROTOCOL_ERROR, e |
| | | resultHandler.handleException(newLdapException(ResultCode.PROTOCOL_ERROR, e |
| | | .getLocalizedMessage())); |
| | | return; |
| | | } |
| | |
| | | * though this request cannot be cancelled, it is important to |
| | | * do this in order to monitor the number of pending operations. |
| | | */ |
| | | final RequestContextImpl<R, ResultHandler<R>> requestContext = |
| | | final RequestContextImpl<R, LdapResultHandler<R>> requestContext = |
| | | new RequestContextImpl<>(this, resultHandler, messageID, false); |
| | | if (addPendingRequest(requestContext)) { |
| | | // Find and cancel the request. |
| | |
| | | * Couldn't find the request. Invoke on context in order |
| | | * to remove pending request. |
| | | */ |
| | | requestContext.handleError(newLdapException(ResultCode.NO_SUCH_OPERATION)); |
| | | requestContext.handleException(newLdapException(ResultCode.NO_SUCH_OPERATION)); |
| | | } |
| | | } |
| | | } else { |
| | | // StartTLS requests cannot be cancelled. |
| | | boolean isCancelSupported = !request.getOID().equals(StartTLSExtendedRequest.OID); |
| | | final RequestContextImpl<R, ResultHandler<R>> requestContext = |
| | | final RequestContextImpl<R, LdapResultHandler<R>> requestContext = |
| | | new RequestContextImpl<>(this, resultHandler, messageID, isCancelSupported); |
| | | |
| | | if (addPendingRequest(requestContext)) { |
| | |
| | | @Override |
| | | public void handleModify(final Integer messageID, final ModifyRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final RequestContextImpl<Result, ResultHandler<Result>> requestContext = |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | final RequestContextImpl<Result, LdapResultHandler<Result>> requestContext = |
| | | new RequestContextImpl<>(this, resultHandler, messageID, true); |
| | | if (addPendingRequest(requestContext)) { |
| | | requestHandler.handleModify(requestContext, request, intermediateResponseHandler, |
| | |
| | | @Override |
| | | public void handleModifyDN(final Integer messageID, final ModifyDNRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final RequestContextImpl<Result, ResultHandler<Result>> requestContext = |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | final RequestContextImpl<Result, LdapResultHandler<Result>> requestContext = |
| | | new RequestContextImpl<>(this, resultHandler, messageID, true); |
| | | if (addPendingRequest(requestContext)) { |
| | | requestHandler.handleModifyDN(requestContext, request, intermediateResponseHandler, |
| | |
| | | @Override |
| | | public void handleSearch(final Integer messageID, final SearchRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final SearchResultHandler entryHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | final SearchRequestContextImpl requestContext = |
| | | new SearchRequestContextImpl(this, entryHandler, resultHandler, messageID, true); |
| | | if (addPendingRequest(requestContext)) { |
| | |
| | | |
| | | if (isClosed.get()) { |
| | | final LocalizableMessage message = INFO_CLIENT_CONNECTION_CLOSING.get(); |
| | | requestContext.handleError(newLdapException(ResultCode.UNWILLING_TO_PERFORM, |
| | | requestContext.handleException(newLdapException(ResultCode.UNWILLING_TO_PERFORM, |
| | | message.toString())); |
| | | return false; |
| | | } else if (pendingRequests.putIfAbsent(messageID, requestContext) != null) { |
| | | final LocalizableMessage message = |
| | | WARN_CLIENT_DUPLICATE_MESSAGE_ID.get(requestContext.getMessageID()); |
| | | requestContext.handleError(newLdapException(ResultCode.PROTOCOL_ERROR, message.toString())); |
| | | requestContext.handleException(newLdapException(ResultCode.PROTOCOL_ERROR, message.toString())); |
| | | return false; |
| | | } else if (isClosed.get()) { |
| | | /* |
| | |
| | | pendingRequests.remove(messageID); |
| | | |
| | | final LocalizableMessage message = INFO_CLIENT_CONNECTION_CLOSING.get(); |
| | | requestContext.handleError(newLdapException(ResultCode.UNWILLING_TO_PERFORM, message.toString())); |
| | | requestContext.handleException(newLdapException(ResultCode.UNWILLING_TO_PERFORM, message.toString())); |
| | | return false; |
| | | } else { |
| | | /* |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.schema.CoreSchema; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | import com.forgerock.opendj.util.Collections2; |
| | |
| | | * If the {@code connection} was {@code null}. |
| | | */ |
| | | public static LdapPromise<RootDSE> readRootDSEAsync(final Connection connection, |
| | | final ResultHandler<? super RootDSE> handler) { |
| | | final LdapResultHandler<? super RootDSE> handler) { |
| | | return connection.searchSingleEntryAsync(SEARCH_REQUEST).then( |
| | | new Function<SearchResultEntry, RootDSE, LdapException>() { |
| | | @Override |
| | |
| | | * private static class MySearchResultHandler implements SearchResultHandler { |
| | | * |
| | | * {@literal @}Override |
| | | * public void handleErrorResult(LdapException error) { |
| | | * public void handleExceptionResult(LdapException error) { |
| | | * // Ignore. |
| | | * } |
| | | * |
| | |
| | | * private static class MySearchResultHandler implements SearchResultHandler { |
| | | * |
| | | * {@literal @}Override |
| | | * public void handleErrorResult(LdapException error) { |
| | | * public void handleExceptionResult(LdapException error) { |
| | | * // Ignore. |
| | | * } |
| | | * |
| | |
| | | * private static class MySearchResultHandler implements SearchResultHandler { |
| | | * |
| | | * {@literal @}Override |
| | | * public void handleErrorResult(LdapException error) { |
| | | * public void handleExceptionResult(LdapException error) { |
| | | * // Ignore. |
| | | * } |
| | | * |
| | |
| | | import org.forgerock.opendj.ldap.controls.ControlDecoder; |
| | | import org.forgerock.opendj.ldap.controls.GenericControl; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | import com.forgerock.opendj.util.Collections2; |
| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | |
| | | import org.forgerock.opendj.ldif.ChangeRecordVisitor; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | import com.forgerock.opendj.util.Iterables; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.Modification; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldif.ChangeRecordVisitor; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | import com.forgerock.opendj.util.Collections2; |
| | |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.requests.ExtendedRequest; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | @Override |
| | | public <R extends ExtendedResult> ResultHandler<S> adaptExtendedResultHandler( |
| | | final ExtendedRequest<R> request, final ResultHandler<? super R> resultHandler, |
| | | public <R extends ExtendedResult> LdapResultHandler<S> adaptExtendedResultHandler( |
| | | final ExtendedRequest<R> request, final LdapResultHandler<? super R> resultHandler, |
| | | final DecodeOptions options) { |
| | | return new ResultHandler<S>() { |
| | | return new LdapResultHandler<S>() { |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException error) { |
| | | final Result result = error.getResult(); |
| | | final R adaptedResult = |
| | | request.getResultDecoder().newExtendedErrorResult(result.getResultCode(), |
| | | result.getMatchedDN(), result.getDiagnosticMessage()); |
| | | adaptedResult.setCause(result.getCause()); |
| | | resultHandler.handleError(newLdapException(adaptedResult)); |
| | | resultHandler.handleException(newLdapException(adaptedResult)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | resultHandler.handleResult(adaptedResult); |
| | | } catch (final DecodeException e) { |
| | | final R adaptedResult = request.getResultDecoder().adaptDecodeException(e); |
| | | resultHandler.handleError(newLdapException(adaptedResult)); |
| | | resultHandler.handleException(newLdapException(adaptedResult)); |
| | | } |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.controls.ControlDecoder; |
| | | import org.forgerock.opendj.ldap.controls.GenericControl; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | import com.forgerock.opendj.util.Collections2; |
| | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.requests.ExtendedRequest; |
| | | |
| | | /** |
| | |
| | | * @return A result handler which is compatible with this extended result |
| | | * decoder. |
| | | */ |
| | | <R extends ExtendedResult> ResultHandler<S> adaptExtendedResultHandler( |
| | | ExtendedRequest<R> request, ResultHandler<? super R> resultHandler, DecodeOptions options); |
| | | <R extends ExtendedResult> LdapResultHandler<S> adaptExtendedResultHandler( |
| | | ExtendedRequest<R> request, LdapResultHandler<? super R> resultHandler, DecodeOptions options); |
| | | |
| | | /** |
| | | * Decodes the provided extended operation result as a {@code Result} of |
| | |
| | | import org.forgerock.opendj.ldap.Attributes; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | import com.forgerock.opendj.util.Iterables; |
| | |
| | | import org.forgerock.opendj.ldap.Option; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.schema.DITContentRule.Builder; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.AsyncFunction; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.Promise; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LdapPromise; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.PromiseImpl; |
| | | import org.forgerock.util.promise.Promises; |
| | |
| | | * @see LdapPromise |
| | | */ |
| | | public class LdapPromiseImpl<S> extends LdapPromiseWrapper<S, PromiseImpl<S, LdapException>> implements |
| | | LdapPromise<S>, ResultHandler<S> { |
| | | LdapPromise<S>, LdapResultHandler<S> { |
| | | |
| | | /** |
| | | * Creates a new {@link LdapPromiseImpl} from a wrapped existing {@link PromiseImpl}. |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(LdapException error) { |
| | | getWrappedPromise().handleError(error); |
| | | public void handleException(LdapException exception) { |
| | | getWrappedPromise().handleException(exception); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LdapPromise; |
| | | import org.forgerock.util.promise.AsyncFunction; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | |
| | | import static org.forgerock.opendj.ldap.spi.LdapPromises.*; |
| | | |
| | |
| | | * |
| | | * |
| | | * This wrapper allows client code to return {@link LdapPromise} instance when |
| | | * using {@link Promise} chaining methods (e.g onSuccess(), then(), thenAsync()). |
| | | * using {@link Promise} chaining methods (e.g thenOnResult(), then(), thenAsync()). |
| | | * Wrapping is specially needed with {@link Promise} method which are not returning the original promise. |
| | | * |
| | | * @param <R> |
| | |
| | | } |
| | | |
| | | @Override |
| | | public LdapPromise<R> onFailure(FailureHandler<? super LdapException> onFailure) { |
| | | wrappedPromise.onFailure(onFailure); |
| | | public LdapPromise<R> thenOnException(ExceptionHandler<? super LdapException> onException) { |
| | | wrappedPromise.thenOnException(onException); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | public LdapPromise<R> onSuccess(SuccessHandler<? super R> onSuccess) { |
| | | wrappedPromise.onSuccess(onSuccess); |
| | | public LdapPromise<R> thenOnResult(ResultHandler<? super R> onResult) { |
| | | wrappedPromise.thenOnResult(onResult); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | public LdapPromise<R> onSuccessOrFailure(Runnable onSuccessOrFailure) { |
| | | wrappedPromise.onSuccessOrFailure(onSuccessOrFailure); |
| | | public LdapPromise<R> thenOnResultOrException(Runnable onResultOrException) { |
| | | wrappedPromise.thenOnResultOrException(onResultOrException); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | // @Checkstyle:ignore |
| | | public <VOUT> LdapPromise<VOUT> then(Function<? super R, VOUT, LdapException> onSuccess) { |
| | | return wrap(wrappedPromise.then(onSuccess), getRequestID()); |
| | | public <VOUT> LdapPromise<VOUT> then(Function<? super R, VOUT, LdapException> onResult) { |
| | | return wrap(wrappedPromise.then(onResult), getRequestID()); |
| | | } |
| | | |
| | | @Override |
| | | // @Checkstyle:ignore |
| | | public <VOUT, EOUT extends Exception> Promise<VOUT, EOUT> then(Function<? super R, VOUT, EOUT> onSuccess, |
| | | Function<? super LdapException, VOUT, EOUT> onFailure) { |
| | | return wrappedPromise.then(onSuccess, onFailure); |
| | | public <VOUT, EOUT extends Exception> Promise<VOUT, EOUT> then(Function<? super R, VOUT, EOUT> onResult, |
| | | Function<? super LdapException, VOUT, EOUT> onException) { |
| | | return wrappedPromise.then(onResult, onException); |
| | | } |
| | | |
| | | @Override |
| | | public LdapPromise<R> then(SuccessHandler<? super R> onSuccess) { |
| | | wrappedPromise.then(onSuccess); |
| | | public LdapPromise<R> thenOnResultOrException(ResultHandler<? super R> onResult, |
| | | ExceptionHandler<? super LdapException> onException) { |
| | | wrappedPromise.thenOnResultOrException(onResult, onException); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | public LdapPromise<R> then(SuccessHandler<? super R> onSuccess, |
| | | FailureHandler<? super LdapException> onFailure) { |
| | | wrappedPromise.then(onSuccess, onFailure); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | public LdapPromise<R> thenAlways(Runnable onSuccessOrFailure) { |
| | | wrappedPromise.thenAlways(onSuccessOrFailure); |
| | | public LdapPromise<R> thenAlways(Runnable onResultOrException) { |
| | | wrappedPromise.thenAlways(onResultOrException); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | // @Checkstyle:ignore |
| | | public <VOUT> LdapPromise<VOUT> thenAsync(AsyncFunction<? super R, VOUT, LdapException> onSuccess) { |
| | | return wrap(wrappedPromise.thenAsync(onSuccess), getRequestID()); |
| | | public <VOUT> LdapPromise<VOUT> thenAsync(AsyncFunction<? super R, VOUT, LdapException> onResult) { |
| | | return wrap(wrappedPromise.thenAsync(onResult), getRequestID()); |
| | | } |
| | | |
| | | @Override |
| | | // @Checkstyle:ignore |
| | | public <VOUT, EOUT extends Exception> Promise<VOUT, EOUT> thenAsync( |
| | | AsyncFunction<? super R, VOUT, EOUT> onSuccess, |
| | | AsyncFunction<? super LdapException, VOUT, EOUT> onFailure) { |
| | | return wrappedPromise.thenAsync(onSuccess, onFailure); |
| | | AsyncFunction<? super R, VOUT, EOUT> onResult, |
| | | AsyncFunction<? super LdapException, VOUT, EOUT> onException) { |
| | | return wrappedPromise.thenAsync(onResult, onException); |
| | | } |
| | | |
| | | @Override |
| | | // @Checkstyle:ignore |
| | | public <EOUT extends Exception> Promise<R, EOUT> thenCatch(Function<? super LdapException, R, EOUT> onException) { |
| | | return wrappedPromise.thenCatch(onException); |
| | | } |
| | | |
| | | @Override |
| | | // @Checkstyle:ignore |
| | | public LdapPromise<R> thenFinally(Runnable onResultOrException) { |
| | | wrappedPromise.thenFinally(onResultOrException); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | // @Checkstyle:ignore |
| | | public <EOUT extends Exception> Promise<R, EOUT> thenCatchAsync( |
| | | AsyncFunction<? super LdapException, R, EOUT> onException) { |
| | | return null; |
| | | } |
| | | |
| | | public P getWrappedPromise() { |
| | |
| | | * already succeeded with the provided result. |
| | | */ |
| | | public static <R> LdapPromise<R> newSuccessfulLdapPromise(final R result) { |
| | | return wrap(Promises.<R, LdapException> newSuccessfulPromise(result), -1); |
| | | return wrap(Promises.<R, LdapException> newResultPromise(result), -1); |
| | | } |
| | | |
| | | /** |
| | |
| | | * already succeeded with the provided result. |
| | | */ |
| | | public static <R> LdapPromise<R> newSuccessfulLdapPromise(final R result, int requestID) { |
| | | return wrap(Promises.<R, LdapException> newSuccessfulPromise(result), requestID); |
| | | return wrap(Promises.<R, LdapException> newResultPromise(result), requestID); |
| | | } |
| | | |
| | | /** |
| | |
| | | * already failed with the provided error. |
| | | */ |
| | | public static <R, E extends LdapException> LdapPromise<R> newFailedLdapPromise(final E error) { |
| | | return wrap(Promises.<R, LdapException> newFailedPromise(error), -1); |
| | | return wrap(Promises.<R, LdapException> newExceptionPromise(error), -1); |
| | | } |
| | | |
| | | /** |
| | |
| | | * already failed with the provided error. |
| | | */ |
| | | public static <R, E extends LdapException> LdapPromise<R> newFailedLdapPromise(final E error, int requestID) { |
| | | return wrap(Promises.<R, LdapException> newFailedPromise(error), requestID); |
| | | return wrap(Promises.<R, LdapException> newExceptionPromise(error), requestID); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public final void setResultOrError(final S result) { |
| | | if (result.getResultCode().isExceptional()) { |
| | | getWrappedPromise().handleError(newLdapException(result)); |
| | | getWrappedPromise().handleException(newLdapException(result)); |
| | | } else { |
| | | getWrappedPromise().handleResult(result); |
| | | } |
| | |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LdapPromise; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | | import org.forgerock.opendj.ldap.SearchResultReferenceIOException; |
| | | import org.forgerock.opendj.ldap.requests.SearchRequest; |
| | |
| | | /** |
| | | * Result handler that places all responses in a queue. |
| | | */ |
| | | private static final class BufferHandler implements SearchResultHandler, ResultHandler<Result> { |
| | | private static final class BufferHandler implements SearchResultHandler, LdapResultHandler<Result> { |
| | | private final BlockingQueue<Response> responses; |
| | | private volatile boolean isInterrupted; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException error) { |
| | | try { |
| | | responses.put(error.getResult()); |
| | | } catch (final InterruptedException e) { |
| | |
| | | final BlockingQueue<Response> entries) { |
| | | Reject.ifNull(connection); |
| | | buffer = new BufferHandler(entries); |
| | | promise = connection.searchAsync(searchRequest, buffer).onSuccess(buffer).onFailure(buffer); |
| | | promise = connection.searchAsync(searchRequest, buffer).thenOnResult(buffer).thenOnException(buffer); |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.forgerock.opendj.ldap.responses.ExtendedResult; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.fest.assertions.Assertions.*; |
| | |
| | | final Connection mockConnection = new MockConnection(ResultCode.SUCCESS, entry); |
| | | final SearchRequest request = |
| | | newSingleEntrySearchRequest("cn=test", SearchScope.BASE_OBJECT, "(objectClass=*)"); |
| | | SuccessHandler<SearchResultEntry> successHandler = mock(SuccessHandler.class); |
| | | SearchResultEntry resultEntry = mockConnection.searchSingleEntryAsync(request).onSuccess(successHandler).get(); |
| | | ResultHandler<SearchResultEntry> resultHandler = mock(ResultHandler.class); |
| | | SearchResultEntry resultEntry = mockConnection.searchSingleEntryAsync(request) |
| | | .thenOnResult(resultHandler).get(); |
| | | assertThat(resultEntry).isEqualTo(entry); |
| | | verify(successHandler).handleResult(any(SearchResultEntry.class)); |
| | | verify(resultHandler).handleResult(any(SearchResultEntry.class)); |
| | | } |
| | | |
| | | @Test |
| | |
| | | newSearchResultEntry("cn=test")); |
| | | final SearchRequest request = |
| | | newSingleEntrySearchRequest("cn=test", SearchScope.BASE_OBJECT, "(objectClass=*)"); |
| | | FailureHandler<LdapException> failureHandler = mock(FailureHandler.class); |
| | | ExceptionHandler<LdapException> exceptionHandler = mock(ExceptionHandler.class); |
| | | |
| | | try { |
| | | mockConnection.searchSingleEntryAsync(request).onFailure(failureHandler).getOrThrow(); |
| | | mockConnection.searchSingleEntryAsync(request).thenOnException(exceptionHandler).getOrThrow(); |
| | | failWasExpected(MultipleEntriesFoundException.class); |
| | | } catch (MultipleEntriesFoundException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED); |
| | | verify(failureHandler).handleError(any(LdapException.class)); |
| | | verify(exceptionHandler).handleException(any(LdapException.class)); |
| | | } |
| | | } |
| | | |
| | |
| | | final SearchRequest request = newSingleEntrySearchRequest("cn=test", SearchScope.BASE_OBJECT, |
| | | "(objectClass=*)"); |
| | | @SuppressWarnings("unchecked") |
| | | FailureHandler<LdapException> failureHandler = mock(FailureHandler.class); |
| | | ExceptionHandler<LdapException> exceptionHandler = mock(ExceptionHandler.class); |
| | | try { |
| | | mockConnection.searchSingleEntryAsync(request).onFailure(failureHandler).getOrThrow(); |
| | | mockConnection.searchSingleEntryAsync(request).thenOnException(exceptionHandler).getOrThrow(); |
| | | failWasExpected(MultipleEntriesFoundException.class); |
| | | } catch (MultipleEntriesFoundException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED); |
| | | verify(failureHandler).handleError(any(LdapException.class)); |
| | | verify(exceptionHandler).handleException(any(LdapException.class)); |
| | | } |
| | | } |
| | | |
| | |
| | | final SearchRequest request = |
| | | newSingleEntrySearchRequest("cn=test", SearchScope.BASE_OBJECT, "(objectClass=*)"); |
| | | @SuppressWarnings("unchecked") |
| | | FailureHandler<LdapException> failureHandler = mock(FailureHandler.class); |
| | | ExceptionHandler<LdapException> exceptionHandler = mock(ExceptionHandler.class); |
| | | try { |
| | | mockConnection.searchSingleEntryAsync(request).onFailure(failureHandler).getOrThrow(); |
| | | mockConnection.searchSingleEntryAsync(request).thenOnException(exceptionHandler).getOrThrow(); |
| | | failWasExpected(LdapException.class); |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM); |
| | | verify(failureHandler).handleError(any(LdapException.class)); |
| | | verify(exceptionHandler).handleException(any(LdapException.class)); |
| | | } |
| | | } |
| | | |
| | |
| | | @Override |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | try { |
| | | return newSuccessfulPromise(mock.getConnection()); |
| | | return newResultPromise(mock.getConnection()); |
| | | } catch (final LdapException e) { |
| | | return newFailedPromise(e); |
| | | return newExceptionPromise(e); |
| | | } |
| | | } |
| | | |
| | |
| | | final LdapException connectError = newLdapException(ResultCode.CLIENT_SIDE_CONNECT_ERROR); |
| | | for (Promise<? extends Connection, LdapException> promise : promises) { |
| | | // Simulate that an error happened with the created connections |
| | | ((PromiseImpl) promise).handleError(connectError); |
| | | ((PromiseImpl) promise).handleException(connectError); |
| | | |
| | | try { |
| | | // Before the fix for OPENDJ-1348 the third promise.get() would hang. |
| | |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | import org.forgerock.opendj.ldap.spi.BindResultLdapPromiseImpl; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.PromiseImpl; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | import org.mockito.ArgumentCaptor; |
| | | import org.mockito.invocation.InvocationOnMock; |
| | | import org.mockito.stubbing.Answer; |
| | |
| | | @Test |
| | | public void testGetConnectionAsync() throws Exception { |
| | | @SuppressWarnings("unchecked") |
| | | final SuccessHandler<Connection> mockSuccessHandler = mock(SuccessHandler.class); |
| | | final ResultHandler<Connection> mockResultHandler = mock(ResultHandler.class); |
| | | |
| | | mockConnectionWithInitialHeartbeatResult(ResultCode.SUCCESS); |
| | | hbc = hbcf.getConnectionAsync().onSuccess(mockSuccessHandler).getOrThrow(); |
| | | hbc = hbcf.getConnectionAsync().thenOnResult(mockResultHandler).getOrThrow(); |
| | | assertThat(hbc).isNotNull(); |
| | | assertThat(hbc.isValid()).isTrue(); |
| | | |
| | | verify(mockSuccessHandler).handleResult(any(Connection.class)); |
| | | verifyNoMoreInteractions(mockSuccessHandler); |
| | | verify(mockResultHandler).handleResult(any(Connection.class)); |
| | | verifyNoMoreInteractions(mockResultHandler); |
| | | } |
| | | |
| | | @Test |
| | | public void testGetConnectionAsyncWithInitialHeartBeatError() throws Exception { |
| | | @SuppressWarnings("unchecked") |
| | | final SuccessHandler<Connection> mockSuccessHandler = mock(SuccessHandler.class); |
| | | final ResultHandler<Connection> mockResultHandler = mock(ResultHandler.class); |
| | | final PromiseImpl<LdapException, NeverThrowsException> promisedError = PromiseImpl.create(); |
| | | |
| | | mockConnectionWithInitialHeartbeatResult(ResultCode.BUSY); |
| | | Promise<? extends Connection, LdapException> promise = hbcf.getConnectionAsync(); |
| | | promise.onSuccess(mockSuccessHandler).onFailure(new FailureHandler<LdapException>() { |
| | | promise.thenOnResult(mockResultHandler).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(LdapException error) { |
| | | promisedError.handleResult(error); |
| | | public void handleException(LdapException exception) { |
| | | promisedError.handleResult(exception); |
| | | } |
| | | }); |
| | | |
| | |
| | | checkInitialHeartBeatFailure(e); |
| | | } |
| | | |
| | | verifyNoMoreInteractions(mockSuccessHandler); |
| | | verifyNoMoreInteractions(mockResultHandler); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | // Attempt to send a new request: it should fail immediately. |
| | | @SuppressWarnings("unchecked") |
| | | final FailureHandler<LdapException> mockHandler = mock(FailureHandler.class); |
| | | hbc.modifyAsync(newModifyRequest(DN.rootDN())).onFailure(mockHandler); |
| | | final ExceptionHandler<LdapException> mockHandler = mock(ExceptionHandler.class); |
| | | hbc.modifyAsync(newModifyRequest(DN.rootDN())).thenOnException(mockHandler); |
| | | final ArgumentCaptor<LdapException> arg = ArgumentCaptor.forClass(LdapException.class); |
| | | verify(mockHandler).handleError(arg.capture()); |
| | | verify(mockHandler).handleException(arg.capture()); |
| | | assertThat(arg.getValue().getResult().getResultCode()).isEqualTo( |
| | | ResultCode.CLIENT_SIDE_SERVER_DOWN); |
| | | |
| | |
| | | @Override |
| | | public void handleAdd(final Integer context, final AddRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> handler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<Result> handler) throws UnsupportedOperationException { |
| | | Result result = null; |
| | | final AbandonableRequest abReq = new AbandonableRequest(request); |
| | | requestsInProgress.put(context, abReq); |
| | |
| | | if (entryMap.containsKey(dn)) { |
| | | // duplicate entry. |
| | | result = Responses.newResult(ResultCode.ENTRY_ALREADY_EXISTS); |
| | | handler.handleError(newLdapException(result)); |
| | | handler.handleException(newLdapException(result)); |
| | | // doesn't matter if it was canceled. |
| | | requestsInProgress.remove(context); |
| | | return; |
| | |
| | | |
| | | if (abReq.isCanceled()) { |
| | | result = Responses.newResult(ResultCode.CANCELLED); |
| | | handler.handleError(newLdapException(result)); |
| | | handler.handleException(newLdapException(result)); |
| | | requestsInProgress.remove(context); |
| | | return; |
| | | } |
| | |
| | | @Override |
| | | public void handleBind(final Integer context, final int version, final BindRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<BindResult> resultHandler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<BindResult> resultHandler) throws UnsupportedOperationException { |
| | | // TODO: all bind types. |
| | | final AbandonableRequest abReq = new AbandonableRequest(request); |
| | | requestsInProgress.put(context, abReq); |
| | |
| | | ByteString.wrap(challenge))); |
| | | } |
| | | } catch (Exception e) { |
| | | resultHandler.handleError(newLdapException(Responses |
| | | resultHandler.handleException(newLdapException(Responses |
| | | .newBindResult(ResultCode.OPERATIONS_ERROR).setCause(e) |
| | | .setDiagnosticMessage(e.toString()))); |
| | | } |
| | |
| | | @Override |
| | | public void handleCompare(final Integer context, final CompareRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<CompareResult> resultHandler) |
| | | final LdapResultHandler<CompareResult> resultHandler) |
| | | throws UnsupportedOperationException { |
| | | CompareResult result = null; |
| | | final AbandonableRequest abReq = new AbandonableRequest(request); |
| | |
| | | if (!entryMap.containsKey(dn)) { |
| | | // entry not found. |
| | | result = Responses.newCompareResult(ResultCode.NO_SUCH_ATTRIBUTE); |
| | | resultHandler.handleError(newLdapException(result)); |
| | | resultHandler.handleException(newLdapException(result)); |
| | | // doesn't matter if it was canceled. |
| | | requestsInProgress.remove(context); |
| | | return; |
| | |
| | | final ByteString s = it.next(); |
| | | if (abReq.isCanceled()) { |
| | | final Result r = Responses.newResult(ResultCode.CANCELLED); |
| | | resultHandler.handleError(newLdapException(r)); |
| | | resultHandler.handleException(newLdapException(r)); |
| | | requestsInProgress.remove(context); |
| | | return; |
| | | } |
| | |
| | | @Override |
| | | public void handleDelete(final Integer context, final DeleteRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> handler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<Result> handler) throws UnsupportedOperationException { |
| | | Result result = null; |
| | | final AbandonableRequest abReq = new AbandonableRequest(request); |
| | | requestsInProgress.put(context, abReq); |
| | |
| | | if (!entryMap.containsKey(dn)) { |
| | | // entry is not found. |
| | | result = Responses.newResult(ResultCode.NO_SUCH_OBJECT); |
| | | handler.handleError(newLdapException(result)); |
| | | handler.handleException(newLdapException(result)); |
| | | // doesn't matter if it was canceled. |
| | | requestsInProgress.remove(context); |
| | | return; |
| | |
| | | |
| | | if (abReq.isCanceled()) { |
| | | result = Responses.newResult(ResultCode.CANCELLED); |
| | | handler.handleError(newLdapException(result)); |
| | | handler.handleException(newLdapException(result)); |
| | | requestsInProgress.remove(context); |
| | | return; |
| | | } |
| | |
| | | public <R extends ExtendedResult> void handleExtendedRequest(final Integer context, |
| | | final ExtendedRequest<R> request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<R> resultHandler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<R> resultHandler) throws UnsupportedOperationException { |
| | | if (request.getOID().equals(StartTLSExtendedRequest.OID)) { |
| | | final R result = request.getResultDecoder().newExtendedErrorResult(ResultCode.SUCCESS, "", ""); |
| | | resultHandler.handleResult(result); |
| | |
| | | @Override |
| | | public void handleModify(final Integer context, final ModifyRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | // TODO: |
| | | } |
| | | |
| | | @Override |
| | | public void handleModifyDN(final Integer context, final ModifyDNRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | // TODO |
| | | } |
| | | |
| | | @Override |
| | | public void handleSearch(final Integer context, final SearchRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final SearchResultHandler entryHandler, |
| | | final ResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | Result result = null; |
| | | final AbandonableRequest abReq = new AbandonableRequest(request); |
| | | requestsInProgress.put(context, abReq); |
| | |
| | | if (!entryMap.containsKey(dn)) { |
| | | // Entry not found. |
| | | result = Responses.newResult(ResultCode.NO_SUCH_OBJECT); |
| | | resultHandler.handleError(newLdapException(result)); |
| | | resultHandler.handleException(newLdapException(result)); |
| | | // Should searchResultHandler handle anything? |
| | | |
| | | // doesn't matter if it was canceled. |
| | |
| | | |
| | | if (abReq.isCanceled()) { |
| | | result = Responses.newResult(ResultCode.CANCELLED); |
| | | resultHandler.handleError(newLdapException(result)); |
| | | resultHandler.handleException(newLdapException(result)); |
| | | requestsInProgress.remove(context); |
| | | return; |
| | | } |
| | |
| | | |
| | | @Override |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | return newSuccessfulPromise(mock(Connection.class)); |
| | | return newResultPromise(mock(Connection.class)); |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.forgerock.opendj.ldap.requests.StartTLSExtendedRequest; |
| | | import org.forgerock.opendj.ldap.responses.ExtendedResult; |
| | | import org.forgerock.opendj.ldap.spi.LDAPConnectionFactoryImpl; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.PromiseImpl; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | import org.glassfish.grizzly.CompletionHandler; |
| | | import org.glassfish.grizzly.EmptyCompletionHandler; |
| | | import org.glassfish.grizzly.SocketConnectorHandler; |
| | |
| | | |
| | | // Plain connection. |
| | | if (options.getSSLContext() == null) { |
| | | onSuccess(connection); |
| | | thenOnResult(connection); |
| | | return; |
| | | } |
| | | |
| | |
| | | startTLS.addEnabledProtocol(options.getEnabledProtocols().toArray( |
| | | new String[options.getEnabledProtocols().size()])); |
| | | |
| | | connection.extendedRequestAsync(startTLS).onSuccess(new SuccessHandler<ExtendedResult>() { |
| | | connection.extendedRequestAsync(startTLS).thenOnResult(new ResultHandler<ExtendedResult>() { |
| | | @Override |
| | | public void handleResult(final ExtendedResult result) { |
| | | onSuccess(connection); |
| | | thenOnResult(connection); |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | onFailure(connection, error); |
| | | public void handleException(final LdapException error) { |
| | | onException(connection, error); |
| | | } |
| | | }); |
| | | } else { |
| | |
| | | options.getEnabledCipherSuites(), new EmptyCompletionHandler<SSLEngine>() { |
| | | @Override |
| | | public void completed(final SSLEngine result) { |
| | | onSuccess(connection); |
| | | thenOnResult(connection); |
| | | } |
| | | |
| | | @Override |
| | | public void failed(final Throwable throwable) { |
| | | onFailure(connection, throwable); |
| | | onException(connection, throwable); |
| | | } |
| | | }); |
| | | } catch (final IOException e) { |
| | | onFailure(connection, e); |
| | | onException(connection, e); |
| | | } |
| | | } |
| | | } |
| | |
| | | public void failed(final Throwable throwable) { |
| | | // Adapt and forward. |
| | | timeoutChecker.get().removeListener(this); |
| | | promise.handleError(adaptConnectionException(throwable)); |
| | | promise.handleException(adaptConnectionException(throwable)); |
| | | releaseTransportAndTimeoutChecker(); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private void onFailure(final GrizzlyLDAPConnection connection, final Throwable t) { |
| | | private void onException(final GrizzlyLDAPConnection connection, final Throwable t) { |
| | | // Abort connection attempt due to error. |
| | | timeoutChecker.get().removeListener(this); |
| | | promise.handleError(adaptConnectionException(t)); |
| | | promise.handleException(adaptConnectionException(t)); |
| | | connection.close(); |
| | | } |
| | | |
| | | private void onSuccess(final GrizzlyLDAPConnection connection) { |
| | | private void thenOnResult(final GrizzlyLDAPConnection connection) { |
| | | timeoutChecker.get().removeListener(this); |
| | | if (!promise.tryHandleResult(connection)) { |
| | | // The connection has been either cancelled or it has timed out. |
| | |
| | | } else if (timeoutEndTime > currentTime) { |
| | | return timeoutEndTime - currentTime; |
| | | } else { |
| | | promise.handleError(newLdapException(ResultCode.CLIENT_SIDE_CONNECT_ERROR, |
| | | promise.handleException(newLdapException(ResultCode.CLIENT_SIDE_CONNECT_ERROR, |
| | | LDAP_CONNECTION_CONNECT_TIMEOUT.get(getSocketAddress(), getTimeout()).toString())); |
| | | return 0; |
| | | } |
| | |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.SSLContextBuilder; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | | import org.forgerock.opendj.ldap.ServerConnection; |
| | |
| | | }; |
| | | |
| | | private static abstract class AbstractHandler<R extends Result> implements |
| | | IntermediateResponseHandler, ResultHandler<R> { |
| | | IntermediateResponseHandler, LdapResultHandler<R> { |
| | | protected final ClientContextImpl context; |
| | | protected final int messageID; |
| | | |
| | |
| | | ldapWrite.perform(writer, messageID, message); |
| | | context.write(writer); |
| | | } catch (final IOException ioe) { |
| | | context.handleError(ioe); |
| | | context.handleException(ioe); |
| | | } finally { |
| | | GrizzlyUtils.recycleWriter(writer); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException error) { |
| | | handleResult(error.getResult()); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException error) { |
| | | final Result result = error.getResult(); |
| | | if (result instanceof BindResult) { |
| | | handleResult((BindResult) result); |
| | |
| | | writer.writeExtendedResult(0, notification); |
| | | connection.write(writer.getASN1Writer().getBuffer(), null); |
| | | } catch (final IOException ioe) { |
| | | handleError(ioe); |
| | | handleException(ioe); |
| | | } finally { |
| | | GrizzlyUtils.recycleWriter(writer); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private void handleError(final Throwable error) { |
| | | private void handleException(final Throwable error) { |
| | | // Close this connection context. |
| | | if (isClosed.compareAndSet(false, true)) { |
| | | try { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException error) { |
| | | final Result result = error.getResult(); |
| | | if (result instanceof CompareResult) { |
| | | handleResult((CompareResult) result); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException error) { |
| | | handleResult(error.getResult()); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException error) { |
| | | final Result result = error.getResult(); |
| | | if (result instanceof ExtendedResult) { |
| | | handleResult((ExtendedResult) result); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException error) { |
| | | handleResult(error.getResult()); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException error) { |
| | | handleResult(error.getResult()); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException error) { |
| | | handleResult(error.getResult()); |
| | | } |
| | | |
| | |
| | | private static void exceptionOccurred(final Connection<?> connection, final Throwable error) { |
| | | final ClientContextImpl clientContext = LDAP_CONNECTION_ATTR.remove(connection); |
| | | if (clientContext != null) { |
| | | clientContext.handleError(error); |
| | | clientContext.handleException(error); |
| | | } |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.LDAPServer; |
| | | import org.forgerock.opendj.ldap.MockConnectionEventListener; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.RoundRobinLoadBalancingAlgorithm; |
| | | import org.forgerock.opendj.ldap.SSLContextBuilder; |
| | | import org.forgerock.opendj.ldap.SdkTestCase; |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.forgerock.opendj.ldap.schema.SchemaBuilder; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.PromiseImpl; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | import org.mockito.invocation.InvocationOnMock; |
| | | import org.mockito.stubbing.Answer; |
| | | import org.testng.annotations.AfterClass; |
| | |
| | | // Use the promise to get the result asynchronously. |
| | | final PromiseImpl<Connection, LdapException> promise = PromiseImpl.create(); |
| | | |
| | | factory.getConnectionAsync().onSuccess(new SuccessHandler<Connection>() { |
| | | factory.getConnectionAsync().thenOnResult(new ResultHandler<Connection>() { |
| | | @Override |
| | | public void handleResult(Connection con) { |
| | | con.close(); |
| | | promise.handleResult(con); |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(LdapException error) { |
| | | promise.handleError(error); |
| | | public void handleException(LdapException exception) { |
| | | promise.handleException(exception); |
| | | } |
| | | |
| | | }); |
| | |
| | | doAnswer(new Answer<Void>() { |
| | | @Override |
| | | public Void answer(InvocationOnMock invocation) throws Throwable { |
| | | ResultHandler<? super BindResult> resultHandler = |
| | | (ResultHandler<? super BindResult>) invocation |
| | | LdapResultHandler<? super BindResult> resultHandler = |
| | | (LdapResultHandler<? super BindResult>) invocation |
| | | .getArguments()[4]; |
| | | resultHandler.handleResult(Responses |
| | | .newBindResult(ResultCode.SUCCESS)); |
| | |
| | | } |
| | | }).when(mockConnection).handleBind(anyInt(), anyInt(), |
| | | any(BindRequest.class), any(IntermediateResponseHandler.class), |
| | | any(ResultHandler.class)); |
| | | any(LdapResultHandler.class)); |
| | | return mockConnection; |
| | | } |
| | | } |
| | |
| | | import org.forgerock.opendj.ldap.MockConnectionEventListener; |
| | | import org.forgerock.opendj.ldap.ProviderNotFoundException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.SdkTestCase; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | | import org.forgerock.opendj.ldap.ServerConnection; |
| | |
| | | import org.forgerock.opendj.ldap.requests.UnbindRequest; |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.PromiseImpl; |
| | |
| | | for (int i = 0; i < ITERATIONS; i++) { |
| | | final PromiseImpl<LdapException, NeverThrowsException> promise = PromiseImpl.create(); |
| | | final Promise<? extends Connection, LdapException> connectionPromise = factory.getConnectionAsync(); |
| | | connectionPromise.onFailure(getFailureHandler(promise)); |
| | | connectionPromise.thenOnException(getExceptionHandler(promise)); |
| | | |
| | | ConnectionException e = (ConnectionException) promise.getOrThrow(TEST_TIMEOUT, TimeUnit.SECONDS); |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_CONNECT_ERROR); |
| | |
| | | connection.addConnectionEventListener(listener); |
| | | final PromiseImpl<LdapException, NeverThrowsException> promise = PromiseImpl.create(); |
| | | final LdapPromise<BindResult> bindPromise = connection.bindAsync(newSimpleBindRequest()); |
| | | bindPromise.onFailure(getFailureHandler(promise)); |
| | | bindPromise.thenOnException(getExceptionHandler(promise)); |
| | | waitForBind(); |
| | | |
| | | TimeoutResultException e = (TimeoutResultException) promise.getOrThrow(TEST_TIMEOUT, TimeUnit.SECONDS); |
| | |
| | | // Now bind with timeout. |
| | | final PromiseImpl<LdapException, NeverThrowsException> promise = PromiseImpl.create(); |
| | | final LdapPromise<BindResult> bindPromise = connection.bindAsync(newSimpleBindRequest()); |
| | | bindPromise.onFailure(getFailureHandler(promise)); |
| | | bindPromise.thenOnException(getExceptionHandler(promise)); |
| | | waitForBind(); |
| | | |
| | | // Wait for the request to timeout and check the handler was invoked. |
| | |
| | | final PromiseImpl<LdapException, NeverThrowsException> promise = PromiseImpl.create(); |
| | | final LdapPromise<SearchResultEntry> connectionPromise = |
| | | connection.readEntryAsync(DN.valueOf("cn=test"), null); |
| | | connectionPromise.onFailure(getFailureHandler(promise)); |
| | | connectionPromise.thenOnException(getExceptionHandler(promise)); |
| | | waitForSearch(); |
| | | |
| | | LdapException e = promise.getOrThrow(TEST_TIMEOUT, TimeUnit.SECONDS); |
| | |
| | | } |
| | | } |
| | | |
| | | private FailureHandler<LdapException> getFailureHandler( |
| | | private ExceptionHandler<LdapException> getExceptionHandler( |
| | | final PromiseImpl<LdapException, NeverThrowsException> promise) { |
| | | return new FailureHandler<LdapException>() { |
| | | return new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(LdapException error) { |
| | | promise.handleResult(error); |
| | | public void handleException(LdapException exception) { |
| | | promise.handleResult(exception); |
| | | } |
| | | }; |
| | | } |
| | |
| | | private void registerBindEvent() { |
| | | notifyEvent(bindLatch).when(serverConnection).handleBind(any(Integer.class), anyInt(), |
| | | any(BindRequest.class), any(IntermediateResponseHandler.class), |
| | | any(ResultHandler.class)); |
| | | any(LdapResultHandler.class)); |
| | | } |
| | | |
| | | private void registerCloseEvent() { |
| | |
| | | |
| | | private void registerSearchEvent() { |
| | | notifyEvent(searchLatch).when(serverConnection).handleSearch(any(Integer.class), any(SearchRequest.class), |
| | | any(IntermediateResponseHandler.class), any(SearchResultHandler.class), any(ResultHandler.class)); |
| | | any(IntermediateResponseHandler.class), any(SearchResultHandler.class), any(LdapResultHandler.class)); |
| | | } |
| | | |
| | | private void resetState() { |
| | |
| | | import org.forgerock.opendj.ldap.controls.PersistentSearchRequestControl; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.forgerock.opendj.ldap.requests.SearchRequest; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.mockito.ArgumentCaptor; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | } |
| | | SearchResultHandler searchHandler = mock(SearchResultHandler.class); |
| | | @SuppressWarnings("unchecked") |
| | | FailureHandler<LdapException> failureHandler = mock(FailureHandler.class); |
| | | connection.searchAsync(request, searchHandler).onFailure(failureHandler); |
| | | ExceptionHandler<LdapException> exceptionHandler = mock(ExceptionHandler.class); |
| | | connection.searchAsync(request, searchHandler).thenOnException(exceptionHandler); |
| | | |
| | | // Pass in a time which is guaranteed to trigger expiration. |
| | | connection.handleTimeout(System.currentTimeMillis() + 1000000); |
| | |
| | | verifyZeroInteractions(searchHandler); |
| | | } else { |
| | | ArgumentCaptor<LdapException> arg = ArgumentCaptor.forClass(LdapException.class); |
| | | verify(failureHandler).handleError(arg.capture()); |
| | | verify(exceptionHandler).handleException(arg.capture()); |
| | | assertThat(arg.getValue()).isInstanceOf(TimeoutResultException.class); |
| | | assertThat(arg.getValue().getResult().getResultCode()).isEqualTo( |
| | | ResultCode.CLIENT_SIDE_TIMEOUT); |
| | |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ProviderNotFoundException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.RoundRobinLoadBalancingAlgorithm; |
| | | import org.forgerock.opendj.ldap.SdkTestCase; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | |
| | | @Override |
| | | public void handleAdd(final Integer requestContext, final AddRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | resultHandler.handleResult(Responses.newResult(ResultCode.SUCCESS)); |
| | | } |
| | | |
| | |
| | | public void handleBind(final Integer requestContext, final int version, |
| | | final BindRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<BindResult> resultHandler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<BindResult> resultHandler) throws UnsupportedOperationException { |
| | | resultHandler.handleResult(Responses.newBindResult(ResultCode.SUCCESS)); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void handleCompare(final Integer requestContext, final CompareRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<CompareResult> resultHandler) |
| | | final LdapResultHandler<CompareResult> resultHandler) |
| | | throws UnsupportedOperationException { |
| | | resultHandler.handleResult(Responses.newCompareResult(ResultCode.SUCCESS)); |
| | | } |
| | |
| | | @Override |
| | | public void handleDelete(final Integer requestContext, final DeleteRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | resultHandler.handleResult(Responses.newResult(ResultCode.SUCCESS)); |
| | | } |
| | | |
| | |
| | | public <R extends ExtendedResult> void handleExtendedRequest(final Integer requestContext, |
| | | final ExtendedRequest<R> request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<R> resultHandler) throws UnsupportedOperationException { |
| | | resultHandler.handleError(newLdapException(request |
| | | final LdapResultHandler<R> resultHandler) throws UnsupportedOperationException { |
| | | resultHandler.handleException(newLdapException(request |
| | | .getResultDecoder().newExtendedErrorResult(ResultCode.PROTOCOL_ERROR, "", |
| | | "Extended operation " + request.getOID() + " not supported"))); |
| | | } |
| | |
| | | @Override |
| | | public void handleModify(final Integer requestContext, final ModifyRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | resultHandler.handleResult(Responses.newResult(ResultCode.SUCCESS)); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void handleModifyDN(final Integer requestContext, final ModifyDNRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | resultHandler.handleResult(Responses.newResult(ResultCode.SUCCESS)); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void handleSearch(final Integer requestContext, final SearchRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final SearchResultHandler entryHandler, |
| | | final ResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | final LdapResultHandler<Result> resultHandler) throws UnsupportedOperationException { |
| | | resultHandler.handleResult(Responses.newResult(ResultCode.SUCCESS)); |
| | | } |
| | | |
| | |
| | | public void handleBind(final Integer requestContext, final int version, |
| | | final BindRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<BindResult> resultHandler) |
| | | final LdapResultHandler<BindResult> resultHandler) |
| | | throws UnsupportedOperationException { |
| | | // Get connection from load balancer, this should fail over |
| | | // twice before getting connection to online server. |
| | |
| | | resultHandler.handleResult(Responses.newBindResult(ResultCode.SUCCESS)); |
| | | } catch (final Exception e) { |
| | | // Unexpected. |
| | | resultHandler.handleError(newLdapException(ResultCode.OTHER, |
| | | resultHandler.handleException(newLdapException(ResultCode.OTHER, |
| | | "Unexpected exception when connecting to load balancer", e)); |
| | | } |
| | | } |
| | |
| | | public void handleBind(final Integer requestContext, final int version, |
| | | final BindRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<BindResult> resultHandler) |
| | | final LdapResultHandler<BindResult> resultHandler) |
| | | throws UnsupportedOperationException { |
| | | // First attempt offline server. |
| | | InetSocketAddress offlineAddress = findFreeSocketAddress(); |
| | |
| | | try { |
| | | // This is expected to fail. |
| | | lcf.getConnection().close(); |
| | | resultHandler.handleError(newLdapException( |
| | | resultHandler.handleException(newLdapException( |
| | | ResultCode.OTHER, |
| | | "Connection to offline server succeeded unexpectedly")); |
| | | } catch (final ConnectionException ce) { |
| | |
| | | resultHandler.handleResult(Responses.newBindResult(ResultCode.SUCCESS)); |
| | | } catch (final Exception e) { |
| | | // Unexpected. |
| | | resultHandler.handleError(newLdapException( |
| | | resultHandler.handleException(newLdapException( |
| | | ResultCode.OTHER, |
| | | "Unexpected exception when connecting to online server", e)); |
| | | } |
| | | } catch (final Exception e) { |
| | | // Unexpected. |
| | | resultHandler.handleError(newLdapException( |
| | | resultHandler.handleException(newLdapException( |
| | | ResultCode.OTHER, |
| | | "Unexpected exception when connecting to offline server", e)); |
| | | } |
| | |
| | | import org.forgerock.opendj.ldap.RequestContext; |
| | | import org.forgerock.opendj.ldap.RequestHandler; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | | import org.forgerock.opendj.ldap.controls.ProxiedAuthV2RequestControl; |
| | | import org.forgerock.opendj.ldap.requests.AddRequest; |
| | |
| | | import org.forgerock.opendj.ldap.responses.CompareResult; |
| | | import org.forgerock.opendj.ldap.responses.ExtendedResult; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | import org.forgerock.util.promise.AsyncFunction; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.util.Utils.*; |
| | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void handleAdd(final RequestContext requestContext, final AddRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final ResultHandler<Result> resultHandler) { |
| | | final IntermediateResponseHandler intermediateResponseHandler, final LdapResultHandler<Result> resultHandler) { |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<>(); |
| | | addProxiedAuthControl(request); |
| | | |
| | |
| | | connectionHolder.set(connection); |
| | | return connection.addAsync(request, intermediateResponseHandler); |
| | | } |
| | | }).onSuccess(resultHandler).onFailure(resultHandler).thenAlways(close(connectionHolder)); |
| | | }).thenOnResult(resultHandler).thenOnException(resultHandler).thenAlways(close(connectionHolder)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void handleBind(final RequestContext requestContext, final int version, final BindRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final ResultHandler<BindResult> resultHandler) { |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final LdapResultHandler<BindResult> resultHandler) { |
| | | |
| | | if (request.getAuthenticationType() != BindRequest.AUTHENTICATION_TYPE_SIMPLE) { |
| | | // TODO: SASL authentication not implemented. |
| | | resultHandler.handleError(newLdapException(ResultCode.PROTOCOL_ERROR, |
| | | resultHandler.handleException(newLdapException(ResultCode.PROTOCOL_ERROR, |
| | | "non-SIMPLE authentication not supported: " + request.getAuthenticationType())); |
| | | } else { |
| | | // Authenticate using a separate bind connection pool, because |
| | |
| | | connectionHolder.set(connection); |
| | | return connection.bindAsync(request, intermediateResponseHandler); |
| | | } |
| | | }).onSuccess(new SuccessHandler<BindResult>() { |
| | | }).thenOnResult(new ResultHandler<BindResult>() { |
| | | @Override |
| | | public final void handleResult(final BindResult result) { |
| | | proxiedAuthControl = ProxiedAuthV2RequestControl.newControl("dn:" + request.getName()); |
| | | resultHandler.handleResult(result); |
| | | } |
| | | }).onFailure(resultHandler).thenAlways(close(connectionHolder)); |
| | | }).thenOnException(resultHandler).thenAlways(close(connectionHolder)); |
| | | } |
| | | |
| | | } |
| | |
| | | @Override |
| | | public void handleCompare(final RequestContext requestContext, final CompareRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<CompareResult> resultHandler) { |
| | | final LdapResultHandler<CompareResult> resultHandler) { |
| | | addProxiedAuthControl(request); |
| | | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<>(); |
| | |
| | | connectionHolder.set(connection); |
| | | return connection.compareAsync(request, intermediateResponseHandler); |
| | | } |
| | | }).onSuccess(resultHandler).onFailure(resultHandler).thenAlways(close(connectionHolder)); |
| | | }).thenOnResult(resultHandler).thenOnException(resultHandler).thenAlways(close(connectionHolder)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void handleDelete(final RequestContext requestContext, final DeleteRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final ResultHandler<Result> resultHandler) { |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | addProxiedAuthControl(request); |
| | | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<>(); |
| | |
| | | connectionHolder.set(connection); |
| | | return connection.deleteAsync(request, intermediateResponseHandler); |
| | | } |
| | | }).onSuccess(resultHandler).onFailure(resultHandler).thenAlways(close(connectionHolder)); |
| | | }).thenOnResult(resultHandler).thenOnException(resultHandler).thenAlways(close(connectionHolder)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public <R extends ExtendedResult> void handleExtendedRequest(final RequestContext requestContext, |
| | | final ExtendedRequest<R> request, final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<R> resultHandler) { |
| | | final LdapResultHandler<R> resultHandler) { |
| | | if (CancelExtendedRequest.OID.equals(request.getOID())) { |
| | | // TODO: not implemented. |
| | | resultHandler.handleError(newLdapException(ResultCode.PROTOCOL_ERROR, |
| | | resultHandler.handleException(newLdapException(ResultCode.PROTOCOL_ERROR, |
| | | "Cancel extended request operation not supported")); |
| | | } else if (StartTLSExtendedRequest.OID.equals(request.getOID())) { |
| | | // TODO: not implemented. |
| | | resultHandler.handleError(newLdapException(ResultCode.PROTOCOL_ERROR, |
| | | resultHandler.handleException(newLdapException(ResultCode.PROTOCOL_ERROR, |
| | | "StartTLS extended request operation not supported")); |
| | | } else { |
| | | // Forward all other extended operations. |
| | |
| | | connectionHolder.set(connection); |
| | | return connection.extendedRequestAsync(request, intermediateResponseHandler); |
| | | } |
| | | }).onSuccess(resultHandler).onFailure(resultHandler) |
| | | }).thenOnResult(resultHandler).thenOnException(resultHandler) |
| | | .thenAlways(close(connectionHolder)); |
| | | } |
| | | } |
| | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void handleModify(final RequestContext requestContext, final ModifyRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final ResultHandler<Result> resultHandler) { |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | addProxiedAuthControl(request); |
| | | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<>(); |
| | |
| | | connectionHolder.set(connection); |
| | | return connection.modifyAsync(request, intermediateResponseHandler); |
| | | } |
| | | }).onSuccess(resultHandler).onFailure(resultHandler).thenAlways(close(connectionHolder)); |
| | | }).thenOnResult(resultHandler).thenOnException(resultHandler).thenAlways(close(connectionHolder)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void handleModifyDN(final RequestContext requestContext, final ModifyDNRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final ResultHandler<Result> resultHandler) { |
| | | final IntermediateResponseHandler intermediateResponseHandler, final LdapResultHandler<Result> resultHandler) { |
| | | addProxiedAuthControl(request); |
| | | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<>(); |
| | |
| | | connectionHolder.set(connection); |
| | | return connection.modifyDNAsync(request, intermediateResponseHandler); |
| | | } |
| | | }).onSuccess(resultHandler).onFailure(resultHandler).thenAlways(close(connectionHolder)); |
| | | }).thenOnResult(resultHandler).thenOnException(resultHandler).thenAlways(close(connectionHolder)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void handleSearch(final RequestContext requestContext, final SearchRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final SearchResultHandler entryHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | addProxiedAuthControl(request); |
| | | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<>(); |
| | |
| | | connectionHolder.set(connection); |
| | | return connection.searchAsync(request, intermediateResponseHandler, entryHandler); |
| | | } |
| | | }).onSuccess(resultHandler).onFailure(resultHandler).thenAlways(close(connectionHolder)); |
| | | }).thenOnResult(resultHandler).thenOnException(resultHandler).thenAlways(close(connectionHolder)); |
| | | } |
| | | |
| | | private void addProxiedAuthControl(final Request request) { |
| | |
| | | import org.forgerock.opendj.ldap.RequestContext; |
| | | import org.forgerock.opendj.ldap.RequestHandler; |
| | | import org.forgerock.opendj.ldap.RequestHandlerFactory; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | | import org.forgerock.opendj.ldap.ServerConnectionFactory; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | |
| | | @Override |
| | | public void handleAdd(final RequestContext requestContext, final AddRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | nextHandler.handleAdd(requestContext, rewrite(request), intermediateResponseHandler, |
| | | resultHandler); |
| | | } |
| | |
| | | public void handleBind(final RequestContext requestContext, final int version, |
| | | final BindRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<BindResult> resultHandler) { |
| | | final LdapResultHandler<BindResult> resultHandler) { |
| | | nextHandler.handleBind(requestContext, version, rewrite(request), |
| | | intermediateResponseHandler, resultHandler); |
| | | } |
| | |
| | | public void handleCompare(final RequestContext requestContext, |
| | | final CompareRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<CompareResult> resultHandler) { |
| | | final LdapResultHandler<CompareResult> resultHandler) { |
| | | nextHandler.handleCompare(requestContext, rewrite(request), |
| | | intermediateResponseHandler, resultHandler); |
| | | } |
| | |
| | | @Override |
| | | public void handleDelete(final RequestContext requestContext, final DeleteRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | nextHandler.handleDelete(requestContext, rewrite(request), intermediateResponseHandler, |
| | | resultHandler); |
| | | } |
| | |
| | | public <R extends ExtendedResult> void handleExtendedRequest( |
| | | final RequestContext requestContext, final ExtendedRequest<R> request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<R> resultHandler) { |
| | | final LdapResultHandler<R> resultHandler) { |
| | | nextHandler.handleExtendedRequest(requestContext, rewrite(request), |
| | | intermediateResponseHandler, resultHandler); |
| | | } |
| | |
| | | @Override |
| | | public void handleModify(final RequestContext requestContext, final ModifyRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | nextHandler.handleModify(requestContext, rewrite(request), intermediateResponseHandler, |
| | | resultHandler); |
| | | } |
| | |
| | | public void handleModifyDN(final RequestContext requestContext, |
| | | final ModifyDNRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | nextHandler.handleModifyDN(requestContext, rewrite(request), |
| | | intermediateResponseHandler, resultHandler); |
| | | } |
| | |
| | | @Override |
| | | public void handleSearch(final RequestContext requestContext, final SearchRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final SearchResultHandler entryHandler, |
| | | final ResultHandler<Result> resultHandler) { |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | nextHandler.handleSearch(requestContext, rewrite(request), intermediateResponseHandler, |
| | | new SearchResultHandler() { |
| | | @Override |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | import org.forgerock.opendj.ldif.LDIFEntryWriter; |
| | | import org.forgerock.util.promise.AsyncFunction; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | |
| | | /** |
| | | * An example client application which searches a Directory Server using the |
| | |
| | | CancelExtendedRequest request = |
| | | Requests.newCancelExtendedRequest(requestID); |
| | | connection.extendedRequestAsync(request) |
| | | .onSuccess(new SuccessHandler<ExtendedResult>() { |
| | | .thenOnResult(new ResultHandler<ExtendedResult>() { |
| | | @Override |
| | | public void handleResult(ExtendedResult result) { |
| | | System.err.println("Cancel request succeeded"); |
| | | CANCEL_LATCH.countDown(); |
| | | } |
| | | }) |
| | | .onFailure(new FailureHandler<LdapException>() { |
| | | .thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(LdapException error) { |
| | | public void handleException(LdapException exception) { |
| | | System.err.println("Cancel request failed: " |
| | | + error.getResult().getResultCode().intValue() |
| | | + exception.getResult().getResultCode().intValue() |
| | | + " " |
| | | + error.getResult().getDiagnosticMessage()); |
| | | + exception.getResult().getDiagnosticMessage()); |
| | | CANCEL_LATCH.countDown(); |
| | | } |
| | | }); |
| | |
| | | return promise; |
| | | } |
| | | }) |
| | | .onSuccess(new SuccessHandler<Result>() { |
| | | .thenOnResult(new ResultHandler<Result>() { |
| | | @Override |
| | | public void handleResult(Result result) { |
| | | resultCode = result.getResultCode().intValue(); |
| | | COMPLETION_LATCH.countDown(); |
| | | } |
| | | }) |
| | | .onFailure(new FailureHandler<LdapException>() { |
| | | .thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(LdapException error) { |
| | | System.err.println(error.getMessage()); |
| | | resultCode = error.getResult().getResultCode().intValue(); |
| | | public void handleException(LdapException exception) { |
| | | System.err.println(exception.getMessage()); |
| | | resultCode = exception.getResult().getResultCode().intValue(); |
| | | COMPLETION_LATCH.countDown(); |
| | | } |
| | | }); |
| | |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.responses.Responses; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | import org.forgerock.opendj.ldif.EntryGenerator; |
| | |
| | | |
| | | return doAdd(connection, currentTime); |
| | | } catch (final AddRateExecutionEndedException a) { |
| | | return newSuccessfulPromise(OTHER); |
| | | return newResultPromise(OTHER); |
| | | } catch (final IOException e) { |
| | | return newFailedPromise(newLdapException(OTHER, e)); |
| | | return newExceptionPromise(newLdapException(OTHER, e)); |
| | | } |
| | | } |
| | | |
| | |
| | | entry = generator.readEntry(); |
| | | } |
| | | |
| | | final ResultHandler<Result> addHandler = new AddStatsHandler(currentTime, entry.getName().toString()); |
| | | final LdapResultHandler<Result> addHandler = new AddStatsHandler( |
| | | currentTime, entry.getName().toString()); |
| | | return connection.addAsync(newAddRequest(entry)) |
| | | .onSuccess(addHandler) |
| | | .onFailure(addHandler); |
| | | .thenOnResult(addHandler) |
| | | .thenOnException(addHandler); |
| | | } |
| | | |
| | | private Promise<?, LdapException> doDelete( |
| | | final Connection connection, final long currentTime, final String entryToRemove) { |
| | | final ResultHandler<Result> deleteHandler = new DeleteStatsHandler(currentTime); |
| | | final LdapResultHandler<Result> deleteHandler = new DeleteStatsHandler(currentTime); |
| | | return connection.deleteAsync(newDeleteRequest(entryToRemove)) |
| | | .onSuccess(deleteHandler) |
| | | .onFailure(deleteHandler); |
| | | .thenOnResult(deleteHandler) |
| | | .thenOnException(deleteHandler); |
| | | } |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.requests.SimpleBindRequest; |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.util.promise.AsyncFunction; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.promise.Promise; |
| | | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | super.handleError(error); |
| | | public void handleException(final LdapException exception) { |
| | | super.handleException(exception); |
| | | |
| | | if (error.getResult().getResultCode() == ResultCode.INVALID_CREDENTIALS) { |
| | | if (exception.getResult().getResultCode() == ResultCode.INVALID_CREDENTIALS) { |
| | | invalidCredRecentCount.getAndIncrement(); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | incrementIterationCount(); |
| | | return returnedPromise.onSuccess(new UpdateStatsResultHandler<BindResult>(startTime)).onFailure( |
| | | new BindUpdateStatsResultHandler(startTime)); |
| | | return returnedPromise.thenOnResult(new UpdateStatsResultHandler<BindResult>(startTime)) |
| | | .thenOnException(new BindUpdateStatsResultHandler(startTime)); |
| | | } |
| | | |
| | | private Promise<BindResult, LdapException> performBind(final Connection connection, |
| | |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | |
| | | data = DataSource.generateData(dataSources, data); |
| | | } |
| | | mr = newModifyRequest(data); |
| | | ResultHandler<Result> modRes = new UpdateStatsResultHandler<>(startTime); |
| | | LdapResultHandler<Result> modRes = new UpdateStatsResultHandler<>(startTime); |
| | | |
| | | incrementIterationCount(); |
| | | return connection.modifyAsync(mr).onSuccess(modRes).onFailure(modRes); |
| | | return connection.modifyAsync(mr).thenOnResult(modRes).thenOnException(modRes); |
| | | } |
| | | |
| | | private ModifyRequest newModifyRequest(final Object[] data) { |
| | |
| | | import org.forgerock.opendj.ldap.ConnectionEventListener; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.responses.ExtendedResult; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | import org.forgerock.util.promise.Promise; |
| | |
| | | * @param <S> |
| | | * The type of expected result. |
| | | */ |
| | | class UpdateStatsResultHandler<S extends Result> implements ResultHandler<S> { |
| | | class UpdateStatsResultHandler<S extends Result> implements LdapResultHandler<S> { |
| | | protected final long currentTime; |
| | | |
| | | UpdateStatsResultHandler(final long currentTime) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException exception) { |
| | | failedRecentCount.getAndIncrement(); |
| | | updateStats(); |
| | | app.errPrintVerboseMessage(LocalizableMessage.raw(error.getResult().toString())); |
| | | app.errPrintVerboseMessage(LocalizableMessage.raw(exception.getResult().toString())); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | final SearchStatsHandler handler = new SearchStatsHandler(startTime); |
| | | incrementIterationCount(); |
| | | return connection.searchAsync(sr, handler).onSuccess(handler).onFailure(handler); |
| | | return connection.searchAsync(sr, handler).thenOnResult(handler).thenOnException(handler); |
| | | } |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.forgerock.opendj.rest2ldap.Rest2LDAP; |
| | | import org.forgerock.util.promise.AsyncFunction; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | |
| | | import static org.forgerock.json.resource.SecurityContext.*; |
| | | import static org.forgerock.json.resource.servlet.SecurityContextFactory.*; |
| | |
| | | // Do the search. |
| | | return connection.searchSingleEntryAsync(searchRequest); |
| | | } |
| | | }).onSuccess(new SuccessHandler<SearchResultEntry>() { |
| | | }).thenOnResult(new ResultHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry result) { |
| | | savedConnection.get().close(); |
| | |
| | | doBind(req, res, newSimpleBindRequest(bindDN, password), chain, savedConnection, sync, |
| | | username, authzid); |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | LdapException normalizedError = error; |
| | | public void handleException(final LdapException exception) { |
| | | LdapException normalizedError = exception; |
| | | if (savedConnection.get() != null) { |
| | | savedConnection.get().close(); |
| | | /* |
| | | * The search error should not be passed |
| | | * as-is back to the user. |
| | | */ |
| | | if (error instanceof EntryNotFoundException |
| | | || error instanceof MultipleEntriesFoundException) { |
| | | normalizedError = newLdapException(ResultCode.INVALID_CREDENTIALS, error); |
| | | } else if (error instanceof AuthenticationException |
| | | || error instanceof AuthorizationException) { |
| | | normalizedError = newLdapException(ResultCode.CLIENT_SIDE_LOCAL_ERROR, error); |
| | | if (exception instanceof EntryNotFoundException |
| | | || exception instanceof MultipleEntriesFoundException) { |
| | | normalizedError = newLdapException(ResultCode.INVALID_CREDENTIALS, exception); |
| | | } else if (exception instanceof AuthenticationException |
| | | || exception instanceof AuthorizationException) { |
| | | normalizedError = |
| | | newLdapException(ResultCode.CLIENT_SIDE_LOCAL_ERROR, exception); |
| | | } else { |
| | | normalizedError = error; |
| | | normalizedError = exception; |
| | | } |
| | | } |
| | | sync.signalAndComplete(asResourceException(normalizedError)); |
| | |
| | | savedConnection.set(connection); |
| | | return connection.bindAsync(bindRequest); |
| | | } |
| | | }).onSuccess(new SuccessHandler<BindResult>() { |
| | | }).thenOnResult(new ResultHandler<BindResult>() { |
| | | @Override |
| | | public void handleResult(final BindResult result) { |
| | | /* |
| | |
| | | } |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | sync.signalAndComplete(asResourceException(error)); |
| | | public void handleException(final LdapException exception) { |
| | | sync.signalAndComplete(asResourceException(exception)); |
| | | } |
| | | }); |
| | | } |
| | |
| | | import org.forgerock.opendj.ldap.LinkedAttribute; |
| | | import org.forgerock.opendj.ldap.Modification; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | /** |
| | |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LdapPromise; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | |
| | | import static org.forgerock.opendj.rest2ldap.Rest2LDAP.*; |
| | | import static org.forgerock.opendj.rest2ldap.Utils.*; |
| | |
| | | /** |
| | | * A cached read request - see cachedReads for more information. |
| | | */ |
| | | private static final class CachedRead implements SearchResultHandler, ResultHandler<Result> { |
| | | private static final class CachedRead implements SearchResultHandler, LdapResultHandler<Result> { |
| | | private SearchResultEntry cachedEntry; |
| | | private final String cachedFilterString; |
| | | /** Guarded by cachedPromiseLatch.*/ |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | handleResult(error.getResult()); |
| | | public void handleException(final LdapException exception) { |
| | | handleResult(exception.getResult()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | // Invoke the handler immediately since a connection is available. |
| | | runnable.run(); |
| | | } else if (config.connectionFactory() != null) { |
| | | config.connectionFactory().getConnectionAsync().onSuccess(new SuccessHandler<Connection>() { |
| | | config.connectionFactory().getConnectionAsync().thenOnResult(new ResultHandler<Connection>() { |
| | | @Override |
| | | public final void handleResult(final Connection result) { |
| | | connection = wrap(result); |
| | | runnable.run(); |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public final void handleError(final LdapException error) { |
| | | handler.handleError(asResourceException(error)); |
| | | public final void handleException(final LdapException exception) { |
| | | handler.handleError(asResourceException(exception)); |
| | | } |
| | | }); |
| | | } else { |
| | |
| | | } |
| | | final LdapPromise<Result> promise = connection |
| | | .searchAsync(withControls(request), intermediateResponseHandler, pendingCachedRead) |
| | | .onSuccess(pendingCachedRead).onFailure(pendingCachedRead); |
| | | .thenOnResult(pendingCachedRead).thenOnException(pendingCachedRead); |
| | | pendingCachedRead.setPromise(promise); |
| | | return promise; |
| | | } |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | import org.forgerock.opendj.ldif.ChangeRecord; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.PromiseImpl; |
| | | import org.forgerock.util.promise.Promises; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | |
| | | import static java.util.Arrays.*; |
| | | |
| | |
| | | |
| | | @Override |
| | | public void handleError(ResourceException error) { |
| | | promise.handleError(error); |
| | | promise.handleException(error); |
| | | |
| | | } |
| | | |
| | |
| | | addRequest.addControl(PostReadRequestControl.newControl(false, attributes)); |
| | | } |
| | | c.getConnection().applyChangeAsync(addRequest) |
| | | .onSuccess(postUpdateSuccessHandler(c, h)) |
| | | .onFailure(postUpdateFailureHandler(h)); |
| | | .thenOnResult(postUpdateResultHandler(c, h)) |
| | | .thenOnException(postUpdateExceptionHandler(h)); |
| | | } |
| | | }); |
| | | } |
| | |
| | | deleteRequest.addControl(SubtreeDeleteRequestControl.newControl(true)); |
| | | } |
| | | addAssertionControl(deleteRequest, request.getRevision()); |
| | | c.getConnection().applyChangeAsync(deleteRequest).onSuccess(postUpdateSuccessHandler(c, h)) |
| | | .onFailure(postUpdateFailureHandler(h)); |
| | | c.getConnection().applyChangeAsync(deleteRequest).thenOnResult(postUpdateResultHandler(c, h)) |
| | | .thenOnException(postUpdateExceptionHandler(h)); |
| | | } catch (final Exception e) { |
| | | h.handleError(asResourceException(e)); |
| | | } |
| | |
| | | final SearchRequest searchRequest = nameStrategy.createSearchRequest(c, getBaseDN(c), resourceId) |
| | | .addAttribute(attributes); |
| | | c.getConnection().searchSingleEntryAsync(searchRequest) |
| | | .onSuccess(postEmptyPatchSuccessHandler(c, request, h)) |
| | | .onFailure(postEmptyPatchFailureHandler(h)); |
| | | .thenOnResult(postEmptyPatchResultHandler(c, request, h)) |
| | | .thenOnException(postEmptyPatchExceptionHandler(h)); |
| | | } |
| | | }); |
| | | } else { |
| | |
| | | promises.add(handler.promise); |
| | | } |
| | | |
| | | Promises.when(promises).onSuccess(new SuccessHandler<List<List<Modification>>>() { |
| | | @Override |
| | | public void handleResult(final List<List<Modification>> result) { |
| | | // The patch operations have been converted successfully. |
| | | try { |
| | | final ModifyRequest modifyRequest = newModifyRequest(dn); |
| | | Promises.when(promises).thenOnResult( |
| | | new org.forgerock.util.promise.ResultHandler<List<List<Modification>>>() { |
| | | @Override |
| | | public void handleResult(final List<List<Modification>> result) { |
| | | // The patch operations have been converted successfully. |
| | | try { |
| | | final ModifyRequest modifyRequest = newModifyRequest(dn); |
| | | |
| | | // Add the modifications. |
| | | for (final List<Modification> modifications : result) { |
| | | if (modifications != null) { |
| | | modifyRequest.getModifications().addAll(modifications); |
| | | // Add the modifications. |
| | | for (final List<Modification> modifications : result) { |
| | | if (modifications != null) { |
| | | modifyRequest.getModifications().addAll(modifications); |
| | | } |
| | | } |
| | | } |
| | | |
| | | final List<String> attributes = asList(getLDAPAttributes(c, request.getFields())); |
| | | if (modifyRequest.getModifications().isEmpty()) { |
| | | /* |
| | | * This patch is a no-op so just read the entry and check its version. |
| | | */ |
| | | c.getConnection().readEntryAsync(dn, attributes) |
| | | .onSuccess(postEmptyPatchSuccessHandler(c, request, h)) |
| | | .onFailure(postEmptyPatchFailureHandler(h)); |
| | | } else { |
| | | // Add controls and perform the modify request. |
| | | if (config.readOnUpdatePolicy() == CONTROLS) { |
| | | modifyRequest.addControl(PostReadRequestControl.newControl(false, attributes)); |
| | | final List<String> attributes = asList(getLDAPAttributes(c, request.getFields())); |
| | | if (modifyRequest.getModifications().isEmpty()) { |
| | | /* |
| | | * This patch is a no-op so just read the entry and check its version. |
| | | */ |
| | | c.getConnection().readEntryAsync(dn, attributes) |
| | | .thenOnResult(postEmptyPatchResultHandler(c, request, h)) |
| | | .thenOnException(postEmptyPatchExceptionHandler(h)); |
| | | } else { |
| | | // Add controls and perform the modify request. |
| | | if (config.readOnUpdatePolicy() == CONTROLS) { |
| | | modifyRequest.addControl( |
| | | PostReadRequestControl.newControl(false, attributes)); |
| | | } |
| | | if (config.usePermissiveModify()) { |
| | | modifyRequest.addControl(PermissiveModifyRequestControl.newControl(true)); |
| | | } |
| | | addAssertionControl(modifyRequest, request.getRevision()); |
| | | c.getConnection().applyChangeAsync(modifyRequest) |
| | | .thenOnResult(postUpdateResultHandler(c, h)) |
| | | .thenOnException(postUpdateExceptionHandler(h)); |
| | | } |
| | | if (config.usePermissiveModify()) { |
| | | modifyRequest.addControl(PermissiveModifyRequestControl.newControl(true)); |
| | | } |
| | | addAssertionControl(modifyRequest, request.getRevision()); |
| | | c.getConnection().applyChangeAsync(modifyRequest) |
| | | .onSuccess(postUpdateSuccessHandler(c, h)) |
| | | .onFailure(postUpdateFailureHandler(h)); |
| | | } catch (final Exception e) { |
| | | h.handleError(asResourceException(e)); |
| | | } |
| | | } catch (final Exception e) { |
| | | h.handleError(asResourceException(e)); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<ResourceException>() { |
| | | @Override |
| | | public void handleError(ResourceException error) { |
| | | h.handleError(asResourceException(error)); |
| | | } |
| | | }); |
| | | }).thenOnException(new ExceptionHandler<ResourceException>() { |
| | | @Override |
| | | public void handleException(ResourceException exception) { |
| | | h.handleError(asResourceException(exception)); |
| | | } |
| | | }); |
| | | } |
| | | })); |
| | | } |
| | |
| | | return true; |
| | | } |
| | | |
| | | }).onSuccess(new SuccessHandler<Result>() { |
| | | }).thenOnResult(new org.forgerock.util.promise.ResultHandler<Result>() { |
| | | @Override |
| | | public void handleResult(Result result) { |
| | | synchronized (sequenceLock) { |
| | |
| | | completeIfNecessary(SUCCESS); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(LdapException error) { |
| | | public void handleException(LdapException exception) { |
| | | synchronized (sequenceLock) { |
| | | completeIfNecessary(asResourceException(error)); |
| | | completeIfNecessary(asResourceException(exception)); |
| | | } |
| | | } |
| | | }); |
| | |
| | | final SearchRequest request = |
| | | nameStrategy.createSearchRequest(c, getBaseDN(c), resourceId).addAttribute(attributes); |
| | | |
| | | c.getConnection().searchSingleEntryAsync(request).onSuccess(new SuccessHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry entry) { |
| | | adaptEntry(c, entry, h); |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | h.handleError(asResourceException(error)); |
| | | } |
| | | }); |
| | | |
| | | c.getConnection().searchSingleEntryAsync(request).thenOnResult( |
| | | new org.forgerock.util.promise.ResultHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry entry) { |
| | | adaptEntry(c, entry, h); |
| | | } |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleException(final LdapException exception) { |
| | | h.handleError(asResourceException(exception)); |
| | | } |
| | | }); |
| | | }; |
| | | }); |
| | | } |
| | |
| | | .addAttribute(attributes); |
| | | |
| | | c.getConnection().searchSingleEntryAsync(searchRequest) |
| | | .onSuccess(new SuccessHandler<SearchResultEntry>() { |
| | | .thenOnResult(new org.forgerock.util.promise.ResultHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry entry) { |
| | | try { |
| | |
| | | } else { |
| | | modifyRequest.getModifications().addAll(result); |
| | | c.getConnection().applyChangeAsync(modifyRequest) |
| | | .onSuccess(postUpdateSuccessHandler(c, h)) |
| | | .onFailure(postUpdateFailureHandler(h)); |
| | | .thenOnResult(postUpdateResultHandler(c, h)) |
| | | .thenOnException(postUpdateExceptionHandler(h)); |
| | | } |
| | | } |
| | | }); |
| | |
| | | h.handleError(asResourceException(e)); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | h.handleError(asResourceException(error)); |
| | | public void handleException(final LdapException exception) { |
| | | h.handleError(asResourceException(exception)); |
| | | } |
| | | }); |
| | | } |
| | |
| | | updateHandler.handleResult(searchRequest.getName()); |
| | | } else { |
| | | c.getConnection().searchSingleEntryAsync(searchRequest) |
| | | .onSuccess(new SuccessHandler<SearchResultEntry>() { |
| | | .thenOnResult(new org.forgerock.util.promise.ResultHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry entry) { |
| | | try { |
| | |
| | | updateHandler.handleError(asResourceException(e)); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | updateHandler.handleError(asResourceException(error)); |
| | | public void handleException(final LdapException exception) { |
| | | updateHandler.handleError(asResourceException(exception)); |
| | | } |
| | | }); |
| | | } |
| | |
| | | } |
| | | |
| | | Promises.when(promises) |
| | | .then(new org.forgerock.util.promise.Function<List<Filter>, Filter, |
| | | ResourceException>() { |
| | | .then(new org.forgerock.util.Function<List<Filter>, Filter, ResourceException>() { |
| | | @Override |
| | | public Filter apply(final List<Filter> value) { |
| | | // Check for unmapped filter components and optimize. |
| | |
| | | return Filter.and(value); |
| | | } |
| | | } |
| | | }).onSuccess(new SuccessHandler<Filter>() { |
| | | }).thenOnResult(new org.forgerock.util.promise.ResultHandler<Filter>() { |
| | | @Override |
| | | public void handleResult(Filter result) { |
| | | p.handleResult(result); |
| | | } |
| | | }).onFailure(new FailureHandler<ResourceException>() { |
| | | }).thenOnException(new ExceptionHandler<ResourceException>() { |
| | | @Override |
| | | public void handleError(ResourceException error) { |
| | | p.handleError(error); |
| | | public void handleException(ResourceException exception) { |
| | | p.handleError(exception); |
| | | } |
| | | }); |
| | | |
| | |
| | | } |
| | | |
| | | Promises.when(promises) |
| | | .then(new org.forgerock.util.promise.Function<List<Filter>, Filter, |
| | | ResourceException>() { |
| | | .then(new org.forgerock.util.Function<List<Filter>, Filter, ResourceException>() { |
| | | @Override |
| | | public Filter apply(final List<Filter> value) { |
| | | // Check for unmapped filter components and optimize. |
| | |
| | | return Filter.or(value); |
| | | } |
| | | } |
| | | }).onSuccess(new SuccessHandler<Filter>() { |
| | | }).thenOnResult(new org.forgerock.util.promise.ResultHandler<Filter>() { |
| | | @Override |
| | | public void handleResult(Filter result) { |
| | | p.handleResult(result); |
| | | } |
| | | }).onFailure(new FailureHandler<ResourceException>() { |
| | | }).thenOnException(new ExceptionHandler<ResourceException>() { |
| | | @Override |
| | | public void handleError(ResourceException error) { |
| | | p.handleError(error); |
| | | public void handleException(ResourceException exception) { |
| | | p.handleError(exception); |
| | | } |
| | | }); |
| | | |
| | |
| | | return etagAttribute != null ? entry.parseAttribute(etagAttribute).asString() : null; |
| | | } |
| | | |
| | | private SuccessHandler<SearchResultEntry> postEmptyPatchSuccessHandler(final Context c, |
| | | final PatchRequest request, final ResultHandler<Resource> h) { |
| | | return new SuccessHandler<SearchResultEntry>() { |
| | | private org.forgerock.util.promise.ResultHandler<SearchResultEntry> postEmptyPatchResultHandler( |
| | | final Context c, final PatchRequest request, final ResultHandler<Resource> h) { |
| | | return new org.forgerock.util.promise.ResultHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry entry) { |
| | | try { |
| | |
| | | }; |
| | | } |
| | | |
| | | private FailureHandler<LdapException> postEmptyPatchFailureHandler(final ResultHandler<Resource> h) { |
| | | return new FailureHandler<LdapException>() { |
| | | private ExceptionHandler<LdapException> postEmptyPatchExceptionHandler(final ResultHandler<Resource> h) { |
| | | return new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | h.handleError(asResourceException(error)); |
| | | public void handleException(final LdapException exception) { |
| | | h.handleError(asResourceException(exception)); |
| | | } |
| | | }; |
| | | } |
| | | |
| | | private SuccessHandler<Result> postUpdateSuccessHandler(final Context c, final ResultHandler<Resource> handler) { |
| | | private org.forgerock.util.promise.ResultHandler<Result> postUpdateResultHandler( |
| | | final Context c, final ResultHandler<Resource> handler) { |
| | | // The handler which will be invoked for the LDAP add result. |
| | | return new SuccessHandler<Result>() { |
| | | return new org.forgerock.util.promise.ResultHandler<Result>() { |
| | | @Override |
| | | public void handleResult(final Result result) { |
| | | // FIXME: handle USE_SEARCH policy. |
| | |
| | | }; |
| | | } |
| | | |
| | | private FailureHandler<LdapException> postUpdateFailureHandler(final ResultHandler<Resource> handler) { |
| | | private ExceptionHandler<LdapException> postUpdateExceptionHandler(final ResultHandler<Resource> handler) { |
| | | // The handler which will be invoked for the LDAP add result. |
| | | return new FailureHandler<LdapException>() { |
| | | return new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | handler.handleError(asResourceException(error)); |
| | | public void handleException(final LdapException exception) { |
| | | handler.handleError(asResourceException(exception)); |
| | | } |
| | | }; |
| | | } |
| | |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.Modification; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | import static org.forgerock.json.resource.PatchOperation.*; |
| | |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | |
| | | final SearchRequest request = createSearchRequest(result); |
| | | final List<Filter> subFilters = new LinkedList<>(); |
| | | |
| | | final FailureHandler<LdapException> failureHandler = new FailureHandler<LdapException>() { |
| | | final ExceptionHandler<LdapException> exceptionHandler = new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(LdapException error) { |
| | | h.handleError(asResourceException(error)); // Propagate. |
| | | public void handleException(LdapException exception) { |
| | | h.handleError(asResourceException(exception)); // Propagate. |
| | | } |
| | | }; |
| | | |
| | |
| | | // Ignore references. |
| | | return true; |
| | | } |
| | | }).onSuccess(new SuccessHandler<Result>() { |
| | | }).thenOnResult(new org.forgerock.util.promise.ResultHandler<Result>() { |
| | | @Override |
| | | public void handleResult(Result result) { |
| | | if (subFilters.size() >= SEARCH_MAX_CANDIDATES) { |
| | | failureHandler.handleError(newLdapException(ResultCode.ADMIN_LIMIT_EXCEEDED)); |
| | | exceptionHandler.handleException(newLdapException(ResultCode.ADMIN_LIMIT_EXCEEDED)); |
| | | } else if (subFilters.size() == 1) { |
| | | h.handleResult(subFilters.get(0)); |
| | | } else { |
| | | h.handleResult(Filter.or(subFilters)); |
| | | } |
| | | } |
| | | }).onFailure(failureHandler); |
| | | }).thenOnException(exceptionHandler); |
| | | } |
| | | }); |
| | | } |
| | |
| | | final ByteString primaryKeyValue = primaryKeyAttribute.firstValue(); |
| | | final Filter filter = Filter.equality(primaryKey.toString(), primaryKeyValue); |
| | | final SearchRequest search = createSearchRequest(filter); |
| | | c.getConnection().searchSingleEntryAsync(search).onSuccess(new SuccessHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry result) { |
| | | synchronized (newLDAPAttribute) { |
| | | newLDAPAttribute.add(result.getName()); |
| | | c.getConnection().searchSingleEntryAsync(search).thenOnResult( |
| | | new org.forgerock.util.promise.ResultHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry result) { |
| | | synchronized (newLDAPAttribute) { |
| | | newLDAPAttribute.add(result.getName()); |
| | | } |
| | | completeIfNecessary(); |
| | | } |
| | | completeIfNecessary(); |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | ResourceException re; |
| | | try { |
| | | throw error; |
| | | } catch (final EntryNotFoundException e) { |
| | | re = |
| | | new BadRequestException(i18n("The request cannot be processed " |
| | | + "because the resource '%s' " + "referenced in field '%s' does " |
| | | + "not exist", primaryKeyValue.toString(), path)); |
| | | } catch (final MultipleEntriesFoundException e) { |
| | | re = |
| | | new BadRequestException(i18n( |
| | | "The request cannot be processed " + "because the resource '%s' " |
| | | + "referenced in field '%s' is " + "ambiguous", |
| | | primaryKeyValue.toString(), path)); |
| | | } catch (final LdapException e) { |
| | | re = asResourceException(e); |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleException(final LdapException error) { |
| | | ResourceException re; |
| | | try { |
| | | throw error; |
| | | } catch (final EntryNotFoundException e) { |
| | | re = new BadRequestException(i18n( |
| | | "The request cannot be processed " + "because the resource '%s' " |
| | | + "referenced in field '%s' does " + "not exist", |
| | | primaryKeyValue.toString(), path)); |
| | | } catch (final MultipleEntriesFoundException e) { |
| | | re = new BadRequestException(i18n( |
| | | "The request cannot be processed " + "because the resource '%s' " |
| | | + "referenced in field '%s' is " + "ambiguous", |
| | | primaryKeyValue.toString(), path)); |
| | | } catch (final LdapException e) { |
| | | re = asResourceException(e); |
| | | } |
| | | exception.compareAndSet(null, re); |
| | | completeIfNecessary(); |
| | | } |
| | | exception.compareAndSet(null, re); |
| | | completeIfNecessary(); |
| | | } |
| | | |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | private void completeIfNecessary() { |
| | |
| | | final Set<String> requestedLDAPAttributes = new LinkedHashSet<>(); |
| | | mapper.getLDAPAttributes(c, path, new JsonPointer(), requestedLDAPAttributes); |
| | | c.getConnection().readEntryAsync(dn, requestedLDAPAttributes) |
| | | .onSuccess(new SuccessHandler<SearchResultEntry>() { |
| | | .thenOnResult(new org.forgerock.util.promise.ResultHandler<SearchResultEntry>() { |
| | | @Override |
| | | public void handleResult(final SearchResultEntry result) { |
| | | mapper.read(c, path, result, handler); |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | }).thenOnException(new ExceptionHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final LdapException error) { |
| | | public void handleException(final LdapException error) { |
| | | if (!(error instanceof EntryNotFoundException)) { |
| | | handler.handleError(asResourceException(error)); |
| | | } else { |
| | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | import static java.util.Collections.*; |
| | |
| | | import org.forgerock.opendj.ldap.GeneralizedTime; |
| | | import org.forgerock.opendj.ldap.LinkedAttribute; |
| | | import org.forgerock.opendj.ldap.schema.Syntax; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | /** |
| | |
| | | import org.forgerock.opendj.ldap.MemoryBackend; |
| | | import org.forgerock.opendj.ldap.RequestContext; |
| | | import org.forgerock.opendj.ldap.RequestHandler; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | | import org.forgerock.opendj.ldap.requests.AddRequest; |
| | | import org.forgerock.opendj.ldap.requests.BindRequest; |
| | |
| | | @Override |
| | | public void handleAdd(RequestContext requestContext, AddRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<Result> resultHandler) { |
| | | LdapResultHandler<Result> resultHandler) { |
| | | requests.add(request); |
| | | handler.handleAdd(requestContext, request, intermediateResponseHandler, |
| | | resultHandler); |
| | |
| | | @Override |
| | | public void handleBind(RequestContext requestContext, int version, BindRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<BindResult> resultHandler) { |
| | | LdapResultHandler<BindResult> resultHandler) { |
| | | requests.add(request); |
| | | handler.handleBind(requestContext, version, request, intermediateResponseHandler, |
| | | resultHandler); |
| | |
| | | @Override |
| | | public void handleCompare(RequestContext requestContext, CompareRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<CompareResult> resultHandler) { |
| | | LdapResultHandler<CompareResult> resultHandler) { |
| | | requests.add(request); |
| | | handler.handleCompare(requestContext, request, intermediateResponseHandler, |
| | | resultHandler); |
| | |
| | | @Override |
| | | public void handleDelete(RequestContext requestContext, DeleteRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<Result> resultHandler) { |
| | | LdapResultHandler<Result> resultHandler) { |
| | | requests.add(request); |
| | | handler.handleDelete(requestContext, request, intermediateResponseHandler, |
| | | resultHandler); |
| | |
| | | public <R extends ExtendedResult> void handleExtendedRequest( |
| | | RequestContext requestContext, ExtendedRequest<R> request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<R> resultHandler) { |
| | | LdapResultHandler<R> resultHandler) { |
| | | requests.add(request); |
| | | handler.handleExtendedRequest(requestContext, request, intermediateResponseHandler, |
| | | resultHandler); |
| | |
| | | @Override |
| | | public void handleModify(RequestContext requestContext, ModifyRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<Result> resultHandler) { |
| | | LdapResultHandler<Result> resultHandler) { |
| | | requests.add(request); |
| | | handler.handleModify(requestContext, request, intermediateResponseHandler, |
| | | resultHandler); |
| | |
| | | @Override |
| | | public void handleModifyDN(RequestContext requestContext, ModifyDNRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, |
| | | ResultHandler<Result> resultHandler) { |
| | | LdapResultHandler<Result> resultHandler) { |
| | | requests.add(request); |
| | | handler.handleModifyDN(requestContext, request, intermediateResponseHandler, |
| | | resultHandler); |
| | |
| | | @Override |
| | | public void handleSearch(RequestContext requestContext, SearchRequest request, |
| | | IntermediateResponseHandler intermediateResponseHandler, SearchResultHandler entryHandler, |
| | | ResultHandler<Result> resultHandler) { |
| | | LdapResultHandler<Result> resultHandler) { |
| | | requests.add(request); |
| | | handler.handleSearch(requestContext, request, intermediateResponseHandler, entryHandler, |
| | | resultHandler); |
| | |
| | | @Override |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | // TODO change the path... |
| | | return newSuccessfulPromise(newConnection(icc)); |
| | | return newResultPromise(newConnection(icc)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | import static org.forgerock.util.Reject.*; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | import org.opends.server.backends.pluggable.spi.Cursor; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.opends.server.backends.pluggable.spi.Cursor; |
| | | import org.opends.server.backends.pluggable.spi.ReadableTransaction; |
| | | import org.opends.server.backends.pluggable.spi.SequentialCursor; |
| | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | import org.opends.server.backends.pluggable.spi.Cursor; |
| | | import org.opends.server.backends.pluggable.spi.Importer; |
| | |
| | | import org.forgerock.opendj.ldap.MemoryBackend; |
| | | import org.forgerock.opendj.ldap.RequestContext; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | |
| | | } |
| | | |
| | | /** Handler for LDAP operations. */ |
| | | private static final class ConfigResultHandler implements ResultHandler<Result> { |
| | | private static final class ConfigResultHandler implements LdapResultHandler<Result> { |
| | | |
| | | private LdapException resultError; |
| | | |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void handleError(LdapException error) |
| | | public void handleException(LdapException exception) |
| | | { |
| | | resultError = error; |
| | | resultError = exception; |
| | | } |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.rest2ldap.Rest2LDAP; |
| | | import org.forgerock.opendj.rest2ldap.servlet.Rest2LDAPContextFactory; |
| | | import org.forgerock.util.promise.AsyncFunction; |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | | import org.opends.server.admin.std.server.ConnectionHandlerCfg; |
| | | import org.opends.server.schema.SchemaConstants; |
| | | import org.opends.server.types.DisconnectReason; |
| | |
| | | if (bindDN == null) |
| | | { |
| | | sendAuthenticationFailure(ctx); |
| | | return newFailedPromise(newLdapException(ResultCode.CANCELLED)); |
| | | return newExceptionPromise(newLdapException(ResultCode.CANCELLED)); |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | |
| | | } |
| | | ).onSuccess(new SuccessHandler<BindResult>() { |
| | | ).thenOnResult(new ResultHandler<BindResult>() { |
| | | @Override |
| | | public void handleResult(BindResult result) |
| | | { |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | onFailure(e, ctx); |
| | | onException(e, ctx); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<LdapException>(){ |
| | | }).thenOnException(new ExceptionHandler<LdapException>(){ |
| | | @Override |
| | | public void handleError(LdapException error) |
| | | public void handleException(LdapException exception) |
| | | { |
| | | final ResultCode rc = error.getResult().getResultCode(); |
| | | final ResultCode rc = exception.getResult().getResultCode(); |
| | | if (ResultCode.CLIENT_SIDE_NO_RESULTS_RETURNED.equals(rc) |
| | | || ResultCode.CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED.equals(rc)) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | onFailure(error, ctx); |
| | | onException(exception, ctx); |
| | | } |
| | | } |
| | | }); |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | onFailure(e, ctx); |
| | | onException(e, ctx); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private void onFailure(Exception e, HTTPRequestContext ctx) |
| | | private void onException(Exception e, HTTPRequestContext ctx) |
| | | { |
| | | ResourceException ex = Rest2LDAP.asResourceException(e); |
| | | try |
| | |
| | | } |
| | | catch (LdapException e) |
| | | { |
| | | op.promise.handleError(e); |
| | | op.promise.handleException(e); |
| | | } |
| | | } |
| | | } |
| | |
| | | OperationWithPromise op = operationsInProgress.remove(messageID); |
| | | if (op != null) |
| | | { |
| | | op.promise.handleError(newLdapException(ResultCode.CANCELLED)); |
| | | op.promise.handleException(newLdapException(ResultCode.CANCELLED)); |
| | | return op.operation.cancel(cancelRequest); |
| | | } |
| | | return new CancelResult(ResultCode.NO_SUCH_OPERATION, null); |
| | |
| | | { |
| | | try |
| | | { |
| | | op.promise.handleError(newLdapException(ResultCode.CANCELLED)); |
| | | op.promise.handleException(newLdapException(ResultCode.CANCELLED)); |
| | | op.operation.abort(cancelRequest); |
| | | |
| | | if (keepStats) |
| | |
| | | logger.traceException(e); |
| | | clientConnection.removeOperationInProgress(operation.getMessageID()); |
| | | // TODO JNR add error message?? |
| | | promise.handleError(newLdapException(ResultCode.OPERATIONS_ERROR, e)); |
| | | promise.handleException(newLdapException(ResultCode.OPERATIONS_ERROR, e)); |
| | | } |
| | | |
| | | return promise; |
| | |
| | | import org.forgerock.opendj.ldap.Functions; |
| | | import org.forgerock.opendj.ldap.GeneralizedTime; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.forgerock.util.promise.Function; |
| | | import org.forgerock.util.Function; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | |
| | | |
| | |
| | | package org.forgerock.opendj.server.core; |
| | | |
| | | import org.forgerock.opendj.ldap.LdapPromise; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | |
| | | /** |
| | | * A data provider which supports backup and restore functionality. |
| | |
| | | * A handler which will be notified when the backup completes. |
| | | * @return A promise representing the completion of the backup. |
| | | */ |
| | | LdapPromise<Void> createBackup(BackupConfig backupConfig, ResultHandler<Void> handler); |
| | | LdapPromise<Void> createBackup(BackupConfig backupConfig, LdapResultHandler<Void> handler); |
| | | |
| | | /** |
| | | * Returns the ID of this data provider. |
| | |
| | | * A handler which will be notified when the restore completes. |
| | | * @return A promise representing the completion of the restore. |
| | | */ |
| | | LdapPromise<Void> restoreBackup(RestoreConfig restoreConfig, ResultHandler<Void> handler); |
| | | LdapPromise<Void> restoreBackup(RestoreConfig restoreConfig, LdapResultHandler<Void> handler); |
| | | |
| | | /** |
| | | * Indicates whether this data provider provides a mechanism to perform a |
| | |
| | | package org.forgerock.opendj.server.core; |
| | | |
| | | import org.forgerock.opendj.ldap.LdapPromise; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldif.EntryWriter; |
| | | |
| | | /** |
| | |
| | | * A handler which will be notified when the export completes. |
| | | * @return A promise representing the completion of the export. |
| | | */ |
| | | LdapPromise<Void> exportEntries(EntryWriter writer, ResultHandler<Void> handler); |
| | | LdapPromise<Void> exportEntries(EntryWriter writer, LdapResultHandler<Void> handler); |
| | | |
| | | /** |
| | | * Returns the ID of this data provider. |
| | |
| | | package org.forgerock.opendj.server.core; |
| | | |
| | | import org.forgerock.opendj.ldap.LdapPromise; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | | import org.forgerock.opendj.ldif.EntryReader; |
| | | |
| | | /** |
| | |
| | | * A handler which will be notified when the import completes. |
| | | * @return A promise representing the completion of the import. |
| | | */ |
| | | LdapPromise<Void> importEntries(EntryReader reader, ResultHandler<Void> handler); |
| | | LdapPromise<Void> importEntries(EntryReader reader, LdapResultHandler<Void> handler); |
| | | } |
| | |
| | | <dependency> |
| | | <groupId>org.forgerock.commons</groupId> |
| | | <artifactId>forgerock-util</artifactId> |
| | | <version>1.3.5-SNAPSHOT</version> |
| | | <version>2.0.0-SNAPSHOT</version> |
| | | </dependency> |
| | | </dependencies> |
| | | </dependencyManagement> |