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;
}
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;
}
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;
}
}
};
}
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;
}
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;
}
Aggregations