/** * Executes an ldap search. * * @param conn to search with * @param sr to read properties from * @return ldap search queue * @throws LDAPException if an error occurs */ protected LDAPSearchQueue search(final LDAPConnection conn, final SearchRequest sr) throws LDAPException { final SearchResultIterator i = new SearchResultIterator(super.search(conn, sr)); listener.asyncRequestReceived(new JLdapAsyncRequest(i.getLDAPSearchQueue())); while (i.hasNext()) { final LDAPMessage message = i.next(); if (message instanceof LDAPSearchResult) { listener.searchItemReceived(processLDAPSearchResult((LDAPSearchResult) message)); } else if (message instanceof LDAPSearchResultReference) { listener.searchItemReceived( processLDAPSearchResultReference((LDAPSearchResultReference) message)); } else if (message instanceof LDAPIntermediateResponse) { listener.searchItemReceived( processLDAPIntermediateResponse((LDAPIntermediateResponse) message)); } else { throw new IllegalStateException("Unknown message: " + message); } } final Response<Void> response = createResponse(request, null, i.getResponse()); listener.responseReceived(response); return null; }
/** {@inheritDoc} */ @Override public boolean hasNext() throws LdapException { if (resultIterator == null || response != null) { return false; } boolean more = false; try { more = resultIterator.hasNext(); if (!more) { final LDAPResponse res = resultIterator.getResponse(); logger.trace("reading search response: {}", res); throwOperationException(request, res); response = createResponse(request, null, res); } } catch (LDAPException e) { final ResultCode rc = ignoreSearchException(config.getSearchIgnoreResultCodes(), e); if (rc == null) { processLDAPException(e); } response = new Response<Void>(null, rc, e.getLDAPErrorMessage(), null, null, null, -1); } return more; }