use of org.apache.directory.api.ldap.model.message.LdapResult in project directory-ldap-api by apache.
the class SearchResultDoneTest method testResponseWith1EmptyReferral.
/**
* Test parsing of a response with an empty Referral
*/
@Test
public void testResponseWith1EmptyReferral() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(SearchResultDoneTest.class.getResource("response_with_1_empty_referral.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchResultDone searchResultDone = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getSearchResultDone();
LdapResult ldapResult = searchResultDone.getLdapResult();
Collection<String> referrals = ldapResult.getReferral().getLdapUrls();
assertEquals(0, referrals.size());
}
use of org.apache.directory.api.ldap.model.message.LdapResult in project directory-ldap-api by apache.
the class LdapResultImplTest method testEqualsDiffImpl.
/**
* Tests for equality when the lockable parent is the same.
*/
@Test
public void testEqualsDiffImpl() {
LdapResultImpl r0 = new LdapResultImpl();
LdapResult r1 = new LdapResult() {
public ResultCodeEnum getResultCode() {
return ResultCodeEnum.SUCCESS;
}
public void setResultCode(ResultCodeEnum a_resultCode) {
}
public Dn getMatchedDn() {
return null;
}
public void setMatchedDn(Dn dn) {
}
public String getDiagnosticMessage() {
return null;
}
public void setDiagnosticMessage(String diagnosticMessage) {
}
public boolean isReferral() {
return false;
}
public Referral getReferral() {
return null;
}
public void setReferral(Referral referral) {
}
public boolean isDefaultSuccess() {
return false;
}
};
assertTrue("r0 equals should see other impl r1 as equal", r0.equals(r1));
assertFalse("r1 impl uses Object.equals() so it should not see " + "r0 as the same object", r1.equals(r0));
}
use of org.apache.directory.api.ldap.model.message.LdapResult in project directory-ldap-api by apache.
the class InitReferrals method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
TLV tlv = container.getCurrentTLV();
// If we hae a Referrals sequence, then it should not be empty
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04011);
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg);
}
ResultResponse response = (ResultResponse) container.getMessage();
LdapResult ldapResult = response.getLdapResult();
Referral referral = new ReferralImpl();
ldapResult.setReferral(referral);
if (IS_DEBUG) {
LOG.debug("Initialising a referrals list");
}
}
use of org.apache.directory.api.ldap.model.message.LdapResult in project directory-ldap-api by apache.
the class StoreErrorMessage method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
// Get the Value and store it in the BindResponse
TLV tlv = container.getCurrentTLV();
String errorMessage;
// message
if (tlv.getLength() == 0) {
errorMessage = "";
} else {
errorMessage = Strings.utf8ToString(tlv.getValue().getData());
}
ResultResponse response = (ResultResponse) container.getMessage();
LdapResult ldapResult = response.getLdapResult();
ldapResult.setDiagnosticMessage(errorMessage);
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("The error message is : " + errorMessage);
}
}
use of org.apache.directory.api.ldap.model.message.LdapResult in project directory-ldap-api by apache.
the class StoreMatchedDN method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
// Get the Value and store it in the BindResponse
TLV tlv = container.getCurrentTLV();
Dn matchedDn;
ResultCodeEnum resultCode;
ResultResponse response = (ResultResponse) container.getMessage();
LdapResult ldapResult = response.getLdapResult();
resultCode = ldapResult.getResultCode();
// Dn
if (tlv.getLength() == 0) {
matchedDn = Dn.EMPTY_DN;
} else {
switch(resultCode) {
case NO_SUCH_OBJECT:
case ALIAS_PROBLEM:
case INVALID_DN_SYNTAX:
case ALIAS_DEREFERENCING_PROBLEM:
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
matchedDn = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
// This is for the client side. We will never decode LdapResult on the server
String msg = I18n.err(I18n.ERR_04013, dnStr, Strings.dumpBytes(dnBytes), ine.getLocalizedMessage());
LOG.error(msg);
throw new DecoderException(I18n.err(I18n.ERR_04014, ine.getLocalizedMessage()), ine);
}
break;
default:
LOG.warn("The matched Dn should not be set when the result code is not one of NoSuchObject," + " AliasProblem, InvalidDNSyntax or AliasDreferencingProblem");
matchedDn = Dn.EMPTY_DN;
break;
}
}
if (IS_DEBUG) {
LOG.debug("The matchedDn is " + matchedDn);
}
ldapResult.setMatchedDn(matchedDn);
}
Aggregations