use of com.unboundid.ldap.protocol.CompareResponseProtocolOp in project ldapsdk by pingidentity.
the class LDAPListenerClientConnection method run.
/**
* Operates in a loop, waiting for a request to arrive from the client and
* handing it off to the request handler for processing. This method is for
* internal use only and must not be invoked by external callers.
*/
@InternalUseOnly()
@Override()
public void run() {
try {
while (true) {
final LDAPMessage requestMessage;
try {
requestMessage = LDAPMessage.readFrom(asn1Reader, false);
if (requestMessage == null) {
// so we won't notify the exception handler.
try {
close();
} catch (final IOException ioe) {
Debug.debugException(ioe);
}
return;
}
} catch (final LDAPException le) {
// This indicates that the client sent a malformed request.
Debug.debugException(le);
close(le);
return;
}
try {
final int messageID = requestMessage.getMessageID();
final List<Control> controls = requestMessage.getControls();
LDAPMessage responseMessage;
switch(requestMessage.getProtocolOpType()) {
case LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST:
requestHandler.processAbandonRequest(messageID, requestMessage.getAbandonRequestProtocolOp(), controls);
responseMessage = null;
break;
case LDAPMessage.PROTOCOL_OP_TYPE_ADD_REQUEST:
try {
responseMessage = requestHandler.processAddRequest(messageID, requestMessage.getAddRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new AddResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_BIND_REQUEST:
try {
responseMessage = requestHandler.processBindRequest(messageID, requestMessage.getBindRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new BindResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null, null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_COMPARE_REQUEST:
try {
responseMessage = requestHandler.processCompareRequest(messageID, requestMessage.getCompareRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_DELETE_REQUEST:
try {
responseMessage = requestHandler.processDeleteRequest(messageID, requestMessage.getDeleteRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_EXTENDED_REQUEST:
try {
responseMessage = requestHandler.processExtendedRequest(messageID, requestMessage.getExtendedRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new ExtendedResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null, null, null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_REQUEST:
try {
responseMessage = requestHandler.processModifyRequest(messageID, requestMessage.getModifyRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new ModifyResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_DN_REQUEST:
try {
responseMessage = requestHandler.processModifyDNRequest(messageID, requestMessage.getModifyDNRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new ModifyDNResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_REQUEST:
try {
responseMessage = requestHandler.processSearchRequest(messageID, requestMessage.getSearchRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new SearchResultDoneProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST:
requestHandler.processUnbindRequest(messageID, requestMessage.getUnbindRequestProtocolOp(), controls);
close();
return;
default:
close(new LDAPException(ResultCode.PROTOCOL_ERROR, ERR_CONN_INVALID_PROTOCOL_OP_TYPE.get(StaticUtils.toHex(requestMessage.getProtocolOpType()))));
return;
}
if (responseMessage != null) {
try {
sendMessage(responseMessage);
} catch (final LDAPException le) {
Debug.debugException(le);
close(le);
return;
}
}
} catch (final Throwable t) {
close(new LDAPException(ResultCode.LOCAL_ERROR, ERR_CONN_EXCEPTION_IN_REQUEST_HANDLER.get(String.valueOf(requestMessage), StaticUtils.getExceptionMessage(t))));
StaticUtils.throwErrorOrRuntimeException(t);
}
}
} finally {
if (listener != null) {
listener.connectionClosed(this);
}
}
}
use of com.unboundid.ldap.protocol.CompareResponseProtocolOp in project ldapsdk by pingidentity.
the class LDAPDebuggerTestCase method testFailedCompare.
/**
* Provides test coverage for a failed compare operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testFailedCompare() throws Exception {
TestRequestHandler.setReturnOp(new CompareResponseProtocolOp(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.compare("dc=example,dc=com", "foo", "bar");
}
use of com.unboundid.ldap.protocol.CompareResponseProtocolOp in project ldapsdk by pingidentity.
the class AccessLogRequestHandler method processCompareRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processCompareRequest(final int messageID, @NotNull final CompareRequestProtocolOp request, @NotNull final List<Control> controls) {
final long opID = nextOperationID.getAndIncrement();
final StringBuilder b = getRequestHeader("COMPARE", opID, messageID);
b.append(" dn=\"");
b.append(request.getDN());
b.append("\" attr=\"");
b.append(request.getAttributeName());
b.append('"');
logHandler.publish(new LogRecord(Level.INFO, b.toString()));
logHandler.flush();
final long startTimeNanos = System.nanoTime();
final LDAPMessage responseMessage = requestHandler.processCompareRequest(messageID, request, controls);
final long eTimeNanos = System.nanoTime() - startTimeNanos;
final CompareResponseProtocolOp protocolOp = responseMessage.getCompareResponseProtocolOp();
generateResponse(b, "COMPARE", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
logHandler.publish(new LogRecord(Level.INFO, b.toString()));
logHandler.flush();
return responseMessage;
}
use of com.unboundid.ldap.protocol.CompareResponseProtocolOp in project ldapsdk by pingidentity.
the class LDAPDebuggerTestCase method testSuccessfulCompare.
/**
* Provides test coverage for a successful compare operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSuccessfulCompare() throws Exception {
TestRequestHandler.setReturnOp(new CompareResponseProtocolOp(6, null, null, null));
final CompareRequest r = new CompareRequest("dc=example,dc=com", "foo", "bar");
r.addControl(new Control("1.2.3.4"));
conn.compare(r);
}
use of com.unboundid.ldap.protocol.CompareResponseProtocolOp 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