use of org.apache.directory.api.ldap.model.message.ExtendedRequest in project directory-ldap-api by apache.
the class StoreExtendedRequestName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ExtendedRequestDecorator<?>> container) throws DecoderException {
ExtendedRequest req;
// Get the Value and store it in the ExtendedRequest
TLV tlv = container.getCurrentTLV();
// OID
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04095);
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg);
} else {
byte[] requestNameBytes = tlv.getValue().getData();
try {
String requestName = Strings.utf8ToString(requestNameBytes);
if (!Oid.isOid(requestName)) {
String msg = "The Request name is not a valid OID : " + Strings.utf8ToString(requestNameBytes) + " (" + Strings.dumpBytes(requestNameBytes) + ") is invalid";
LOG.error(msg);
// throw an exception, we will get a PROTOCOL_ERROR
throw new DecoderException(msg);
}
req = LdapApiServiceFactory.getSingleton().newExtendedRequest(requestName, null);
req.setMessageId(container.getMessageId());
container.setMessage(LdapApiServiceFactory.getSingleton().decorate(req));
} catch (DecoderException de) {
String msg = "The Request name is not a valid OID : " + Strings.utf8ToString(requestNameBytes) + " (" + Strings.dumpBytes(requestNameBytes) + ") is invalid";
LOG.error("{} : {}", msg, de.getMessage());
// Rethrow the exception, we will get a PROTOCOL_ERROR
throw de;
}
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("OID read : {}", req.getRequestName());
}
}
use of org.apache.directory.api.ldap.model.message.ExtendedRequest in project directory-ldap-api by apache.
the class BatchRequestTest method testResponseWith2ExtendedRequest.
/**
* Test parsing of a Request with 2 ExtendedRequest
*/
@Test
public void testResponseWith2ExtendedRequest() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(BatchRequestTest.class.getResource("request_with_2_ExtendedRequest.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
BatchRequestDsml batchRequest = parser.getBatchRequest();
assertEquals(2, batchRequest.getRequests().size());
if (batchRequest.getCurrentRequest() instanceof ExtendedRequest) {
assertTrue(true);
} else {
fail();
}
}
use of org.apache.directory.api.ldap.model.message.ExtendedRequest in project directory-ldap-api by apache.
the class DefaultLdapCodecService method newExtendedRequest.
/**
* {@inheritDoc}
*/
@Override
public ExtendedRequest newExtendedRequest(String oid, byte[] value) {
ExtendedRequest req;
ExtendedOperationFactory extendedRequestFactory = extendedOperationFactories.get(oid);
if (extendedRequestFactory != null) {
req = extendedRequestFactory.newRequest(value);
} else {
ExtendedRequestDecorator<ExtendedRequest> decorator = new ExtendedRequestDecorator(this, new ExtendedRequestImpl());
decorator.setRequestName(oid);
decorator.setRequestValue(value);
req = decorator;
}
return req;
}
Aggregations