use of org.apache.directory.api.ldap.model.message.DeleteResponse in project directory-ldap-api by apache.
the class LdapNetworkConnection method deleteTree.
/**
* deletes the entry with the given Dn, and all its children
*
* @param dn the target entry's Dn as a String
* @throws LdapException If the Dn is not valid or if the deletion failed
*/
public void deleteTree(String dn) throws LdapException {
try {
String treeDeleteOid = "1.2.840.113556.1.4.805";
Dn newDn = new Dn(dn);
if (isControlSupported(treeDeleteOid)) {
DeleteRequest deleteRequest = new DeleteRequestImpl();
deleteRequest.setName(newDn);
deleteRequest.addControl(new OpaqueControl(treeDeleteOid));
DeleteResponse deleteResponse = delete(deleteRequest);
processResponse(deleteResponse);
} else {
String msg = "The subtreeDelete control (1.2.840.113556.1.4.805) is not supported by the server\n" + " The deletion has been aborted";
LOG.error(msg);
throw new LdapException(msg);
}
} catch (LdapInvalidDnException e) {
LOG.error(e.getMessage(), e);
throw new LdapException(e.getMessage(), e);
}
}
use of org.apache.directory.api.ldap.model.message.DeleteResponse in project directory-ldap-api by apache.
the class LdapNetworkConnection method deleteTree.
/**
* deletes the entry with the given Dn, and all its children
*
* @param dn the target entry's Dn
* @throws LdapException If the Dn is not valid or if the deletion failed
*/
public void deleteTree(Dn dn) throws LdapException {
String treeDeleteOid = "1.2.840.113556.1.4.805";
if (isControlSupported(treeDeleteOid)) {
DeleteRequest deleteRequest = new DeleteRequestImpl();
deleteRequest.setName(dn);
deleteRequest.addControl(new OpaqueControl(treeDeleteOid));
DeleteResponse deleteResponse = delete(deleteRequest);
processResponse(deleteResponse);
} else {
String msg = "The subtreeDelete control (1.2.840.113556.1.4.805) is not supported by the server\n" + " The deletion has been aborted";
LOG.error(msg);
throw new LdapException(msg);
}
}
use of org.apache.directory.api.ldap.model.message.DeleteResponse in project directory-ldap-api by apache.
the class LdapNetworkConnection method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(Dn dn) throws LdapException {
DeleteRequest deleteRequest = new DeleteRequestImpl();
deleteRequest.setName(dn);
DeleteResponse deleteResponse = delete(deleteRequest);
processResponse(deleteResponse);
}
use of org.apache.directory.api.ldap.model.message.DeleteResponse in project directory-ldap-api by apache.
the class BatchResponseTest method testResponseWith2DelResponse.
/**
* Test parsing of a Response with the 2 DelResponse
*/
@Test
public void testResponseWith2DelResponse() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(BatchResponseTest.class.getResource("response_with_2_DelResponse.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
BatchResponseDsml batchResponse = parser.getBatchResponse();
assertEquals(2, batchResponse.getResponses().size());
DsmlDecorator<? extends Response> response = batchResponse.getCurrentResponse();
if (response instanceof DeleteResponse) {
assertTrue(true);
} else {
fail();
}
}
use of org.apache.directory.api.ldap.model.message.DeleteResponse in project directory-ldap-api by apache.
the class DelResponseTest method testResponseWith2Referrals.
/**
* Test parsing of a response with 2 Referral elements
*/
@Test
public void testResponseWith2Referrals() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(DelResponseTest.class.getResource("response_with_2_referrals.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
DeleteResponse delResponse = (DeleteResponse) parser.getBatchResponse().getCurrentResponse();
LdapResult ldapResult = delResponse.getLdapResult();
Collection<String> referrals = ldapResult.getReferral().getLdapUrls();
assertEquals(2, referrals.size());
try {
assertTrue(referrals.contains(new LdapUrl("ldap://www.apache.org/").toString()));
} catch (LdapURLEncodingException e) {
fail();
}
try {
assertTrue(referrals.contains(new LdapUrl("ldap://www.apple.com/").toString()));
} catch (LdapURLEncodingException e) {
fail();
}
}
Aggregations