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;
}
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
* |
* +--> 0x04 L2 reference
* +--> 0x04 L3 reference
* +--> ...
* +--> 0x04 Li reference
* +--> ...
* +--> 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;
}
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;
}
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));
}
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));
}
Aggregations