Search in sources :

Example 1 with IntegerDecoderException

use of org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException in project directory-ldap-api by apache.

the class StoredProcedureRequestImpl method getParameterValueString.

/**
 * Get a parameter value
 *
 * @param index The position of the parameter in the list of parameters
 * @return The paremeter's value
 */
public Object getParameterValueString(int index) {
    if (!"java".equals(language)) {
        Object obj = parameters.get(index).getValue();
        if (obj instanceof byte[]) {
            String str = Strings.utf8ToString((byte[]) obj);
            String type = (String) getParameterTypeString(index);
            if ("int".equals(type)) {
                try {
                    return IntegerDecoder.parse(new BerValue((byte[]) obj));
                } catch (IntegerDecoderException e) {
                    throw new RuntimeException("Failed to decode INTEGER: " + Strings.dumpBytes((byte[]) obj), e);
                }
            } else {
                return str;
            }
        }
    }
    return getJavaParameterValue(index);
}
Also used : BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException)

Example 2 with IntegerDecoderException

use of org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException in project directory-ldap-api by apache.

the class InitAbandonRequest method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<AbandonRequestDecorator> container) throws DecoderException {
    // Create the AbandonRequest LdapMessage instance and store it in the container
    AbandonRequest internalAbandonRequest = new AbandonRequestImpl();
    internalAbandonRequest.setMessageId(container.getMessageId());
    AbandonRequestDecorator abandonRequest = new AbandonRequestDecorator(container.getLdapCodecService(), internalAbandonRequest);
    container.setMessage(abandonRequest);
    // The current TLV should be a integer
    // We get it and store it in MessageId
    TLV tlv = container.getCurrentTLV();
    BerValue value = tlv.getValue();
    if ((value == null) || (value.getData() == null)) {
        String msg = I18n.err(I18n.ERR_04075);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
    try {
        int abandonnedMessageId = IntegerDecoder.parse(value, 0, Integer.MAX_VALUE);
        abandonRequest.setAbandoned(abandonnedMessageId);
        if (IS_DEBUG) {
            LOG.debug("AbandonMessage Id has been decoded : {}", Integer.valueOf(abandonnedMessageId));
        }
        container.setGrammarEndAllowed(true);
        return;
    } catch (IntegerDecoderException ide) {
        LOG.error(I18n.err(I18n.ERR_04076, Strings.dumpBytes(value.getData()), ide.getMessage()));
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(ide.getMessage(), ide);
    }
}
Also used : IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) AbandonRequest(org.apache.directory.api.ldap.model.message.AbandonRequest) AbandonRequestImpl(org.apache.directory.api.ldap.model.message.AbandonRequestImpl) AbandonRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 3 with IntegerDecoderException

use of org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException in project directory-ldap-api by apache.

the class StoreSearchRequestDerefAlias method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequest searchRequest = container.getMessage().getDecorated();
    TLV tlv = container.getCurrentTLV();
    // We have to check that this is a correct derefAliases
    BerValue value = tlv.getValue();
    int derefAliases = 0;
    try {
        derefAliases = IntegerDecoder.parse(value, LdapCodecConstants.NEVER_DEREF_ALIASES, LdapCodecConstants.DEREF_ALWAYS);
    } catch (IntegerDecoderException ide) {
        String msg = I18n.err(I18n.ERR_04102, value.toString());
        LOG.error(msg);
        throw new DecoderException(msg, ide);
    }
    searchRequest.setDerefAliases(AliasDerefMode.getDerefMode(derefAliases));
    if (IS_DEBUG) {
        switch(derefAliases) {
            case LdapCodecConstants.NEVER_DEREF_ALIASES:
                LOG.debug("Handling object strategy : NEVER_DEREF_ALIASES");
                break;
            case LdapCodecConstants.DEREF_IN_SEARCHING:
                LOG.debug("Handling object strategy : DEREF_IN_SEARCHING");
                break;
            case LdapCodecConstants.DEREF_FINDING_BASE_OBJ:
                LOG.debug("Handling object strategy : DEREF_FINDING_BASE_OBJ");
                break;
            case LdapCodecConstants.DEREF_ALWAYS:
                LOG.debug("Handling object strategy : DEREF_ALWAYS");
                break;
            default:
                LOG.debug("Handling object strategy : UNKNOWN");
        }
    }
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 4 with IntegerDecoderException

use of org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException in project directory-ldap-api by apache.

the class StoreVersion method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<BindRequestDecorator> container) throws DecoderException {
    BindRequest bindRequestMessage = container.getMessage();
    // The current TLV should be a integer between 1 and 127
    // We get it and store it in Version
    TLV tlv = container.getCurrentTLV();
    BerValue value = tlv.getValue();
    try {
        int version = IntegerDecoder.parse(value, 1, 127);
        if (IS_DEBUG) {
            LOG.debug("Ldap version ", Integer.valueOf(version));
        }
        bindRequestMessage.setVersion3(version == 3);
    } catch (IntegerDecoderException ide) {
        LOG.error(I18n.err(I18n.ERR_04078, Strings.dumpBytes(value.getData()), ide.getMessage()));
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(ide.getMessage(), ide);
    }
}
Also used : IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 5 with IntegerDecoderException

use of org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException in project directory-ldap-api by apache.

the class StoreSearchRequestTimeLimit method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequest searchRequest = container.getMessage().getDecorated();
    TLV tlv = container.getCurrentTLV();
    // The current TLV should be a integer
    // We get it and store it in timeLimit
    BerValue value = tlv.getValue();
    int timeLimit = 0;
    try {
        timeLimit = IntegerDecoder.parse(value, 0, Integer.MAX_VALUE);
    } catch (IntegerDecoderException ide) {
        String msg = I18n.err(I18n.ERR_04104, value.toString());
        LOG.error(msg);
        throw new DecoderException(msg, ide);
    }
    searchRequest.setTimeLimit(timeLimit);
    if (IS_DEBUG) {
        LOG.debug("The timeLimit value is set to {} seconds", Integer.valueOf(timeLimit));
    }
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Aggregations

IntegerDecoderException (org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException)12 DecoderException (org.apache.directory.api.asn1.DecoderException)11 BerValue (org.apache.directory.api.asn1.ber.tlv.BerValue)11 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)9 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)3 ByteBuffer (java.nio.ByteBuffer)2 EncoderException (org.apache.directory.api.asn1.EncoderException)2 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)2 StoredProcedureContainer (org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureContainer)2 StoredProcedureDecoder (org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureDecoder)2 StoredProcedureRequestDecorator (org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureRequestDecorator)2 Test (org.junit.Test)2 AbandonRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator)1 ModifyRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator)1 AbandonRequest (org.apache.directory.api.ldap.model.message.AbandonRequest)1 AbandonRequestImpl (org.apache.directory.api.ldap.model.message.AbandonRequestImpl)1 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)1 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)1 ResultCodeEnum (org.apache.directory.api.ldap.model.message.ResultCodeEnum)1 ResultResponse (org.apache.directory.api.ldap.model.message.ResultResponse)1