Search in sources :

Example 11 with IntermediateResponse

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

the class IntermediateResponseTest method testDecodeIntermediateResponseNoValue.

/**
 * Test the decoding of an IntermediateResponse with no value
 */
@Test
public void testDecodeIntermediateResponseNoValue() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x16);
    stream.put(new byte[] { // LDAPMessage ::= SEQUENCE {
    0x30, // LDAPMessage ::= SEQUENCE {
    0x14, 0x02, 0x01, // messageID MessageID
    0x01, // CHOICE { ..., intermediateResponse IntermediateResponse, ...
    0x79, // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
    0x0F, // responseName [0] LDAPOID,
    (byte) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2' });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<IntermediateResponseDecorator<?>> ldapMessageContainer = new LdapMessageContainer<IntermediateResponseDecorator<?>>(codec);
    // Decode the IntermediateResponse PDU
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    // Check the decoded IntermediateResponse PDU
    IntermediateResponse intermediateResponse = ldapMessageContainer.getMessage();
    assertEquals(1, intermediateResponse.getMessageId());
    assertEquals("1.3.6.1.5.5.2", intermediateResponse.getResponseName());
    assertEquals("", Strings.utf8ToString(intermediateResponse.getResponseValue()));
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(intermediateResponse);
        // Check the length
        assertEquals(0x16, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) IntermediateResponseDecorator(org.apache.directory.api.ldap.codec.decorators.IntermediateResponseDecorator) IntermediateResponse(org.apache.directory.api.ldap.model.message.IntermediateResponse) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 12 with IntermediateResponse

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

the class DefaultLdapCodecService method newIntermediateResponse.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public <I extends IntermediateResponse> I newIntermediateResponse(String responseName, int messageId, byte[] serializedResponse) throws DecoderException {
    IntermediateResponseDecorator<IntermediateResponse> resp;
    IntermediateResponseFactory intermediateResponseFactory = intermediateResponseFactories.get(responseName);
    if (intermediateResponseFactory != null) {
        resp = (IntermediateResponseDecorator<IntermediateResponse>) intermediateResponseFactory.newResponse(serializedResponse);
    } else {
        resp = new IntermediateResponseDecorator<IntermediateResponse>(this, new IntermediateResponseImpl(responseName));
        resp.setResponseValue(serializedResponse);
        resp.setResponseName(responseName);
    }
    resp.setMessageId(messageId);
    return (I) resp;
}
Also used : IntermediateResponse(org.apache.directory.api.ldap.model.message.IntermediateResponse) IntermediateResponseFactory(org.apache.directory.api.ldap.codec.api.IntermediateResponseFactory) IntermediateResponseImpl(org.apache.directory.api.ldap.model.message.IntermediateResponseImpl)

Aggregations

IntermediateResponse (org.apache.directory.api.ldap.model.message.IntermediateResponse)12 DecoderException (org.apache.directory.api.asn1.DecoderException)8 IntermediateResponseDecorator (org.apache.directory.api.ldap.codec.decorators.IntermediateResponseDecorator)8 ByteBuffer (java.nio.ByteBuffer)7 EncoderException (org.apache.directory.api.asn1.EncoderException)7 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)7 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)7 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)7 Test (org.junit.Test)7 Control (org.apache.directory.api.ldap.model.message.Control)3 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)2 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)2 AddResponse (org.apache.directory.api.ldap.model.message.AddResponse)2 BindResponse (org.apache.directory.api.ldap.model.message.BindResponse)2 CompareResponse (org.apache.directory.api.ldap.model.message.CompareResponse)2 DeleteResponse (org.apache.directory.api.ldap.model.message.DeleteResponse)2 IntermediateResponseFactory (org.apache.directory.api.ldap.codec.api.IntermediateResponseFactory)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