Search in sources :

Example 71 with EncoderException

use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.

the class ModifyDnResponseDecorator method encode.

/**
 * Encode the ModifyDnResponse message to a PDU.
 *
 * @param buffer The buffer where to put the PDU
 */
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
    try {
        // The ModifyResponse Tag
        buffer.put(LdapCodecConstants.MODIFY_DN_RESPONSE_TAG);
        buffer.put(TLV.getBytes(modifyDnResponseLength));
        // The LdapResult
        ((LdapResultDecorator) getLdapResult()).encode(buffer);
    } catch (BufferOverflowException boe) {
        throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
    }
    return buffer;
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) BufferOverflowException(java.nio.BufferOverflowException)

Example 72 with EncoderException

use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.

the class ModifyRequestDecorator method encode.

/**
 * Encode the ModifyRequest message to a PDU.
 * <br>
 * ModifyRequest :
 * <pre>
 * 0x66 LL
 *   0x04 LL object
 *   0x30 LL modifiations
 *     0x30 LL modification sequence
 *       0x0A 0x01 operation
 *       0x30 LL modification
 *         0x04 LL type
 *         0x31 LL vals
 *           0x04 LL attributeValue
 *           ...
 *           0x04 LL attributeValue
 *     ...
 *     0x30 LL modification sequence
 *       0x0A 0x01 operation
 *       0x30 LL modification
 *         0x04 LL type
 *         0x31 LL vals
 *           0x04 LL attributeValue
 *           ...
 *           0x04 LL attributeValue
 * </pre>
 *
 * @param buffer The buffer where to put the PDU
 * @return The PDU.
 */
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
    try {
        // The AddRequest Tag
        buffer.put(LdapCodecConstants.MODIFY_REQUEST_TAG);
        buffer.put(TLV.getBytes(modifyRequestLength));
        // The entry
        BerValue.encode(buffer, dnBytes);
        // The modifications sequence
        buffer.put(UniversalTag.SEQUENCE.getValue());
        buffer.put(TLV.getBytes(changesLength));
        // The modifications list
        Collection<Modification> modifications = getModifications();
        if ((modifications != null) && (!modifications.isEmpty())) {
            int modificationNumber = 0;
            // Compute the modifications length
            for (Modification modification : modifications) {
                // The modification sequence
                buffer.put(UniversalTag.SEQUENCE.getValue());
                int localModificationSequenceLength = changeLength.get(modificationNumber);
                buffer.put(TLV.getBytes(localModificationSequenceLength));
                // The operation. The value has to be changed, it's not
                // the same value in DirContext and in RFC 2251.
                buffer.put(UniversalTag.ENUMERATED.getValue());
                buffer.put((byte) 1);
                buffer.put((byte) modification.getOperation().getValue());
                // The modification
                buffer.put(UniversalTag.SEQUENCE.getValue());
                int localModificationLength = modificationLength.get(modificationNumber);
                buffer.put(TLV.getBytes(localModificationLength));
                // The modification type
                BerValue.encode(buffer, modification.getAttribute().getUpId());
                // The values
                buffer.put(UniversalTag.SET.getValue());
                int localValuesLength = valuesLength.get(modificationNumber);
                buffer.put(TLV.getBytes(localValuesLength));
                if (modification.getAttribute().size() != 0) {
                    for (org.apache.directory.api.ldap.model.entry.Value value : modification.getAttribute()) {
                        if (value.isHumanReadable()) {
                            BerValue.encode(buffer, value.getValue());
                        } else {
                            BerValue.encode(buffer, value.getBytes());
                        }
                    }
                }
                // Go to the next modification number
                modificationNumber++;
            }
        }
    } catch (BufferOverflowException boe) {
        throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
    }
    return buffer;
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) EncoderException(org.apache.directory.api.asn1.EncoderException) Value(org.apache.directory.api.ldap.model.entry.Value) BufferOverflowException(java.nio.BufferOverflowException)

Example 73 with EncoderException

use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.

the class ModifyResponseDecorator method encode.

/**
 * Encode the ModifyResponse message to a PDU.
 *
 * @param buffer The buffer where to put the PDU
 */
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
    try {
        // The ModifyResponse Tag
        buffer.put(LdapCodecConstants.MODIFY_RESPONSE_TAG);
        buffer.put(TLV.getBytes(modifyResponseLength));
        // The LdapResult
        ((LdapResultDecorator) getLdapResult()).encode(buffer);
    } catch (BufferOverflowException boe) {
        throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
    }
    return buffer;
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) BufferOverflowException(java.nio.BufferOverflowException)

Example 74 with EncoderException

use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.

the class SearchRequestDecorator method encode.

