new org.nasutekds.server.tools.LDAPWriter(socket);
BindRequestProtocolOp bindRequest =
new BindRequestProtocolOp(ByteString.valueOf("cn=Directory Manager"),
3, ByteString.valueOf("password"));
LDAPMessage message = new LDAPMessage(1, bindRequest);
w.writeMessage(message);
message = r.readMessage();
BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp();
assertEquals(bindResponse.getResultCode(), LDAPResultCode.SUCCESS);
// Create a search request and send it to the server. Make sure to include
// the delay request control so it won't complete before we can send the
// cancel request.
SearchRequestProtocolOp searchRequest =
new SearchRequestProtocolOp(ByteString.valueOf("o=test"),
SearchScope.BASE_OBJECT,
DereferencePolicy.NEVER_DEREF_ALIASES, 0,
0, false,
LDAPFilter.decode("(match=false)"),
new LinkedHashSet<String>());
message = new LDAPMessage(2, searchRequest,
DelayPreOpPlugin.createDelayControlList(5000));
w.writeMessage(message);
// Create a cancel request and send it to the server.
ByteStringBuilder builder = new ByteStringBuilder();
ASN1Writer writer = ASN1.getWriter(builder);
writer.writeStartSequence();
writer.writeInteger(2);
writer.writeEndSequence();
ExtendedRequestProtocolOp extendedRequest =
new ExtendedRequestProtocolOp(OID_CANCEL_REQUEST,
builder.toByteString());
message = new LDAPMessage(3, extendedRequest);
w.writeMessage(message);
// Read two response messages from the server. One should be a search
// result done and the other should be an extended response. They should
// both have a result code of "cancelled".
for (int i=0; i < 2; i++)
{
message = r.readMessage();
switch (message.getProtocolOpType())
{
case OP_TYPE_SEARCH_RESULT_DONE:
SearchResultDoneProtocolOp searchResultDone =
message.getSearchResultDoneProtocolOp();
assertEquals(searchResultDone.getResultCode(),
LDAPResultCode.CANCELED);
break;
case OP_TYPE_EXTENDED_RESPONSE:
ExtendedResponseProtocolOp extendedResponse =
message.getExtendedResponseProtocolOp();
assertEquals(extendedResponse.getResultCode(),
LDAPResultCode.CANCELED);
break;
default:
}