Search in sources :

Example 76 with EncoderException

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

the class SearchResultReferenceDecorator method encode.

/**
 * Encode the SearchResultReference message to a PDU.
 * <br>
 * SearchResultReference :
 * <pre>
 * 0x73 LL
 *   0x04 LL reference
 *   [0x04 LL reference]*
 * </pre>
 *
 * @param buffer The buffer where to put the PDU
 * @return The PDU.
 */
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
    SearchResultReference searchResultReference = getDecorated();
    try {
        // The SearchResultReference Tag
        buffer.put(LdapCodecConstants.SEARCH_RESULT_REFERENCE_TAG);
        buffer.put(TLV.getBytes(searchResultReferenceLength));
        // The referrals, if any
        Referral referral = searchResultReference.getReferral();
        if (referral != null) {
            // Each referral
            for (byte[] ldapUrlBytes : referral.getLdapUrlsBytes()) {
                // Encode the current referral
                BerValue.encode(buffer, ldapUrlBytes);
            }
        }
    } catch (BufferOverflowException boe) {
        throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
    }
    return buffer;
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) Referral(org.apache.directory.api.ldap.model.message.Referral) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) BufferOverflowException(java.nio.BufferOverflowException)

Example 77 with EncoderException

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

the class UnbindRequestDecorator method encode.

/**
 * Encode the Unbind protocolOp part
 */
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
    try {
        // The tag
        buffer.put(LdapCodecConstants.UNBIND_REQUEST_TAG);
        // The length is always null.
        buffer.put((byte) 0);
    } catch (BufferOverflowException boe) {
        String msg = I18n.err(I18n.ERR_04005);
        throw new EncoderException(msg, boe);
    }
    return buffer;
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) BufferOverflowException(java.nio.BufferOverflowException)

Example 78 with EncoderException

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

the class DefaultLdapCodecService method toJndi.

/**
 * {@inheritDoc}
 */
@Override
public javax.naming.ldap.ExtendedRequest toJndi(final ExtendedRequest modelRequest) throws EncoderException {
    final String oid = modelRequest.getRequestName();
    final byte[] value;
    if (modelRequest instanceof ExtendedRequestDecorator) {
        ExtendedRequestDecorator<?> decorator = (ExtendedRequestDecorator<?>) modelRequest;
        value = decorator.getRequestValue();
    } else {
        // have to ask the factory to decorate for us - can't do it ourselves
        ExtendedOperationFactory extendedRequestFactory = extendedOperationFactories.get(modelRequest.getRequestName());
        ExtendedRequestDecorator<?> decorator = (ExtendedRequestDecorator<?>) extendedRequestFactory.decorate(modelRequest);
        value = decorator.getRequestValue();
    }
    return new javax.naming.ldap.ExtendedRequest() {

        private static final long serialVersionUID = -4160980385909987475L;

        @Override
        public String getID() {
            return oid;
        }

        @Override
        public byte[] getEncodedValue() {
            return value;
        }

        @Override
        public javax.naming.ldap.ExtendedResponse createExtendedResponse(String id, byte[] berValue, int offset, int length) throws NamingException {
            ExtendedOperationFactory factory = extendedOperationFactories.get(modelRequest.getRequestName());
            try {
                final ExtendedResponseDecorator<?> resp = (ExtendedResponseDecorator<?>) factory.newResponse(berValue);
                return new javax.naming.ldap.ExtendedResponse() {

                    private static final long serialVersionUID = -7686354122066100703L;

                    @Override
                    public String getID() {
                        return oid;
                    }

                    @Override
                    public byte[] getEncodedValue() {
                        return resp.getResponseValue();
                    }
                };
            } catch (DecoderException de) {
                NamingException ne = new NamingException("Unable to decode encoded response value: " + Strings.dumpBytes(berValue));
                ne.setRootCause(de);
                throw ne;
            }
        }
    };
}
Also used : ExtendedOperationFactory(org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory) ExtendedRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedRequestDecorator) DecoderException(org.apache.directory.api.asn1.DecoderException) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest) ExtendedResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator) NamingException(javax.naming.NamingException)

Example 79 with EncoderException

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

the class AndFilter method encode.

/**
 * Encode the AndFilter message to a PDU.
 * <br>
 * AndFilter :
 * <pre>
 * 0xA0 LL
 *  filter.encode() ... filter.encode()
 * </pre>
 *
 * @param buffer The buffer where to put the PDU
 * @return The PDU.
 */
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
    if (buffer == null) {
        throw new EncoderException(I18n.err(I18n.ERR_04023));
    }
    try {
        // The AndFilter Tag
        buffer.put((byte) LdapCodecConstants.AND_FILTER_TAG);
        buffer.put(TLV.getBytes(filtersLength));
    } catch (BufferOverflowException boe) {
        throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
    }
    super.encode(buffer);
    return buffer;
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) BufferOverflowException(java.nio.BufferOverflowException)

Example 80 with EncoderException

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

the class CompareRequestDecorator method encode.

/**
 * Encode the CompareRequest message to a PDU.
 * <pre>
 * CompareRequest :
 *   0x6E LL
 *     0x04 LL entry
 *     0x30 LL attributeValueAssertion
 *       0x04 LL attributeDesc
 *       0x04 LL assertionValue
 * </pre>
 *
 * @param buffer The buffer where to put the PDU
 */
@Override
public ByteBuffer encode(ByteBuffer buffer) throws EncoderException {
    try {
        // The CompareRequest Tag
        buffer.put(LdapCodecConstants.COMPARE_REQUEST_TAG);
        buffer.put(TLV.getBytes(compareRequestLength));
        // The entry
        BerValue.encode(buffer, dnBytes);
        // The attributeValueAssertion sequence Tag
        buffer.put(UniversalTag.SEQUENCE.getValue());
        buffer.put(TLV.getBytes(avaLength));
    } catch (BufferOverflowException boe) {
        throw new EncoderException(I18n.err(I18n.ERR_04005), boe);
    }
    // The attributeDesc
    BerValue.encode(buffer, attrIdBytes);
    // The assertionValue
    BerValue.encode(buffer, attrValBytes);
    return buffer;
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) 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