Search in sources :

Example 6 with Referral

use of org.apache.directory.api.ldap.model.message.Referral in project directory-ldap-api by apache.

the class SearchResultReferenceDecorator method encode.

/**
 * Encode the SearchResultReference message to a PDU.
 * <br>
 * SearchResultReference :
 * <pre>
 * 0x73 LL
 *   0x04 LL reference
 *   [0x04 LL reference]*
 * </pre>
 *
 * @param buffer The buffer where to put the PDU
 * @return The PDU.
 */
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
    SearchResultReference searchResultReference = getDecorated();
    try {
        // The SearchResultReference Tag
        buffer.put(LdapCodecConstants.SEARCH_RESULT_REFERENCE_TAG);
        buffer.put(TLV.getBytes(searchResultReferenceLength));
        // The referrals, if any
        Referral referral = searchResultReference.getReferral();
        if (referral != null) {
            // Each referral
            for (byte[] ldapUrlBytes : referral.getLdapUrlsBytes()) {
                // Encode the current referral
                BerValue.encode(buffer, ldapUrlBytes);
            }
        }
    } catch (BufferOverflowException boe) {
        throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
    }
    return buffer;
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) Referral(org.apache.directory.api.ldap.model.message.Referral) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) BufferOverflowException(java.nio.BufferOverflowException)

Example 7 with Referral

use of org.apache.directory.api.ldap.model.message.Referral in project directory-ldap-api by apache.

the class SearchResultReferenceDecorator method computeLength.

// -------------------------------------------------------------------------
// The Decorator methods
// -------------------------------------------------------------------------
/**
 * Compute the SearchResultReference length
 * <br>
 * SearchResultReference :
 * <pre>
 * 0x73 L1
 *  |
 *  +--&gt; 0x04 L2 reference
 *  +--&gt; 0x04 L3 reference
 *  +--&gt; ...
 *  +--&gt; 0x04 Li reference
 *  +--&gt; ...
 *  +--&gt; 0x04 Ln reference
 *
 * L1 = n*Length(0x04) + sum(Length(Li)) + sum(Length(reference[i]))
 *
 * Length(SearchResultReference) = Length(0x73 + Length(L1) + L1
 * </pre>
 *
 * @return The encoded length
 */
@Override
public int computeLength() {
    searchResultReferenceLength = 0;
    // We may have more than one reference.
    Referral referral = getReferral();
    int referralLength = LdapEncoder.computeReferralLength(referral);
    if (referralLength != 0) {
        setReferral(referral);
        searchResultReferenceLength = referralLength;
    }
    return 1 + TLV.getNbBytes(searchResultReferenceLength) + searchResultReferenceLength;
}
Also used : Referral(org.apache.directory.api.ldap.model.message.Referral)

Example 8 with Referral

use of org.apache.directory.api.ldap.model.message.Referral in project directory-ldap-api by apache.

the class LdapResultDsml method toDsml.

/**
 * {@inheritDoc}
 */
@Override
public Element toDsml(Element root) {
    // RequestID
    int requestID = message.getMessageId();
    if (requestID > 0) {
        root.addAttribute("requestID", Integer.toString(requestID));
    }
    // Matched Dn
    Dn matchedDn = result.getMatchedDn();
    if (!Dn.isNullOrEmpty(matchedDn)) {
        root.addAttribute("matchedDn", matchedDn.getName());
    }
    // Controls
    ParserUtils.addControls(codec, root, message.getControls().values());
    // ResultCode
    Element resultCodeElement = root.addElement("resultCode");
    resultCodeElement.addAttribute("code", Integer.toString(result.getResultCode().getResultCode()));
    resultCodeElement.addAttribute("descr", result.getResultCode().getMessage());
    // ErrorMessage
    String errorMessage = result.getDiagnosticMessage();
    if ((errorMessage != null) && (errorMessage.length() != 0)) {
        Element errorMessageElement = root.addElement("errorMessage");
        errorMessageElement.addText(errorMessage);
    }
    // Referrals
    Referral referral = result.getReferral();
    if (referral != null) {
        Collection<String> ldapUrls = referral.getLdapUrls();
        if (ldapUrls != null) {
            for (String ldapUrl : ldapUrls) {
                Element referalElement = root.addElement("referal");
                referalElement.addText(ldapUrl);
            }
        }
    }
    return root;
}
Also used : Referral(org.apache.directory.api.ldap.model.message.Referral) Element(org.dom4j.Element) Dn(org.apache.directory.api.ldap.model.name.Dn)

Example 9 with Referral

use of org.apache.directory.api.ldap.model.message.Referral in project directory-ldap-api by apache.

the class BindResponseImplTest method testEqualsWithTheWorks.

