Search in sources :

Example 11 with SearchResultDoneProtocolOp

use of com.unboundid.ldap.protocol.SearchResultDoneProtocolOp in project ldapsdk by pingidentity.

the class InMemoryDirectoryServer method search.

/**
 * {@inheritDoc}
 * <BR><BR>
 * This method may be used regardless of whether the server is listening for
 * client connections, and regardless of whether search operations are allowed
 * in the server.
 */
@Override()
@NotNull()
public SearchResult search(@NotNull final SearchRequest searchRequest) throws LDAPSearchException {
    final ArrayList<Control> requestControlList = new ArrayList<>(searchRequest.getControlList());
    requestControlList.add(new Control(InMemoryRequestHandler.OID_INTERNAL_OPERATION_REQUEST_CONTROL, false));
    final List<SearchResultEntry> entryList = new ArrayList<>(10);
    final List<SearchResultReference> referenceList = new ArrayList<>(10);
    final LDAPMessage responseMessage = inMemoryHandler.processSearchRequest(1, new SearchRequestProtocolOp(searchRequest.getBaseDN(), searchRequest.getScope(), searchRequest.getDereferencePolicy(), searchRequest.getSizeLimit(), searchRequest.getTimeLimitSeconds(), searchRequest.typesOnly(), searchRequest.getFilter(), searchRequest.getAttributeList()), requestControlList, entryList, referenceList);
    final List<SearchResultEntry> returnEntryList;
    final List<SearchResultReference> returnReferenceList;
    final SearchResultListener searchListener = searchRequest.getSearchResultListener();
    if (searchListener == null) {
        returnEntryList = Collections.unmodifiableList(entryList);
        returnReferenceList = Collections.unmodifiableList(referenceList);
    } else {
        returnEntryList = null;
        returnReferenceList = null;
        for (final SearchResultEntry e : entryList) {
            searchListener.searchEntryReturned(e);
        }
        for (final SearchResultReference r : referenceList) {
            searchListener.searchReferenceReturned(r);
        }
    }
    final SearchResultDoneProtocolOp searchDone = responseMessage.getSearchResultDoneProtocolOp();
    final ResultCode rc = ResultCode.valueOf(searchDone.getResultCode());
    final String[] referralURLs;
    final List<String> referralURLList = searchDone.getReferralURLs();
    if ((referralURLList == null) || referralURLList.isEmpty()) {
        referralURLs = StaticUtils.NO_STRINGS;
    } else {
        referralURLs = new String[referralURLList.size()];
        referralURLList.toArray(referralURLs);
    }
    final Control[] responseControls;
    final List<Control> controlList = responseMessage.getControls();
    if ((controlList == null) || controlList.isEmpty()) {
        responseControls = StaticUtils.NO_CONTROLS;
    } else {
        responseControls = new Control[controlList.size()];
        controlList.toArray(responseControls);
    }
    final SearchResult searchResult = new SearchResult(responseMessage.getMessageID(), rc, searchDone.getDiagnosticMessage(), searchDone.getMatchedDN(), referralURLs, returnEntryList, returnReferenceList, entryList.size(), referenceList.size(), responseControls);
    if (rc == ResultCode.SUCCESS) {
        return searchResult;
    } else {
        throw new LDAPSearchException(searchResult);
    }
}
Also used : SearchRequestProtocolOp(com.unboundid.ldap.protocol.SearchRequestProtocolOp) ArrayList(java.util.ArrayList) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) SearchResultReference(com.unboundid.ldap.sdk.SearchResultReference) SearchResult(com.unboundid.ldap.sdk.SearchResult) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) SearchResultListener(com.unboundid.ldap.sdk.SearchResultListener) SearchResultDoneProtocolOp(com.unboundid.ldap.protocol.SearchResultDoneProtocolOp) LDAPSearchException(com.unboundid.ldap.sdk.LDAPSearchException) ResultCode(com.unboundid.ldap.sdk.ResultCode) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) NotNull(com.unboundid.util.NotNull)

Example 12 with SearchResultDoneProtocolOp

use of com.unboundid.ldap.protocol.SearchResultDoneProtocolOp in project ldapsdk by pingidentity.