/**
 * Encode the SearchRequest message to a PDU.
 * <br>
 * SearchRequest :
 * <pre>
 * 0x63 LL
 *   0x04 LL baseObject
 *   0x0A 01 scope
 *   0x0A 01 derefAliases
 *   0x02 0N sizeLimit
 *   0x02 0N timeLimit
 *   0x01 0x01 typesOnly
 *   filter.encode()
 *   0x30 LL attributeDescriptionList
 *     0x04 LL attributeDescription
 *     ...
 *     0x04 LL attributeDescription
 * </pre>
 *
 * @param buffer The buffer where to put the PDU
 * @return The PDU.
 */
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
    try {
        // The SearchRequest Tag
        buffer.put(LdapCodecConstants.SEARCH_REQUEST_TAG);
        buffer.put(TLV.getBytes(searchRequestLength));
        // The baseObject
        BerValue.encode(buffer, dnBytes);
        // The scope
        BerValue.encodeEnumerated(buffer, getScope().getScope());
        // The derefAliases
        BerValue.encodeEnumerated(buffer, getDerefAliases().getValue());
        // The sizeLimit
        BerValue.encode(buffer, getSizeLimit());
        // The timeLimit
        BerValue.encode(buffer, getTimeLimit());
        // The typesOnly
        BerValue.encode(buffer, getTypesOnly());
        // The filter
        getCodecFilter().encode(buffer);
        // The attributeDescriptionList
        buffer.put(UniversalTag.SEQUENCE.getValue());
        buffer.put(TLV.getBytes(attributeDescriptionListLength));
        if ((getAttributes() != null) && (!getAttributes().isEmpty())) {
            // encode each attribute
            for (byte[] attributeBytes : attributeNameBytes) {
                BerValue.encode(buffer, attributeBytes);
            }
        }
    } catch (BufferOverflowException boe) {
        throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
    }
    return buffer;
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) BufferOverflowException(java.nio.BufferOverflowException)

Example 75 with EncoderException

use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.

the class SearchResultEntryDecorator method encode.

/**
 * Encode the SearchResultEntry message to a PDU.
 * <br>
 * SearchResultEntry :
 * <pre>
 * 0x64 LL
 *   0x04 LL objectName
 *   0x30 LL attributes
 *     0x30 LL partialAttributeList
 *       0x04 LL type
 *       0x31 LL vals
 *         0x04 LL attributeValue
 *         ...
 *         0x04 LL attributeValue
 *     ...
 *     0x30 LL partialAttributeList
 *       0x04 LL type
 *       0x31 LL vals
 *         0x04 LL attributeValue
 *         ...
 *         0x04 LL attributeValue
 * </pre>
 *
 * @param buffer The buffer where to put the PDU
 * @return The PDU.
 */
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
    try {
        // The SearchResultEntry Tag
        buffer.put(LdapCodecConstants.SEARCH_RESULT_ENTRY_TAG);
        buffer.put(TLV.getBytes(searchResultEntryLength));
        // The objectName
        BerValue.encode(buffer, objectNameBytes);
        // The attributes sequence
        buffer.put(UniversalTag.SEQUENCE.getValue());
        buffer.put(TLV.getBytes(attributesLength));
        // The partial attribute list
        Entry entry = getEntry();
        if ((entry != null) && (entry.size() != 0)) {
            int attributeNumber = 0;
            // Compute the attributes length
            for (Attribute attribute : entry) {
                // The partial attribute list sequence
                buffer.put(UniversalTag.SEQUENCE.getValue());
                int localAttributeLength = attributeLength.get(attributeNumber);
                buffer.put(TLV.getBytes(localAttributeLength));
                // The attribute type
                BerValue.encode(buffer, attributeIds.get(attributeNumber));
                // The values
                buffer.put(UniversalTag.SET.getValue());
                int localValuesLength = valuesLength.get(attributeNumber);
                buffer.put(TLV.getBytes(localValuesLength));
                if (attribute.size() > 0) {
                    for (Value value : attribute) {
                        BerValue.encode(buffer, value.getBytes());
                    }
                }
                // Go to the next attribute number
                attributeNumber++;
            }
        }
    } catch (BufferOverflowException boe) {
        throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
    }
    return buffer;
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Value(org.apache.directory.api.ldap.model.entry.Value) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) BufferOverflowException(java.nio.BufferOverflowException)

Aggregations

EncoderException (org.apache.directory.api.asn1.EncoderException)226 ByteBuffer (java.nio.ByteBuffer)191 Test (org.junit.Test)189 DecoderException (org.apache.directory.api.asn1.DecoderException)151 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)150 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)127 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)124 BufferOverflowException (java.nio.BufferOverflowException)40 Control (org.apache.directory.api.ldap.model.message.Control)38 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)35 AbstractCodecServiceTest (org.apache.directory.api.ldap.extras.AbstractCodecServiceTest)35 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)33 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)33 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)28 SyncInfoValue (org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValue)20 SyncInfoValueDecorator (org.apache.directory.api.ldap.extras.intermediate.syncrepl.SyncInfoValueDecorator)20 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)20 AndNode (org.apache.directory.api.ldap.model.filter.AndNode)15 Entry (org.apache.directory.api.ldap.model.entry.Entry)14 EqualityNode (org.apache.directory.api.ldap.model.filter.EqualityNode)14