/**
 * Tests for equality of two fully loaded identical BindResponse PDUs.
 */
@Test
public void testEqualsWithTheWorks() throws LdapException {
    LdapResultImpl r0 = new LdapResultImpl();
    LdapResultImpl r1 = new LdapResultImpl();
    r0.setDiagnosticMessage("blah blah blah");
    r1.setDiagnosticMessage("blah blah blah");
    r0.setMatchedDn(new Dn("dc=example,dc=com"));
    r1.setMatchedDn(new Dn("dc=example,dc=com"));
    r0.setResultCode(ResultCodeEnum.TIME_LIMIT_EXCEEDED);
    r1.setResultCode(ResultCodeEnum.TIME_LIMIT_EXCEEDED);
    Referral refs0 = new ReferralImpl();
    refs0.addLdapUrl("ldap://someserver.com");
    refs0.addLdapUrl("ldap://anotherserver.org");
    Referral refs1 = new ReferralImpl();
    refs1.addLdapUrl("ldap://someserver.com");
    refs1.addLdapUrl("ldap://anotherserver.org");
    BindResponseImpl resp0 = new BindResponseImpl(1);
    BindResponseImpl resp1 = new BindResponseImpl(1);
    resp0.setServerSaslCreds(PASSWORD);
    resp1.setServerSaslCreds(PASSWORD);
    assertTrue("loaded carbon copies should be equal", resp0.equals(resp1));
    assertTrue("loaded carbon copies should be equal", resp1.equals(resp0));
}
Also used : Referral(org.apache.directory.api.ldap.model.message.Referral) ReferralImpl(org.apache.directory.api.ldap.model.message.ReferralImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) BindResponseImpl(org.apache.directory.api.ldap.model.message.BindResponseImpl) LdapResultImpl(org.apache.directory.api.ldap.model.message.LdapResultImpl) Test(org.junit.Test)

Example 10 with Referral

use of org.apache.directory.api.ldap.model.message.Referral in project directory-ldap-api by apache.

the class LdapResultImplTest method testNotEqualsDiffReferrals.

/**
 * Tests for inequality when the referrals are not the same.
 */
@Test
public void testNotEqualsDiffReferrals() throws LdapException {
    LdapResultImpl r0 = new LdapResultImpl();
    LdapResultImpl r1 = new LdapResultImpl();
    r0.setDiagnosticMessage("blah blah blah");
    r1.setDiagnosticMessage("blah blah blah");
    r0.setMatchedDn(new Dn("dc=example,dc=com"));
    r1.setMatchedDn(new Dn("dc=example,dc=com"));
    r0.setResultCode(ResultCodeEnum.TIME_LIMIT_EXCEEDED);
    r1.setResultCode(ResultCodeEnum.TIME_LIMIT_EXCEEDED);
    Referral refs0 = new ReferralImpl();
    r0.setReferral(refs0);
    refs0.addLdapUrl("ldap://someserver.com");
    refs0.addLdapUrl("ldap://anotherserver.org");
    Referral refs1 = new ReferralImpl();
    r1.setReferral(refs1);
    refs1.addLdapUrl("ldap://abc.com");
    refs1.addLdapUrl("ldap://anotherserver.org");
    assertFalse("results with different referrals should not be equal", r0.equals(r1));
    assertFalse("results with different referrals should not be equal", r1.equals(r0));
}
Also used : Referral(org.apache.directory.api.ldap.model.message.Referral) ReferralImpl(org.apache.directory.api.ldap.model.message.ReferralImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapResultImpl(org.apache.directory.api.ldap.model.message.LdapResultImpl) Test(org.junit.Test)

Aggregations

Referral (org.apache.directory.api.ldap.model.message.Referral)23 Test (org.junit.Test)16 ReferralImpl (org.apache.directory.api.ldap.model.message.ReferralImpl)11 Dn (org.apache.directory.api.ldap.model.name.Dn)10 DecoderException (org.apache.directory.api.asn1.DecoderException)9 LdapResultImpl (org.apache.directory.api.ldap.model.message.LdapResultImpl)9 EncoderException (org.apache.directory.api.asn1.EncoderException)8 ByteBuffer (java.nio.ByteBuffer)6 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)6 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)6 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)6 SearchResultReference (org.apache.directory.api.ldap.model.message.SearchResultReference)5 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)3 AddResponseDecorator (org.apache.directory.api.ldap.codec.decorators.AddResponseDecorator)3 SearchResultReferenceDecorator (org.apache.directory.api.ldap.codec.decorators.SearchResultReferenceDecorator)3 AddResponse (org.apache.directory.api.ldap.model.message.AddResponse)3 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)3 BufferOverflowException (java.nio.BufferOverflowException)2 HashSet (java.util.HashSet)2 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)2