the class LDAPDebuggerRequestHandler method processSearchRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processSearchRequest(final int messageID, @NotNull final SearchRequestProtocolOp request, @NotNull final List<Control> controls) {
    final StringBuilder b = getBuffer();
    appendHeader(b, messageID);
    b.append("     Search Request Protocol Op:").append(StaticUtils.EOL);
    b.append("          Base DN:  ").append(request.getBaseDN()).append(StaticUtils.EOL);
    b.append("          Scope:  ").append(request.getScope()).append(StaticUtils.EOL);
    b.append("          Dereference Policy:  ").append(request.getDerefPolicy()).append(StaticUtils.EOL);
    b.append("          Size Limit:  ").append(request.getSizeLimit()).append(StaticUtils.EOL);
    b.append("          Time Limit:  ").append(request.getSizeLimit()).append(StaticUtils.EOL);
    b.append("          Types Only:  ").append(request.typesOnly()).append(StaticUtils.EOL);
    b.append("          Filter:  ");
    request.getFilter().toString(b);
    b.append(StaticUtils.EOL);
    final List<String> attributes = request.getAttributes();
    if (!attributes.isEmpty()) {
        b.append("          Requested Attributes:").append(StaticUtils.EOL);
        for (final String attr : attributes) {
            b.append("               ").append(attr).append(StaticUtils.EOL);
        }
    }
    appendControls(b, controls);
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    final LDAPMessage responseMessage = requestHandler.processSearchRequest(messageID, request, controls);
    b.setLength(0);
    appendHeader(b, responseMessage.getMessageID());
    b.append("     Search Result Done Protocol Op:").append(StaticUtils.EOL);
    final SearchResultDoneProtocolOp protocolOp = responseMessage.getSearchResultDoneProtocolOp();
    appendResponse(b, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs());
    appendControls(b, responseMessage.getControls());
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    return responseMessage;
}
Also used : LogRecord(java.util.logging.LogRecord) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) SearchResultDoneProtocolOp(com.unboundid.ldap.protocol.SearchResultDoneProtocolOp) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) NotNull(com.unboundid.util.NotNull)

Example 13 with SearchResultDoneProtocolOp

use of com.unboundid.ldap.protocol.SearchResultDoneProtocolOp in project ldapsdk by pingidentity.

the class AccessLogRequestHandler method processSearchRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processSearchRequest(final int messageID, @NotNull final SearchRequestProtocolOp request, @NotNull final List<Control> controls) {
    final long opID = nextOperationID.getAndIncrement();
    final StringBuilder b = getRequestHeader("SEARCH", opID, messageID);
    b.append(" base=\"");
    b.append(request.getBaseDN());
    b.append("\" scope=");
    b.append(request.getScope().intValue());
    b.append(" filter=\"");
    request.getFilter().toString(b);
    b.append("\" attrs=\"");
    final List<String> attrList = request.getAttributes();
    if (attrList.isEmpty()) {
        b.append("ALL");
    } else {
        final Iterator<String> iterator = attrList.iterator();
        while (iterator.hasNext()) {
            b.append(iterator.next());
            if (iterator.hasNext()) {
                b.append(',');
            }
        }
    }
    b.append('"');
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    final AtomicLong l = new AtomicLong(0L);
    entryCounts.put(messageID, l);
    try {
        final long startTimeNanos = System.nanoTime();
        final LDAPMessage responseMessage = requestHandler.processSearchRequest(messageID, request, controls);
        final long eTimeNanos = System.nanoTime() - startTimeNanos;
        final SearchResultDoneProtocolOp protocolOp = responseMessage.getSearchResultDoneProtocolOp();
        generateResponse(b, "SEARCH", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
        b.append(" entriesReturned=");
        b.append(l.get());
        logHandler.publish(new LogRecord(Level.INFO, b.toString()));
        logHandler.flush();
        return responseMessage;
    } finally {
        entryCounts.remove(messageID);
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) LogRecord(java.util.logging.LogRecord) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) SearchResultDoneProtocolOp(com.unboundid.ldap.protocol.SearchResultDoneProtocolOp) NotNull(com.unboundid.util.NotNull)

Aggregations

SearchResultDoneProtocolOp (com.unboundid.ldap.protocol.SearchResultDoneProtocolOp)13 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)11 NotNull (com.unboundid.util.NotNull)8 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5 Control (com.unboundid.ldap.sdk.Control)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)5 SearchRequestProtocolOp (com.unboundid.ldap.protocol.SearchRequestProtocolOp)4 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)3 Attribute (com.unboundid.ldap.sdk.Attribute)3 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)3 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)3 ArrayList (java.util.ArrayList)3 Test (org.testng.annotations.Test)3 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)2 BindRequestProtocolOp (com.unboundid.ldap.protocol.BindRequestProtocolOp)2 CompareResponseProtocolOp (com.unboundid.ldap.protocol.CompareResponseProtocolOp)2 DeleteResponseProtocolOp (com.unboundid.ldap.protocol.DeleteResponseProtocolOp)2 ExtendedResponseProtocolOp (com.unboundid.ldap.protocol.ExtendedResponseProtocolOp)2 ModifyDNResponseProtocolOp (com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp)2 ModifyResponseProtocolOp (com.unboundid.ldap.protocol.ModifyResponseProtocolOp)2