use of org.apache.directory.api.ldap.model.message.CompareResponse in project directory-ldap-api by apache.
the class LdapNetworkConnection method compare.
/**
* {@inheritDoc}
*/
@Override
public boolean compare(Dn dn, String attributeName, Value value) throws LdapException {
CompareRequest compareRequest = new CompareRequestImpl();
compareRequest.setName(dn);
compareRequest.setAttributeId(attributeName);
if (value.isHumanReadable()) {
compareRequest.setAssertionValue(value.getValue());
} else {
compareRequest.setAssertionValue(value.getBytes());
}
CompareResponse compareResponse = compare(compareRequest);
return processResponse(compareResponse);
}
use of org.apache.directory.api.ldap.model.message.CompareResponse in project directory-ldap-api by apache.
the class LdapNetworkConnection method compare.
/**
* {@inheritDoc}
*/
@Override
public boolean compare(Dn dn, String attributeName, String value) throws LdapException {
CompareRequest compareRequest = new CompareRequestImpl();
compareRequest.setName(dn);
compareRequest.setAttributeId(attributeName);
compareRequest.setAssertionValue(value);
CompareResponse compareResponse = compare(compareRequest);
return processResponse(compareResponse);
}
use of org.apache.directory.api.ldap.model.message.CompareResponse in project directory-ldap-api by apache.
the class MessageDecorator method getDecorator.
/**
* Gets the decorator associated with a given message
*
* @param codec The LdapApiService to use
* @param decoratedMessage The message to decorate
* @return The decorator instance
*/
public static MessageDecorator<? extends Message> getDecorator(LdapApiService codec, Message decoratedMessage) {
if (decoratedMessage instanceof MessageDecorator) {
return (MessageDecorator<?>) decoratedMessage;
}
MessageDecorator<?> decorator;
switch(decoratedMessage.getType()) {
case ABANDON_REQUEST:
decorator = new AbandonRequestDecorator(codec, (AbandonRequest) decoratedMessage);
break;
case ADD_REQUEST:
decorator = new AddRequestDecorator(codec, (AddRequest) decoratedMessage);
break;
case ADD_RESPONSE:
decorator = new AddResponseDecorator(codec, (AddResponse) decoratedMessage);
break;
case BIND_REQUEST:
decorator = new BindRequestDecorator(codec, (BindRequest) decoratedMessage);
break;
case BIND_RESPONSE:
decorator = new BindResponseDecorator(codec, (BindResponse) decoratedMessage);
break;
case COMPARE_REQUEST:
decorator = new CompareRequestDecorator(codec, (CompareRequest) decoratedMessage);
break;
case COMPARE_RESPONSE:
decorator = new CompareResponseDecorator(codec, (CompareResponse) decoratedMessage);
break;
case DEL_REQUEST:
decorator = new DeleteRequestDecorator(codec, (DeleteRequest) decoratedMessage);
break;
case DEL_RESPONSE:
decorator = new DeleteResponseDecorator(codec, (DeleteResponse) decoratedMessage);
break;
case EXTENDED_REQUEST:
decorator = codec.decorate((ExtendedRequest) decoratedMessage);
break;
case EXTENDED_RESPONSE:
decorator = codec.decorate((ExtendedResponse) decoratedMessage);
break;
case INTERMEDIATE_RESPONSE:
decorator = new IntermediateResponseDecorator(codec, (IntermediateResponse) decoratedMessage);
break;
case MODIFY_REQUEST:
decorator = new ModifyRequestDecorator(codec, (ModifyRequest) decoratedMessage);
break;
case MODIFY_RESPONSE:
decorator = new ModifyResponseDecorator(codec, (ModifyResponse) decoratedMessage);
break;
case MODIFYDN_REQUEST:
decorator = new ModifyDnRequestDecorator(codec, (ModifyDnRequest) decoratedMessage);
break;
case MODIFYDN_RESPONSE:
decorator = new ModifyDnResponseDecorator(codec, (ModifyDnResponse) decoratedMessage);
break;
case SEARCH_REQUEST:
decorator = new SearchRequestDecorator(codec, (SearchRequest) decoratedMessage);
break;
case SEARCH_RESULT_DONE:
decorator = new SearchResultDoneDecorator(codec, (SearchResultDone) decoratedMessage);
break;
case SEARCH_RESULT_ENTRY:
decorator = new SearchResultEntryDecorator(codec, (SearchResultEntry) decoratedMessage);
break;
case SEARCH_RESULT_REFERENCE:
decorator = new SearchResultReferenceDecorator(codec, (SearchResultReference) decoratedMessage);
break;
case UNBIND_REQUEST:
decorator = new UnbindRequestDecorator(codec, (UnbindRequest) decoratedMessage);
break;
default:
return null;
}
Map<String, Control> controls = decoratedMessage.getControls();
if (controls != null) {
for (Control control : controls.values()) {
decorator.addControl(control);
}
}
return decorator;
}
use of org.apache.directory.api.ldap.model.message.CompareResponse in project directory-ldap-api by apache.
the class LdapNetworkConnection method compare.
/**
* {@inheritDoc}
*/
@Override
public CompareResponse compare(CompareRequest compareRequest) throws LdapException {
if (compareRequest == null) {
String msg = "Cannot process a null compareRequest";
LOG.debug(msg);
throw new IllegalArgumentException(msg);
}
CompareFuture compareFuture = compareAsync(compareRequest);
// Get the result from the future
try {
// Read the response, waiting for it if not available immediately
// Get the response, blocking
CompareResponse compareResponse = compareFuture.get(timeout, TimeUnit.MILLISECONDS);
if (compareResponse == null) {
// We didn't received anything : this is an error
if (LOG.isErrorEnabled()) {
LOG.error(I18n.err(I18n.ERR_03203_OP_FAILED_TIMEOUT, "Compare"));
}
throw new LdapException(TIME_OUT_ERROR);
}
if (compareResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
// Everything is fine, return the response
if (LOG.isDebugEnabled()) {
LOG.debug(I18n.msg(I18n.MSG_03215_COMPARE_SUCCESSFUL, compareResponse));
}
} else {
// We have had an error
if (LOG.isDebugEnabled()) {
LOG.debug(I18n.msg(I18n.MSG_03214_COMPARE_FAILED, compareResponse));
}
}
return compareResponse;
} catch (Exception ie) {
// Catch all other exceptions
LOG.error(NO_RESPONSE_ERROR, ie);
// Send an abandon request
if (!compareFuture.isCancelled()) {
abandon(compareRequest.getMessageId());
}
throw new LdapException(NO_RESPONSE_ERROR, ie);
}
}
use of org.apache.directory.api.ldap.model.message.CompareResponse in project directory-ldap-api by apache.
the class LdapNetworkConnection method compare.
/**
* {@inheritDoc}
*/
@Override
public boolean compare(Dn dn, String attributeName, byte[] value) throws LdapException {
CompareRequest compareRequest = new CompareRequestImpl();
compareRequest.setName(dn);
compareRequest.setAttributeId(attributeName);
compareRequest.setAssertionValue(value);
CompareResponse compareResponse = compare(compareRequest);
return processResponse(compareResponse);
}
Aggregations