Search in sources :

Example 16 with DeleteResponse

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);
    }
}
Also used : DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) DeleteRequestImpl(org.apache.directory.api.ldap.model.message.DeleteRequestImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 17 with DeleteResponse

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);
    }
}
Also used : DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) DeleteRequestImpl(org.apache.directory.api.ldap.model.message.DeleteRequestImpl) OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 18 with DeleteResponse

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);
}
Also used : DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) DeleteRequestImpl(org.apache.directory.api.ldap.model.message.DeleteRequestImpl) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest)

Example 19 with 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();
    }
}
Also used : BatchResponseDsml(org.apache.directory.api.dsmlv2.response.BatchResponseDsml) Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 20 with DeleteResponse

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();
    }
}
Also used : LdapUrl(org.apache.directory.api.ldap.model.url.LdapUrl) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Aggregations

DeleteResponse (org.apache.directory.api.ldap.model.message.DeleteResponse)25 Test (org.junit.Test)17 AbstractResponseTest (org.apache.directory.api.dsmlv2.AbstractResponseTest)15 Dsmlv2ResponseParser (org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser)15 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)13 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)8 Control (org.apache.directory.api.ldap.model.message.Control)6 DeleteRequest (org.apache.directory.api.ldap.model.message.DeleteRequest)5 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)4 DeleteRequestImpl (org.apache.directory.api.ldap.model.message.DeleteRequestImpl)4 DecoderException (org.apache.directory.api.asn1.DecoderException)3 DeleteResponseDecorator (org.apache.directory.api.ldap.codec.decorators.DeleteResponseDecorator)3 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)3 AddResponse (org.apache.directory.api.ldap.model.message.AddResponse)3 BindResponse (org.apache.directory.api.ldap.model.message.BindResponse)3 ByteBuffer (java.nio.ByteBuffer)2 EncoderException (org.apache.directory.api.asn1.EncoderException)2 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)2 BatchResponseDsml (org.apache.directory.api.dsmlv2.response.BatchResponseDsml)2 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)2