use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class ModifyRequestTest method testRequestWithModificationWithEmptyValue.
/**
* Test parsing of a request with a Modification element with an empty value
* @throws NamingException
*/
@Test
public void testRequestWithModificationWithEmptyValue() throws LdapException {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(ModifyRequestTest.class.getResource("request_with_modification_with_empty_value.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
Collection<Modification> modifications = modifyRequest.getModifications();
assertEquals(1, modifications.size());
Modification modification = modifications.iterator().next();
assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
Attribute attribute = modification.getAttribute();
assertEquals("directreport", attribute.getId());
assertEquals(1, attribute.size());
assertEquals("", attribute.get().getValue());
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class LdapNetworkConnection method bind.
/**
* Bind to the server using a CramMd5Request object.
*
* @param request The CramMd5Request POJO containing all the needed parameters
* @return A LdapResponse containing the result
* @throws LdapException if some error occurred
*/
public BindResponse bind(SaslCramMd5Request request) throws LdapException {
if (request == null) {
String msg = I18n.msg(I18n.MSG_03204_NULL_REQUEST);
LOG.debug(msg);
throw new IllegalArgumentException(msg);
}
BindFuture bindFuture = bindAsync(request);
// Get the result from the future
try {
// Read the response, waiting for it if not available immediately
// Get the response, blocking
BindResponse bindResponse = bindFuture.get(timeout, TimeUnit.MILLISECONDS);
if (bindResponse == null) {
// We didn't received anything : this is an error
if (LOG.isErrorEnabled()) {
LOG.error(I18n.err(I18n.ERR_03203_OP_FAILED_TIMEOUT, "Bind"));
}
throw new LdapException(TIME_OUT_ERROR);
}
if (bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
authenticated.set(true);
// Everything is fine, return the response
if (LOG.isDebugEnabled()) {
LOG.debug(I18n.msg(I18n.MSG_03202_BIND_SUCCESSFUL, bindResponse));
}
} else {
// We have had an error
if (LOG.isDebugEnabled()) {
LOG.debug(I18n.msg(I18n.MSG_03201_BIND_FAIL, bindResponse));
}
}
return bindResponse;
} catch (Exception ie) {
// Catch all other exceptions
LOG.error(NO_RESPONSE_ERROR, ie);
throw new LdapException(NO_RESPONSE_ERROR, ie);
}
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class LdapNetworkConnection method extended.
/**
* {@inheritDoc}
*/
@Override
public ExtendedResponse extended(ExtendedRequest extendedRequest) throws LdapException {
if (extendedRequest == null) {
String msg = "Cannot process a null extendedRequest";
LOG.debug(msg);
throw new IllegalArgumentException(msg);
}
ExtendedFuture extendedFuture = extendedAsync(extendedRequest);
// Get the result from the future
try {
// Read the response, waiting for it if not available immediately
// Get the response, blocking
ExtendedResponse response = (ExtendedResponse) extendedFuture.get(timeout, TimeUnit.MILLISECONDS);
if (response == null) {
// We didn't received anything : this is an error
if (LOG.isErrorEnabled()) {
LOG.error(I18n.err(I18n.ERR_03203_OP_FAILED_TIMEOUT, "Extended"));
}
throw new LdapException(TIME_OUT_ERROR);
}
if (response.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
// Everything is fine, return the response
if (LOG.isDebugEnabled()) {
LOG.debug(I18n.msg(I18n.MSG_03219_EXTENDED_SUCCESSFUL, response));
}
} else {
// We have had an error
if (LOG.isDebugEnabled()) {
LOG.debug(I18n.msg(I18n.MSG_03218_EXTENDED_FAILED, response));
}
}
// Get back the response. It's still an opaque response
if (Strings.isEmpty(response.getResponseName())) {
response.setResponseName(extendedRequest.getRequestName());
}
// Decode the payload now
return codec.decorate(response);
} catch (Exception ie) {
// Catch all other exceptions
LOG.error(NO_RESPONSE_ERROR, ie);
// Send an abandon request
if (!extendedFuture.isCancelled()) {
abandon(extendedRequest.getMessageId());
}
throw new LdapException(NO_RESPONSE_ERROR, ie);
}
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class LdapNetworkConnection method delete.
/**
* {@inheritDoc}
*/
@Override
public DeleteResponse delete(DeleteRequest deleteRequest) throws LdapException {
if (deleteRequest == null) {
String msg = "Cannot process a null deleteRequest";
LOG.debug(msg);
throw new IllegalArgumentException(msg);
}
DeleteFuture deleteFuture = deleteAsync(deleteRequest);
// Get the result from the future
try {
// Read the response, waiting for it if not available immediately
// Get the response, blocking
DeleteResponse delResponse = deleteFuture.get(timeout, TimeUnit.MILLISECONDS);
if (delResponse == null) {
// We didn't received anything : this is an error
if (LOG.isErrorEnabled()) {
LOG.error(I18n.err(I18n.ERR_03203_OP_FAILED_TIMEOUT, "Delete"));
}
throw new LdapException(TIME_OUT_ERROR);
}
if (delResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
// Everything is fine, return the response
if (LOG.isDebugEnabled()) {
LOG.debug(I18n.msg(I18n.MSG_03217_DELETE_SUCCESSFUL, delResponse));
}
} else {
// We have had an error
if (LOG.isDebugEnabled()) {
LOG.debug(I18n.msg(I18n.MSG_03216_DELETE_FAILED, delResponse));
}
}
return delResponse;
} catch (Exception ie) {
// Catch all other exceptions
LOG.error(NO_RESPONSE_ERROR, ie);
// Send an abandon request
if (!deleteFuture.isCancelled()) {
abandon(deleteRequest.getMessageId());
}
throw new LdapException(NO_RESPONSE_ERROR, ie);
}
}
use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.
the class LdapNetworkConnection method modifyDn.
/**
* {@inheritDoc}
*/
@Override
public ModifyDnResponse modifyDn(ModifyDnRequest modDnRequest) throws LdapException {
if (modDnRequest == null) {
String msg = "Cannot process a null modDnRequest";
LOG.debug(msg);
throw new IllegalArgumentException(msg);
}
ModifyDnFuture modifyDnFuture = modifyDnAsync(modDnRequest);
// Get the result from the future
try {
// Read the response, waiting for it if not available immediately
// Get the response, blocking
ModifyDnResponse modifyDnResponse = modifyDnFuture.get(timeout, TimeUnit.MILLISECONDS);
if (modifyDnResponse == null) {
// We didn't received anything : this is an error
if (LOG.isErrorEnabled()) {
LOG.error(I18n.err(I18n.ERR_03203_OP_FAILED_TIMEOUT, "ModifyDn"));
}
throw new LdapException(TIME_OUT_ERROR);
}
if (modifyDnResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
// Everything is fine, return the response
if (LOG.isDebugEnabled()) {
LOG.debug(I18n.msg(I18n.MSG_03226_MODIFYDN_SUCCESSFUL, modifyDnResponse));
}
} else {
// We have had an error
if (LOG.isDebugEnabled()) {
LOG.debug(I18n.msg(I18n.MSG_03225_MODIFYDN_FAILED, modifyDnResponse));
}
}
return modifyDnResponse;
} catch (Exception ie) {
// Catch all other exceptions
LOG.error(NO_RESPONSE_ERROR, ie);
// Send an abandon request
if (!modifyDnFuture.isCancelled()) {
abandon(modDnRequest.getMessageId());
}
throw new LdapException(NO_RESPONSE_ERROR, ie);
}
}
Aggregations