use of org.apache.directory.api.asn1.ber.tlv.BerValue in project directory-ldap-api by apache.
the class StoredProcedureRequestImpl method getParameterValueString.
/**
* Get a parameter value
*
* @param index The position of the parameter in the list of parameters
* @return The paremeter's value
*/
public Object getParameterValueString(int index) {
if (!"java".equals(language)) {
Object obj = parameters.get(index).getValue();
if (obj instanceof byte[]) {
String str = Strings.utf8ToString((byte[]) obj);
String type = (String) getParameterTypeString(index);
if ("int".equals(type)) {
try {
return IntegerDecoder.parse(new BerValue((byte[]) obj));
} catch (IntegerDecoderException e) {
throw new RuntimeException("Failed to decode INTEGER: " + Strings.dumpBytes((byte[]) obj), e);
}
} else {
return str;
}
}
}
return getJavaParameterValue(index);
}
use of org.apache.directory.api.asn1.ber.tlv.BerValue 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.ber.tlv.BerValue in project directory-ldap-api by apache.
the class InitAbandonRequest method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<AbandonRequestDecorator> container) throws DecoderException {
// Create the AbandonRequest LdapMessage instance and store it in the container
AbandonRequest internalAbandonRequest = new AbandonRequestImpl();
internalAbandonRequest.setMessageId(container.getMessageId());
AbandonRequestDecorator abandonRequest = new AbandonRequestDecorator(container.getLdapCodecService(), internalAbandonRequest);
container.setMessage(abandonRequest);
// The current TLV should be a integer
// We get it and store it in MessageId
TLV tlv = container.getCurrentTLV();
BerValue value = tlv.getValue();
if ((value == null) || (value.getData() == null)) {
String msg = I18n.err(I18n.ERR_04075);
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg);
}
try {
int abandonnedMessageId = IntegerDecoder.parse(value, 0, Integer.MAX_VALUE);
abandonRequest.setAbandoned(abandonnedMessageId);
if (IS_DEBUG) {
LOG.debug("AbandonMessage Id has been decoded : {}", Integer.valueOf(abandonnedMessageId));
}
container.setGrammarEndAllowed(true);
return;
} catch (IntegerDecoderException ide) {
LOG.error(I18n.err(I18n.ERR_04076, Strings.dumpBytes(value.getData()), ide.getMessage()));
// This will generate a PROTOCOL_ERROR
throw new DecoderException(ide.getMessage(), ide);
}
}
use of org.apache.directory.api.asn1.ber.tlv.BerValue in project directory-ldap-api by apache.
the class StoreModifyDnRequestDeleteOldRdn method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyDnRequestDecorator> container) throws DecoderException {
ModifyDnRequest modifyDnRequest = container.getMessage();
TLV tlv = container.getCurrentTLV();
// We get the value. If it's a 0, it's a FALSE. If it's
// a FF, it's a TRUE. Any other value should be an error,
// but we could relax this constraint. So if we have
// something
// which is not 0, it will be interpreted as TRUE, but we
// will generate a warning.
BerValue value = tlv.getValue();
try {
modifyDnRequest.setDeleteOldRdn(BooleanDecoder.parse(value));
} catch (BooleanDecoderException bde) {
LOG.error(I18n.err(I18n.ERR_04091, Strings.dumpBytes(value.getData()), bde.getMessage()));
// This will generate a PROTOCOL_ERROR
throw new DecoderException(bde.getMessage(), bde);
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
if (modifyDnRequest.getDeleteOldRdn()) {
LOG.debug(" Old Rdn attributes will be deleted");
} else {
LOG.debug(" Old Rdn attributes will be retained");
}
}
}
use of org.apache.directory.api.asn1.ber.tlv.BerValue in project directory-ldap-api by apache.
the class StoreSearchRequestDerefAlias 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 derefAliases
BerValue value = tlv.getValue();
int derefAliases = 0;
try {
derefAliases = IntegerDecoder.parse(value, LdapCodecConstants.NEVER_DEREF_ALIASES, LdapCodecConstants.DEREF_ALWAYS);
} catch (IntegerDecoderException ide) {
String msg = I18n.err(I18n.ERR_04102, value.toString());
LOG.error(msg);
throw new DecoderException(msg, ide);
}
searchRequest.setDerefAliases(AliasDerefMode.getDerefMode(derefAliases));
if (IS_DEBUG) {
switch(derefAliases) {
case LdapCodecConstants.NEVER_DEREF_ALIASES:
LOG.debug("Handling object strategy : NEVER_DEREF_ALIASES");
break;
case LdapCodecConstants.DEREF_IN_SEARCHING:
LOG.debug("Handling object strategy : DEREF_IN_SEARCHING");
break;
case LdapCodecConstants.DEREF_FINDING_BASE_OBJ:
LOG.debug("Handling object strategy : DEREF_FINDING_BASE_OBJ");
break;
case LdapCodecConstants.DEREF_ALWAYS:
LOG.debug("Handling object strategy : DEREF_ALWAYS");
break;
default:
LOG.debug("Handling object strategy : UNKNOWN");
}
}
}
Aggregations