Search in sources :

Example 6 with IntegerDecoderException

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

the class StoredProcedureTest method testDecodeStoredProcedureOneParam.

@Test
public void testDecodeStoredProcedureOneParam() throws IntegerDecoderException {
    Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
    ByteBuffer stream = ByteBuffer.allocate(0x1D);
    stream.put(new byte[] { 0x30, 0x1B, 0x04, 0x04, 'J', 'a', 'v', 'a', 0x04, 0x07, 'e', 'x', 'e', 'c', 'u', 't', 'e', 0x30, 0x0A, 0x30, 0x08, 0x04, 0x03, 'i', 'n', 't', 0x04, 0x01, 0x01 });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a StoredProcedure Container
    StoredProcedureContainer storedProcedureContainer = new StoredProcedureContainer();
    // Decode a StoredProcedure message
    try {
        storedProcedureDecoder.decode(stream, storedProcedureContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    StoredProcedureRequestDecorator storedProcedure = storedProcedureContainer.getStoredProcedure();
    assertEquals("Java", storedProcedure.getLanguage());
    assertEquals("execute", storedProcedure.getProcedureSpecification());
    assertEquals(1, storedProcedure.size());
    assertEquals("int", Strings.utf8ToString((byte[]) storedProcedure.getParameterType(0)));
    assertEquals(1, IntegerDecoder.parse(new BerValue((byte[]) storedProcedure.getParameterValue(0))));
    // Check the encoding
    try {
        ByteBuffer bb = storedProcedure.encodeInternal();
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : StoredProcedureDecoder(org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureDecoder) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) StoredProcedureContainer(org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureContainer) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) StoredProcedureRequestDecorator(org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureRequestDecorator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 7 with IntegerDecoderException

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

the class AbstractReadInteger method action.

/**
 * {@inheritDoc}
 */
@Override
public final void action(E container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    // The Length should not be null
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_01101_NULL_LENGTH);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
    BerValue value = tlv.getValue();
    try {
        int number = IntegerDecoder.parse(value, minValue, maxValue);
        if (IS_DEBUG) {
            LOG.debug(I18n.msg(I18n.MSG_01100_INTEGER_VALUE, number));
        }
        setIntegerValue(number, container);
    } catch (IntegerDecoderException ide) {
        LOG.error(I18n.err(I18n.ERR_01102_INVALID_INTEGER, Strings.dumpBytes(value.getData()), ide.getLocalizedMessage()));
        // 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) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 8 with IntegerDecoderException

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

the class StoreOperationType method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
    ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // Decode the operation type
    int operation = 0;
    try {
        operation = IntegerDecoder.parse(tlv.getValue(), 0, 2);
    } catch (IntegerDecoderException ide) {
        String msg = I18n.err(I18n.ERR_04082, Strings.dumpBytes(tlv.getValue().getData()));
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg, ide);
    }
    // Store the current operation.
    modifyRequestDecorator.setCurrentOperation(operation);
    if (IS_DEBUG) {
        switch(operation) {
            case LdapCodecConstants.OPERATION_ADD:
                LOG.debug("Modification operation : ADD");
                break;
            case LdapCodecConstants.OPERATION_DELETE:
                LOG.debug("Modification operation : DELETE");
                break;
            case LdapCodecConstants.OPERATION_REPLACE:
                LOG.debug("Modification operation : REPLACE");
                break;
            default:
                LOG.debug("Modification operation : UNKNOWN");
        }
    }
}
Also used : ModifyRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 9 with IntegerDecoderException

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

the class StoreSearchRequestScope 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 scope
    BerValue value = tlv.getValue();
    int scope = 0;
    try {
        scope = IntegerDecoder.parse(value, LdapCodecConstants.SCOPE_BASE_OBJECT, LdapCodecConstants.SCOPE_WHOLE_SUBTREE);
    } catch (IntegerDecoderException ide) {
        String msg = I18n.err(I18n.ERR_04101, value.toString());
        LOG.error(msg);
        throw new DecoderException(msg, ide);
    }
    searchRequest.setScope(SearchScope.getSearchScope(scope));
    if (IS_DEBUG) {
        switch(scope) {
            case LdapCodecConstants.SCOPE_BASE_OBJECT:
                LOG.debug("Searching within BASE_OBJECT scope ");
                break;
            case LdapCodecConstants.SCOPE_SINGLE_LEVEL:
                LOG.debug("Searching within SINGLE_LEVEL scope ");
                break;
            case LdapCodecConstants.SCOPE_WHOLE_SUBTREE:
                LOG.debug("Searching within WHOLE_SUBTREE scope ");
                break;
            default:
                LOG.debug("Searching within UNKNOWN scope ");
        }
    }
}
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 10 with IntegerDecoderException

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

the class StoreResultCode method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    // The current TLV should be a integer
    // We get it and store it in MessageId
    TLV tlv = container.getCurrentTLV();
    BerValue value = tlv.getValue();
    ResultCodeEnum resultCode = ResultCodeEnum.SUCCESS;
    try {
        resultCode = ResultCodeEnum.getResultCode(IntegerDecoder.parse(value, 0, ResultCodeEnum.E_SYNC_REFRESH_REQUIRED.getResultCode()));
    } catch (IntegerDecoderException ide) {
        LOG.error(I18n.err(I18n.ERR_04018, Strings.dumpBytes(value.getData()), ide.getMessage()));
        throw new DecoderException(ide.getMessage(), ide);
    }
    if (IS_DEBUG) {
        LOG.debug("The result code is set to " + resultCode);
    }
    ResultResponse response = (ResultResponse) container.getMessage();
    LdapResult ldapResult = response.getLdapResult();
    ldapResult.setResultCode(resultCode);
}
Also used : ResultResponse(org.apache.directory.api.ldap.model.message.ResultResponse) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) 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) ResultCodeEnum(org.apache.directory.api.ldap.model.message.ResultCodeEnum)

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