use of com.unboundid.ldap.protocol.SearchResultDoneProtocolOp in project ldapsdk by pingidentity.
the class ProxyRequestHandler method processSearchRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processSearchRequest(final int messageID, @NotNull final SearchRequestProtocolOp request, @NotNull final List<Control> controls) {
final String[] attrs;
final List<String> attrList = request.getAttributes();
if (attrList.isEmpty()) {
attrs = StaticUtils.NO_STRINGS;
} else {
attrs = new String[attrList.size()];
attrList.toArray(attrs);
}
final ProxySearchResultListener searchListener = new ProxySearchResultListener(listenerConnection, messageID);
final SearchRequest searchRequest = new SearchRequest(searchListener, request.getBaseDN(), request.getScope(), request.getDerefPolicy(), request.getSizeLimit(), request.getTimeLimit(), request.typesOnly(), request.getFilter(), attrs);
if (!controls.isEmpty()) {
searchRequest.setControls(controls);
}
searchRequest.setIntermediateResponseListener(this);
LDAPResult searchResult;
try {
searchResult = ldapConnection.search(searchRequest);
} catch (final LDAPException le) {
Debug.debugException(le);
searchResult = le.toLDAPResult();
}
final SearchResultDoneProtocolOp searchResultDoneProtocolOp = new SearchResultDoneProtocolOp(searchResult.getResultCode().intValue(), searchResult.getMatchedDN(), searchResult.getDiagnosticMessage(), Arrays.asList(searchResult.getReferralURLs()));
return new LDAPMessage(messageID, searchResultDoneProtocolOp, Arrays.asList(searchResult.getResponseControls()));
}
use of com.unboundid.ldap.protocol.SearchResultDoneProtocolOp in project ldapsdk by pingidentity.
the class InMemoryOperationInterceptorRequestHandler method processSearchRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processSearchRequest(final int messageID, @NotNull final SearchRequestProtocolOp request, @NotNull final List<Control> controls) {
final InterceptedSearchOperation op = new InterceptedSearchOperation(connection, messageID, request, toArray(controls));
activeOperations.put(messageID, op);
try {
for (final InMemoryOperationInterceptor i : interceptors) {
try {
i.processSearchRequest(op);
} catch (final LDAPException le) {
Debug.debugException(le);
return new LDAPMessage(messageID, new SearchResultDoneProtocolOp(le.toLDAPResult()), le.getResponseControls());
} catch (final Exception e) {
Debug.debugException(e);
return new LDAPMessage(messageID, new SearchResultDoneProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_REQUEST_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null));
}
}
final LDAPMessage resultMessage = wrappedHandler.processSearchRequest(messageID, new SearchRequestProtocolOp((SearchRequest) op.getRequest()), op.getRequest().getControlList());
op.setResult(resultMessage.getSearchResultDoneProtocolOp().toLDAPResult(toArray(resultMessage.getControls())));
for (final InMemoryOperationInterceptor i : interceptors) {
try {
i.processSearchResult(op);
} catch (final Exception e) {
Debug.debugException(e);
return new LDAPMessage(messageID, new SearchResultDoneProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_RESULT_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null));
}
}
return new LDAPMessage(messageID, new SearchResultDoneProtocolOp(op.getResult()), op.getResult().getResponseControls());
} finally {
activeOperations.remove(messageID);
}
}
use of com.unboundid.ldap.protocol.SearchResultDoneProtocolOp in project ldapsdk by pingidentity.
the class LDAPDebuggerTestCase method testSuccessfulSearch.
/**
* Provides test coverage for a successful search operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSuccessfulSearch() throws Exception {
TestRequestHandler.setReturnOp(new SearchResultDoneProtocolOp(0, null, null, null));
TestRequestHandler.setReturnEntries(new SearchResultEntryProtocolOp("dc=example,dc=com", Arrays.asList(new Attribute("objectClass", "top", "domain"), new Attribute("dc", "example"))));
TestRequestHandler.setReturnReferences(new SearchResultReferenceProtocolOp(Arrays.asList("ldap://server1.example.com/dc=example,dc=com", "ldap://server2.example.com/dc=example,dc=com")));
try {
final SearchRequest r = new SearchRequest("dc=example,dc=com", SearchScope.BASE, "(objectClass=*)");
r.addControl(new Control("1.2.3.4"));
conn.search(r);
} finally {
TestRequestHandler.setReturnEntries();
TestRequestHandler.setReturnReferences();
}
}
use of com.unboundid.ldap.protocol.SearchResultDoneProtocolOp in project ldapsdk by pingidentity.
the class LDAPDebuggerTestCase method testFailedSearch.
/**
* Provides test coverage for a failed search operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testFailedSearch() throws Exception {
TestRequestHandler.setReturnOp(new SearchResultDoneProtocolOp(32, "dc=example,dc=com", "msg", Arrays.asList("ldap://server1.example.com/dc=example,dc=com", "ldap://server2.example.com/dc=example,dc=com")));
conn.search("dc=example,dc=com", SearchScope.BASE, "(objectClass=*)", "*", "+");
}
use of com.unboundid.ldap.protocol.SearchResultDoneProtocolOp in project ldapsdk by pingidentity.
the class CannedResponseRequestHandlerTestCase method testDefaultConstructor.
/**
* Tests the behavior of the request handler with the default configuration.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDefaultConstructor() throws Exception {
final CannedResponseRequestHandler handler = new CannedResponseRequestHandler().newInstance(null);
LDAPMessage m = handler.processAddRequest(1, new AddRequestProtocolOp("dc=example,dc=com", Arrays.asList(new Attribute("objectClass", "top", "domain"), new Attribute("dc", "example"))), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 1);
assertTrue(m.getProtocolOp() instanceof AddResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processBindRequest(2, new BindRequestProtocolOp("uid=admin,dc=example,dc=com", "password"), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 2);
assertTrue(m.getProtocolOp() instanceof BindResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processCompareRequest(3, new CompareRequestProtocolOp("dc=example,dc=com", "objectClass", new ASN1OctetString("top")), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 3);
assertTrue(m.getProtocolOp() instanceof CompareResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processDeleteRequest(4, new DeleteRequestProtocolOp("dc=example,dc=com"), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 4);
assertTrue(m.getProtocolOp() instanceof DeleteResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processExtendedRequest(5, new ExtendedRequestProtocolOp("1.2.3.4", null), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 5);
assertTrue(m.getProtocolOp() instanceof ExtendedResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processModifyRequest(6, new ModifyRequestProtocolOp("dc=example,dc=com", Arrays.asList(new Modification(ModificationType.REPLACE, "description", "foo"))), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 6);
assertTrue(m.getProtocolOp() instanceof ModifyResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processModifyDNRequest(6, new ModifyDNRequestProtocolOp("ou=People,dc=example,dc=com", "ou=Users", true, null), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 6);
assertTrue(m.getProtocolOp() instanceof ModifyDNResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processSearchRequest(7, new SearchRequestProtocolOp("dc=example,dc=com", SearchScope.SUB, DereferencePolicy.NEVER, 0, 0, false, Filter.createEqualityFilter("uid", "test"), Arrays.<String>asList()), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 7);
assertTrue(m.getProtocolOp() instanceof SearchResultDoneProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
}
Aggregations