/** * Invokes the handlers for the supplied async request. Calls {@link #responseReceived(Response)} if a handler * aborts the operation. * * @param request to handle * * @throws LdapException if a handler throws */ protected void processAsyncRequest(final AsyncRequest request) throws LdapException { logger.trace("processing async request={}", request); final HandlerResult<AsyncRequest> hr = executeHandlers(getAsyncRequestHandlers(), searchRequest, request); if (hr.getAbort()) { logger.debug("Aborting search on async request=%s", request); responseReceived(new Response<>(null, null)); } }
/** * Invokes the handlers for the supplied async request. Calls {@link #responseReceived(Response)} if a handler * aborts the operation. * * @param request to handle * * @throws LdapException if a handler throws */ protected void processAsyncRequest(final AsyncRequest request) throws LdapException { logger.trace("processing async request={}", request); final HandlerResult<AsyncRequest> hr = executeHandlers(getAsyncRequestHandlers(), searchRequest, request); if (hr.getAbort()) { logger.debug("Aborting search on async request=%s", request); responseReceived(new Response<Void>(null, null)); } }
/** * Invokes the handlers for the supplied async request. Calls {@link #responseReceived(Response)} if a handler * aborts the operation. * * @param request to handle * * @throws LdapException if a handler throws */ protected void processAsyncRequest(final AsyncRequest request) throws LdapException { logger.trace("processing async request={}", request); final HandlerResult<AsyncRequest> hr = executeHandlers(getAsyncRequestHandlers(), searchRequest, request); if (hr.getAbort()) { logger.debug("Aborting search on async request=%s", request); responseReceived(new Response<>(null, null)); } }
/** * Implementation that does not require the response. * * @param conn the operation occurred on * @param request the operation executed * @param referralUrls encountered in the operation * * @return handler result * * @throws LdapException if an error occurs following referrals */ public HandlerResult<Response<S>> handle(final Connection conn, final Q request, final String[] referralUrls) throws LdapException { HandlerResult<Response<S>> result; if (referralDepth > referralLimit) { result = new HandlerResult<>( new Response<>((S) null, ResultCode.REFERRAL_LIMIT_EXCEEDED, null, null, null, null, -1)); } else { final Response<S> referralResponse = followReferral(conn, request, referralUrls); if (referralResponse != null) { result = new HandlerResult<>(referralResponse); } else { result = new HandlerResult<>(null); } } return result; }
/** * Implementation that does not require the response. * * @param conn the operation occurred on * @param request the operation executed * @param referralUrls encountered in the operation * * @return handler result * * @throws LdapException if an error occurs following referrals */ public HandlerResult<Response<S>> handle(final Connection conn, final Q request, final String[] referralUrls) throws LdapException { final HandlerResult<Response<S>> result; if (referralDepth > referralLimit) { result = new HandlerResult<>( new Response<>((S) null, ResultCode.REFERRAL_LIMIT_EXCEEDED, null, null, null, null, -1)); } else { final Response<S> referralResponse = followReferral(conn, request, referralUrls); if (referralResponse != null) { result = new HandlerResult<>(referralResponse); } else { result = new HandlerResult<>(null); } } return result; }
@Override public void responseReceived(final Response<Void> response) { searchResponse = new Response<>( searchResult, response.getResultCode(), response.getMessage(), response.getMatchedDn(), response.getControls(), response.getReferralURLs(), response.getMessageId()); responseLock.release(); }
@Override public void responseReceived(final Response<Void> response) { searchResponse = new Response<>( searchResult, response.getResultCode(), response.getMessage(), response.getMatchedDn(), response.getControls(), response.getReferralURLs(), response.getMessageId()); responseLock.release(); }
@Override public void responseReceived(final Response<Void> response) { searchResponse = new Response<>( searchResult, response.getResultCode(), response.getMessage(), response.getMatchedDn(), response.getControls(), response.getReferralURLs(), response.getMessageId()); responseLock.release(); }
@Override protected Response<SearchResult> invoke(final SearchRequest request) throws LdapException { Response<SearchResult> response; if (cache != null) { final SearchResult sr = cache.get(request); if (sr == null) { response = executeSearch(request); cache.put(request, response.getResult()); logger.debug("invoke stored result={} in cache", response.getResult()); } else { logger.debug("invoke found result={} in cache", sr); response = new Response<>(sr, null); } } else { response = executeSearch(request); } return response; }
@Override protected Response<SearchResult> invoke(final SearchRequest request) throws LdapException { final Response<SearchResult> response; if (cache != null) { final SearchResult sr = cache.get(request); if (sr == null) { response = executeSearch(request); cache.put(request, response.getResult()); logger.debug("invoke stored result={} in cache", response.getResult()); } else { logger.debug("invoke found result={} in cache", sr); response = new Response<>(sr, null); } } else { response = executeSearch(request); } return response; }
@Override public synchronized Response<Void> reopen() throws LdapException { try { if (providerConnection != null) { providerConnection.close(null); } } catch (LdapException e) { logger.warn("Error closing connection with the LDAP", e); } finally { providerConnection = null; } providerConnection = providerConnectionFactory.create(); if (config.getConnectionInitializer() != null) { return config.getConnectionInitializer().initialize(this); } else { return new Response<>(null, null); } }
@Override protected Response<SearchResult> invoke(final SearchRequest request) throws LdapException { final Response<SearchResult> response; if (cache != null) { final SearchResult sr = cache.get(request); if (sr == null) { response = executeSearch(request); cache.put(request, response.getResult()); logger.debug("invoke stored result={} in cache", response.getResult()); } else { logger.debug("invoke found result={} in cache", sr); response = new Response<>(sr, null); } } else { response = executeSearch(request); } return response; }
@Override public synchronized Response<Void> reopen() throws LdapException { try { if (providerConnection != null) { providerConnection.close(null); } } catch (LdapException e) { logger.warn("Error closing connection with the LDAP", e); } finally { providerConnection = null; } providerConnection = providerConnectionFactory.create(); if (config.getConnectionInitializer() != null) { return config.getConnectionInitializer().initialize(this); } else { return new Response<>(null, null); } }
@Override public synchronized Response<Void> reopen() throws LdapException { try { if (providerConnection != null) { providerConnection.close(null); } } catch (LdapException e) { logger.warn("Error closing connection with the LDAP", e); } finally { providerConnection = null; } providerConnection = providerConnectionFactory.create(); if (config.getConnectionInitializer() != null) { return config.getConnectionInitializer().initialize(this); } else { return new Response<>(null, null); } }
/** * This will establish a connection if one does not already exist. This connection should be closed using {@link * #close()}. * * @return response associated with the {@link ConnectionInitializer} or an empty response if no connection * initializer was configured * * @throws IllegalStateException if the connection is already open * @throws LdapException if the LDAP cannot be reached */ @Override public synchronized Response<Void> open() throws LdapException { if (isOpen()) { throw new IllegalStateException("Connection already open"); } providerConnection = providerConnectionFactory.create(); if (config.getConnectionInitializer() != null) { return config.getConnectionInitializer().initialize(this); } else { return new Response<>(null, null); } }
/** * This will establish a connection if one does not already exist. This connection should be closed using {@link * #close()}. * * @return response associated with the {@link ConnectionInitializer} or an empty response if no connection * initializer was configured * * @throws IllegalStateException if the connection is already open * @throws LdapException if the LDAP cannot be reached */ @Override public synchronized Response<Void> open() throws LdapException { if (isOpen()) { throw new IllegalStateException("Connection already open"); } providerConnection = providerConnectionFactory.create(); if (config.getConnectionInitializer() != null) { return config.getConnectionInitializer().initialize(this); } else { return new Response<>(null, null); } }
@Override public HandlerResult<Response<S>> handle(final Connection conn, final Q request, final Response<S> response) throws LdapException { final HandlerResult<Response<S>> result; if (referralDepth > referralLimit) { result = new HandlerResult<>( new Response<>( response.getResult(), ResultCode.REFERRAL_LIMIT_EXCEEDED, response.getMessage(), response.getMatchedDn(), response.getControls(), response.getReferralURLs(), response.getMessageId())); } else { final Response<S> referralResponse = followReferral(conn, request, response.getReferralURLs()); if (referralResponse != null) { result = new HandlerResult<>(referralResponse); } else { result = new HandlerResult<>(response); } } return result; }
/** * Creates an operation response with the supplied response data. * * @param <T> type of response * @param request containing controls * @param result of the operation * @param resultResponse provider response * * @return operation response */ protected <T> Response<T> createResponse(final Request request, final T result, final ResultResponse resultResponse) { final LdapResult ldapResult = resultResponse.getLdapResult(); final Referral ref = ldapResult.getReferral(); return new Response<>( result, ResultCode.valueOf(ldapResult.getResultCode().getValue()), ldapResult.getDiagnosticMessage(), ldapResult.getMatchedDn() != null ? ldapResult.getMatchedDn().getName() : null, processResponseControls(config.getControlProcessor(), request.getControls(), resultResponse), ref != null ? ref.getLdapUrls().toArray(new String[ref.getReferralLength()]) : null, resultResponse.getMessageId()); }
/** * Performs the ldap search. * * @param request to invoke search with * * @return ldap response * * @throws LdapException if an error occurs */ protected Response<SearchResult> executeSearch(final SearchRequest request) throws LdapException { final SearchIterator si = getConnection().getProviderConnection().search(request); final SearchResult result = readResult(request, si); final Response<Void> response = si.getResponse(); return new Response<>( result, response.getResultCode(), response.getMessage(), response.getMatchedDn(), response.getControls(), response.getReferralURLs(), response.getMessageId()); }
/** * Performs the ldap search. * * @param request to invoke search with * * @return ldap response * * @throws LdapException if an error occurs */ protected Response<SearchResult> executeSearch(final SearchRequest request) throws LdapException { final SearchIterator si = getConnection().getProviderConnection().search(request); final SearchResult result = readResult(request, si); final Response<Void> response = si.getResponse(); return new Response<>( result, response.getResultCode(), response.getMessage(), response.getMatchedDn(), response.getControls(), response.getReferralURLs(), response.getMessageId()); }