Search in sources :

Example 6 with OpaqueControl

use of org.apache.directory.api.ldap.model.message.controls.OpaqueControl in project directory-ldap-api by apache.

the class BindRequestPerfTest method testEncodeBindRequestPerf.

/**
 * Test the decoding of a BindRequest with Simple authentication and no
 * controls
 */
@Test
@Ignore
public void testEncodeBindRequestPerf() throws Exception {
    Dn dn = new Dn("uid=akarasulu,dc=example,dc=com");
    int nbLoops = 1000000;
    long t0 = System.currentTimeMillis();
    for (int i = 0; i < nbLoops; i++) {
        // Check the decoded BindRequest
        BindRequest bindRequest = new BindRequestImpl();
        bindRequest.setMessageId(1);
        bindRequest.setSimple(true);
        bindRequest.setDn(dn);
        bindRequest.setCredentials(Strings.getBytesUtf8("password"));
        Control control = new OpaqueControl("2.16.840.1.113730.3.4.2");
        bindRequest.addControl(control);
        // Check the encoding
        try {
            encoder.encodeMessage(bindRequest);
        } catch (EncoderException ee) {
            ee.printStackTrace();
            fail(ee.getMessage());
        }
    }
    long t1 = System.currentTimeMillis();
    System.out.println("BindRequest testEncodeBindRequestPerf, " + nbLoops + " loops, Delta = " + (t1 - t0));
}
Also used : EncoderException(org.apache.directory.api.asn1.EncoderException) Control(org.apache.directory.api.ldap.model.message.Control) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) Dn(org.apache.directory.api.ldap.model.name.Dn) OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl) BindRequestImpl(org.apache.directory.api.ldap.model.message.BindRequestImpl) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 7 with OpaqueControl

use of org.apache.directory.api.ldap.model.message.controls.OpaqueControl in project directory-ldap-api by apache.

the class DefaultLdapCodecService method fromJndiControl.

/**
 * {@inheritDoc}
 */
@Override
public Control fromJndiControl(javax.naming.ldap.Control control) throws DecoderException {
    @SuppressWarnings("rawtypes") ControlFactory factory = controlFactories.get(control.getID());
    if (factory == null) {
        OpaqueControl ourControl = new OpaqueControl(control.getID());
        ourControl.setCritical(control.isCritical());
        BasicControlDecorator decorator = new BasicControlDecorator(this, ourControl);
        decorator.setValue(control.getEncodedValue());
        return decorator;
    }
    @SuppressWarnings("unchecked") CodecControl<? extends Control> ourControl = factory.newCodecControl();
    ourControl.setCritical(control.isCritical());
    ourControl.setValue(control.getEncodedValue());
    ourControl.decode(control.getEncodedValue());
    return ourControl;
}
Also used : BasicControlDecorator(org.apache.directory.api.ldap.codec.BasicControlDecorator) ControlFactory(org.apache.directory.api.ldap.codec.api.ControlFactory) OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl)

Aggregations

OpaqueControl (org.apache.directory.api.ldap.model.message.controls.OpaqueControl)7 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 DeleteRequest (org.apache.directory.api.ldap.model.message.DeleteRequest)2 DeleteRequestImpl (org.apache.directory.api.ldap.model.message.DeleteRequestImpl)2 DeleteResponse (org.apache.directory.api.ldap.model.message.DeleteResponse)2 Dn (org.apache.directory.api.ldap.model.name.Dn)2 Test (org.junit.Test)2 EncoderException (org.apache.directory.api.asn1.EncoderException)1 BasicControlDecorator (org.apache.directory.api.ldap.codec.BasicControlDecorator)1 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)1 ControlFactory (org.apache.directory.api.ldap.codec.api.ControlFactory)1 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)1 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)1 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)1 BindRequestImpl (org.apache.directory.api.ldap.model.message.BindRequestImpl)1 Control (org.apache.directory.api.ldap.model.message.Control)1 BeforeClass (org.junit.BeforeClass)1 Ignore (org.junit.Ignore)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1