use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreMessageId 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();
// The Length should not be null
if (tlv.getLength() == 0) {
LOG.error(I18n.err(I18n.ERR_04068));
// This will generate a PROTOCOL_ERROR
throw new DecoderException(I18n.err(I18n.ERR_04069));
}
BerValue value = tlv.getValue();
try {
int messageId = IntegerDecoder.parse(value, 0, Integer.MAX_VALUE);
container.setMessageId(messageId);
if (IS_DEBUG) {
LOG.debug("Ldap Message Id has been decoded : " + messageId);
}
} catch (IntegerDecoderException ide) {
LOG.error(I18n.err(I18n.ERR_04070, Strings.dumpBytes(value.getData()), ide.getLocalizedMessage()));
// This will generate a PROTOCOL_ERROR
throw new DecoderException(ide.getMessage(), ide);
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class AddReferral method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
TLV tlv = container.getCurrentTLV();
Message response = container.getMessage();
LdapResult ldapResult = ((ResultResponse) response).getLdapResult();
Referral referral = ldapResult.getReferral();
if (tlv.getLength() == 0) {
referral.addLdapUrl("");
} else {
if (ldapResult.getResultCode() == ResultCodeEnum.REFERRAL) {
try {
String url = Strings.utf8ToString(tlv.getValue().getData());
referral.addLdapUrl(new LdapUrl(url).toString());
} catch (LdapURLEncodingException luee) {
String badUrl = Strings.utf8ToString(tlv.getValue().getData());
LOG.error(I18n.err(I18n.ERR_04015, badUrl, luee.getMessage()));
throw new DecoderException(I18n.err(I18n.ERR_04016, luee.getMessage()), luee);
}
} else {
LOG.warn("The Referral error message is not allowed when havind an error code no equals to REFERRAL");
referral.addLdapUrl(LdapUrl.EMPTY_URL.toString());
}
}
if (IS_DEBUG) {
StringBuilder sb = new StringBuilder();
boolean isFirst = true;
for (String url : ldapResult.getReferral().getLdapUrls()) {
if (isFirst) {
isFirst = false;
} else {
sb.append(", ");
}
sb.append(url);
}
LOG.debug("The referral error message is set to " + sb.toString());
}
// We can have an END transition
container.setGrammarEndAllowed(true);
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreTypeMatchingRule method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
SearchRequestDecorator searchRequest = container.getMessage();
TLV tlv = container.getCurrentTLV();
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04022);
LOG.error(msg);
throw new DecoderException(msg);
} else {
// Store the value.
ExtensibleMatchFilter extensibleMatchFilter = (ExtensibleMatchFilter) searchRequest.getTerminalFilter();
String type = Strings.utf8ToString(tlv.getValue().getData());
extensibleMatchFilter.setType(type);
if (IS_DEBUG) {
LOG.debug("Stored a type matching rule : {}", type);
}
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class ApiAsn1BerOsgiTest method useBundleClasses.
@Override
protected void useBundleClasses() throws Exception {
new CheckNotNullLength<Asn1Container>();
new Asn1Decoder().getMaxLengthLength();
new BerValue().init(5);
new TLV(1).getValue();
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreAssertionValue method action.
/**
* {@inheritDoc}
*/
@Override
public void action(VirtualListViewRequestContainer vlvContainer) {
TLV tlv = vlvContainer.getCurrentTLV();
if (tlv.getLength() != 0) {
byte[] assertionValue = tlv.getValue().getData();
vlvContainer.getDecorator().setAssertionValue(assertionValue);
} else {
vlvContainer.getDecorator().setAssertionValue(Strings.EMPTY_BYTES);
}
// The last element is optional, we can quit here
vlvContainer.setGrammarEndAllowed(true);
}
Aggregations