Search in sources :

Example 6 with ResultResponse

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

the class AddReferral method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    Message response = container.getMessage();
    LdapResult ldapResult = ((ResultResponse) response).getLdapResult();
    Referral referral = ldapResult.getReferral();
    if (tlv.getLength() == 0) {
        referral.addLdapUrl("");
    } else {
        if (ldapResult.getResultCode() == ResultCodeEnum.REFERRAL) {
            try {
                String url = Strings.utf8ToString(tlv.getValue().getData());
                referral.addLdapUrl(new LdapUrl(url).toString());
            } catch (LdapURLEncodingException luee) {
                String badUrl = Strings.utf8ToString(tlv.getValue().getData());
                LOG.error(I18n.err(I18n.ERR_04015, badUrl, luee.getMessage()));
                throw new DecoderException(I18n.err(I18n.ERR_04016, luee.getMessage()), luee);
            }
        } else {
            LOG.warn("The Referral error message is not allowed when havind an error code no equals to REFERRAL");
            referral.addLdapUrl(LdapUrl.EMPTY_URL.toString());
        }
    }
    if (IS_DEBUG) {
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        for (String url : ldapResult.getReferral().getLdapUrls()) {
            if (isFirst) {
                isFirst = false;
            } else {
                sb.append(", ");
            }
            sb.append(url);
        }
        LOG.debug("The referral error message is set to " + sb.toString());
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
}
Also used : ResultResponse(org.apache.directory.api.ldap.model.message.ResultResponse) LdapUrl(org.apache.directory.api.ldap.model.url.LdapUrl) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) Message(org.apache.directory.api.ldap.model.message.Message) Referral(org.apache.directory.api.ldap.model.message.Referral) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Aggregations

ResultResponse (org.apache.directory.api.ldap.model.message.ResultResponse)6 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)5 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)5 DecoderException (org.apache.directory.api.asn1.DecoderException)4 ResultCodeEnum (org.apache.directory.api.ldap.model.message.ResultCodeEnum)3 Referral (org.apache.directory.api.ldap.model.message.Referral)2 BerValue (org.apache.directory.api.asn1.ber.tlv.BerValue)1 IntegerDecoderException (org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException)1 PasswordPolicy (org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)1 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)1 Message (org.apache.directory.api.ldap.model.message.Message)1 ReferralImpl (org.apache.directory.api.ldap.model.message.ReferralImpl)1 Dn (org.apache.directory.api.ldap.model.name.Dn)1 LdapUrl (org.apache.directory.api.ldap.model.url.LdapUrl)1 PasswordException (org.apache.directory.ldap.client.template.exception.PasswordException)1