Search in sources :

Example 6 with ExtendedRequest

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());
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 7 with ExtendedRequest

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();
    }
}
Also used : BatchRequestDsml(org.apache.directory.api.dsmlv2.request.BatchRequestDsml) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 8 with ExtendedRequest

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;
}
Also used : ExtendedRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedRequestDecorator) ExtendedRequestImpl(org.apache.directory.api.ldap.model.message.ExtendedRequestImpl) ExtendedOperationFactory(org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest)

Aggregations

ExtendedRequest (org.apache.directory.api.ldap.model.message.ExtendedRequest)8 DecoderException (org.apache.directory.api.asn1.DecoderException)2 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)2 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)2 BatchRequestDsml (org.apache.directory.api.dsmlv2.request.BatchRequestDsml)2 ExtendedOperationFactory (org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory)2 ExtendedRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ExtendedRequestDecorator)2 AbandonRequest (org.apache.directory.api.ldap.model.message.AbandonRequest)2 AddRequest (org.apache.directory.api.ldap.model.message.AddRequest)2 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)2 CompareRequest (org.apache.directory.api.ldap.model.message.CompareRequest)2 DeleteRequest (org.apache.directory.api.ldap.model.message.DeleteRequest)2 ExtendedResponse (org.apache.directory.api.ldap.model.message.ExtendedResponse)2 NamingException (javax.naming.NamingException)1 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)1 Oid (org.apache.directory.api.asn1.util.Oid)1 BinaryAttributeDetector (org.apache.directory.api.ldap.codec.api.BinaryAttributeDetector)1 AbandonRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator)1 AddRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator)1 AddResponseDecorator (org.apache.directory.api.ldap.codec.decorators.AddResponseDecorator)1