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());
}
}
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;
}
Aggregations