Search in sources :

Example 1 with SearchResultDone

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

the class SearchResultDoneTest method testDecodeSearchResultDoneSuccessWithControls.

/**
 * Test the decoding of a SearchResultDone with controls
 */
@Test
public void testDecodeSearchResultDoneSuccessWithControls() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x2B);
    stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
    0x29, 0x02, 0x01, // messageID MessageID
    0x01, 0x65, // CHOICE { ..., searchResDone SearchResultDone, ...
    0x07, // SearchResultDone ::= [APPLICATION 5] LDAPResult
    0x0A, 0x01, // LDAPResult ::= SEQUENCE {
    0x00, // },
    0x04, // matchedDN LDAPDN,
    0x00, 0x04, // errorMessage LDAPString,
    0x00, // }
    (byte) 0xA0, // A control
    0x1B, 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    LdapMessageContainer<SearchResultDoneDecorator> ldapMessageContainer = new LdapMessageContainer<SearchResultDoneDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    SearchResultDone searchResultDone = ldapMessageContainer.getMessage();
    assertEquals(1, searchResultDone.getMessageId());
    assertEquals(ResultCodeEnum.SUCCESS, searchResultDone.getLdapResult().getResultCode());
    assertEquals("", searchResultDone.getLdapResult().getMatchedDn().getName());
    assertEquals("", searchResultDone.getLdapResult().getDiagnosticMessage());
    // Check the Control
    Map<String, Control> controls = searchResultDone.getControls();
    assertEquals(1, controls.size());
    @SuppressWarnings("unchecked") CodecControl<Control> control = (org.apache.directory.api.ldap.codec.api.CodecControl<Control>) controls.get("2.16.840.1.113730.3.4.2");
    assertEquals("2.16.840.1.113730.3.4.2", control.getOid());
    assertEquals("", Strings.dumpBytes((byte[]) control.getValue()));
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(searchResultDone);
        // Check the length
        assertEquals(0x2B, 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) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) ByteBuffer(java.nio.ByteBuffer) DecoderException(org.apache.directory.api.asn1.DecoderException) 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) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) SearchResultDoneDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultDoneDecorator) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 2 with SearchResultDone

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

the class SearchResultDoneTest method testDecodeSearchResultDoneEsyncRefresh.

/**
 * Test the decoding of a SearchResultDone with a result code of length 2 bytes
 */
@Test
public void testDecodeSearchResultDoneEsyncRefresh() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x0F);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    0x0D, 0x02, 0x01, // messageID MessageID
    0x01, 0x65, // CHOICE { ..., searchResDone SearchResultDone, ...
    0x08, // SearchResultDone ::= [APPLICATION 5] LDAPResult
    0x0A, 0x02, 0x10, // LDAPResult ::= SEQUENCE {
    0x00, // },
    0x04, // matchedDN LDAPDN,
    0x00, 0x04, // errorMessage LDAPString,
    0x00 // referral [3] Referral OPTIONAL }
    // }
    });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a SearchResultDone Container
    LdapMessageContainer<SearchResultDoneDecorator> ldapMessageContainer = new LdapMessageContainer<SearchResultDoneDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    SearchResultDone searchResultDone = ldapMessageContainer.getMessage();
    assertEquals(1, searchResultDone.getMessageId());
    assertEquals(ResultCodeEnum.E_SYNC_REFRESH_REQUIRED, searchResultDone.getLdapResult().getResultCode());
    assertEquals("", searchResultDone.getLdapResult().getMatchedDn().getName());
    assertEquals("", searchResultDone.getLdapResult().getDiagnosticMessage());
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(searchResultDone);
        // Check the length
        assertEquals(0x0F, 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) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) SearchResultDoneDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultDoneDecorator) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 3 with SearchResultDone

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

the class Dsmlv2Engine method processRequest.

/**
 * Processes a single request
 *
 * @param request the request to process
 * @param respWriter The writer used to store the DSML response
 * @exception Exception If we had an error while processing the request
 */
protected void processRequest(DsmlDecorator<? extends Request> request, BufferedWriter respWriter) throws Exception {
    ResultCodeEnum resultCode = null;
    switch(request.getDecorated().getType()) {
        case ABANDON_REQUEST:
            connection.abandon((AbandonRequest) request);
            return;
        case ADD_REQUEST:
            AddResponse response = connection.add((AddRequest) request);
            resultCode = response.getLdapResult().getResultCode();
            AddResponseDsml addResponseDsml = new AddResponseDsml(connection.getCodecService(), response);
            writeResponse(respWriter, addResponseDsml);
            break;
        case BIND_REQUEST:
            BindResponse bindResponse = connection.bind((BindRequest) request);
            resultCode = bindResponse.getLdapResult().getResultCode();
            BindResponseDsml authResponseDsml = new BindResponseDsml(connection.getCodecService(), bindResponse);
            writeResponse(respWriter, authResponseDsml);
            break;
        case COMPARE_REQUEST:
            CompareResponse compareResponse = connection.compare((CompareRequest) request);
            resultCode = compareResponse.getLdapResult().getResultCode();
            CompareResponseDsml compareResponseDsml = new CompareResponseDsml(connection.getCodecService(), compareResponse);
            writeResponse(respWriter, compareResponseDsml);
            break;
        case DEL_REQUEST:
            DeleteResponse delResponse = connection.delete((DeleteRequest) request);
            resultCode = delResponse.getLdapResult().getResultCode();
            DelResponseDsml delResponseDsml = new DelResponseDsml(connection.getCodecService(), delResponse);
            writeResponse(respWriter, delResponseDsml);
            break;
        case EXTENDED_REQUEST:
            ExtendedResponse extendedResponse = connection.extended((ExtendedRequest) request);
            resultCode = extendedResponse.getLdapResult().getResultCode();
            ExtendedResponseDsml extendedResponseDsml = new ExtendedResponseDsml(connection.getCodecService(), extendedResponse);
            writeResponse(respWriter, extendedResponseDsml);
            break;
        case MODIFY_REQUEST:
            ModifyResponse modifyResponse = connection.modify((ModifyRequest) request);
            resultCode = modifyResponse.getLdapResult().getResultCode();
            ModifyResponseDsml modifyResponseDsml = new ModifyResponseDsml(connection.getCodecService(), modifyResponse);
            writeResponse(respWriter, modifyResponseDsml);
            break;
        case MODIFYDN_REQUEST:
            ModifyDnResponse modifyDnResponse = connection.modifyDn((ModifyDnRequest) request);
            resultCode = modifyDnResponse.getLdapResult().getResultCode();
            ModDNResponseDsml modDNResponseDsml = new ModDNResponseDsml(connection.getCodecService(), modifyDnResponse);
            writeResponse(respWriter, modDNResponseDsml);
            break;
        case SEARCH_REQUEST:
            SearchCursor searchResponses = connection.search((SearchRequest) request);
            SearchResponseDsml searchResponseDsml = new SearchResponseDsml(connection.getCodecService());
            if (respWriter != null) {
                StringBuilder sb = new StringBuilder();
                sb.append("<searchResponse");
                if (request.getDecorated().getMessageId() > 0) {
                    sb.append(" requestID=\"");
                    sb.append(request.getDecorated().getMessageId());
                    sb.append('"');
                }
                sb.append('>');
                respWriter.write(sb.toString());
            }
            while (searchResponses.next()) {
                Response searchResponse = searchResponses.get();
                if (searchResponse.getType() == MessageTypeEnum.SEARCH_RESULT_ENTRY) {
                    SearchResultEntry searchResultEntry = (SearchResultEntry) searchResponse;
                    SearchResultEntryDsml searchResultEntryDsml = new SearchResultEntryDsml(connection.getCodecService(), searchResultEntry);
                    searchResponseDsml = new SearchResponseDsml(connection.getCodecService(), searchResultEntryDsml);
                    if (respWriter != null) {
                        writeResponse(respWriter, searchResultEntryDsml);
                    } else {
                        searchResponseDsml.addResponse(searchResultEntryDsml);
                    }
                } else if (searchResponse.getType() == MessageTypeEnum.SEARCH_RESULT_REFERENCE) {
                    SearchResultReference searchResultReference = (SearchResultReference) searchResponse;
                    SearchResultReferenceDsml searchResultReferenceDsml = new SearchResultReferenceDsml(connection.getCodecService(), searchResultReference);
                    searchResponseDsml = new SearchResponseDsml(connection.getCodecService(), searchResultReferenceDsml);
                    if (respWriter != null) {
                        writeResponse(respWriter, searchResultReferenceDsml);
                    } else {
                        searchResponseDsml.addResponse(searchResultReferenceDsml);
                    }
                }
            }
            SearchResultDone srDone = searchResponses.getSearchResultDone();
            if (srDone != null) {
                resultCode = srDone.getLdapResult().getResultCode();
                SearchResultDoneDsml srdDsml = new SearchResultDoneDsml(connection.getCodecService(), srDone);
                if (respWriter != null) {
                    writeResponse(respWriter, srdDsml);
                    respWriter.write("</searchResponse>");
                } else {
                    searchResponseDsml.addResponse(srdDsml);
                    batchResponse.addResponse(searchResponseDsml);
                }
            }
            break;
        case UNBIND_REQUEST:
            connection.unBind();
            break;
        default:
            throw new IllegalStateException("Unexpected request tpye " + request.getDecorated().getType());
    }
    if ((!continueOnError) && (resultCode != null) && (resultCode != ResultCodeEnum.SUCCESS) && (resultCode != ResultCodeEnum.COMPARE_TRUE) && (resultCode != ResultCodeEnum.COMPARE_FALSE) && (resultCode != ResultCodeEnum.REFERRAL)) {
        // Turning on Exit flag
        exit = true;
    }
}
Also used : DelResponseDsml(org.apache.directory.api.dsmlv2.response.DelResponseDsml) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) BindResponse(org.apache.directory.api.ldap.model.message.BindResponse) SearchResultDoneDsml(org.apache.directory.api.dsmlv2.response.SearchResultDoneDsml) ResultCodeEnum(org.apache.directory.api.ldap.model.message.ResultCodeEnum) ModifyResponseDsml(org.apache.directory.api.dsmlv2.response.ModifyResponseDsml) CompareResponseDsml(org.apache.directory.api.dsmlv2.response.CompareResponseDsml) ModifyDnResponse(org.apache.directory.api.ldap.model.message.ModifyDnResponse) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) CompareResponse(org.apache.directory.api.ldap.model.message.CompareResponse) SearchResponseDsml(org.apache.directory.api.dsmlv2.response.SearchResponseDsml) SearchResultEntryDsml(org.apache.directory.api.dsmlv2.response.SearchResultEntryDsml) AddResponseDsml(org.apache.directory.api.dsmlv2.response.AddResponseDsml) SearchResultReferenceDsml(org.apache.directory.api.dsmlv2.response.SearchResultReferenceDsml) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) AddResponse(org.apache.directory.api.ldap.model.message.AddResponse) BindResponseDsml(org.apache.directory.api.dsmlv2.response.BindResponseDsml) ErrorResponse(org.apache.directory.api.dsmlv2.response.ErrorResponse) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) CompareResponse(org.apache.directory.api.ldap.model.message.CompareResponse) AddResponse(org.apache.directory.api.ldap.model.message.AddResponse) DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) Response(org.apache.directory.api.ldap.model.message.Response) ModifyDnResponse(org.apache.directory.api.ldap.model.message.ModifyDnResponse) BindResponse(org.apache.directory.api.ldap.model.message.BindResponse) ExtendedResponseDsml(org.apache.directory.api.dsmlv2.response.ExtendedResponseDsml) DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) ModDNResponseDsml(org.apache.directory.api.dsmlv2.response.ModDNResponseDsml) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry)

Example 4 with SearchResultDone

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

the class LdapNetworkConnection method messageReceived.

/**
 * Handle the incoming LDAP messages. This is where we feed the cursor for search
 * requests, or call the listener.
 *
 * @param session The session that received a message
 * @param message The received message
 * @throws Exception If there is some error while processing the message
 */
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
    // Feed the response and store it into the session
    if (message instanceof SslFilter.SslFilterMessage) {
        // This is a SSL message telling if the session has been secured or not
        HandshakeFuture handshakeFuture = (HandshakeFuture) ldapSession.getAttribute("HANDSHAKE_FUTURE");
        if (message == SslFilter.SESSION_SECURED) {
            // SECURED
            handshakeFuture.secured();
        } else {
            // UNSECURED
            handshakeFuture.cancel();
        }
        ldapSession.removeAttribute("HANDSHAKE_FUTURE");
        return;
    }
    Message response = (Message) message;
    if (LOG.isDebugEnabled()) {
        LOG.debug(I18n.msg(I18n.MSG_03243_MESSAGE_RECEIVED, response));
    }
    int messageId = response.getMessageId();
    // this check is necessary to prevent adding an abandoned operation's
    // result(s) to corresponding queue
    ResponseFuture<? extends Response> responseFuture = peekFromFutureMap(messageId);
    boolean isNoD = isNoticeOfDisconnect(response);
    if ((responseFuture == null) && !isNoD) {
        LOG.info("There is no future associated with the messageId {}, ignoring the message", messageId);
        return;
    }
    if (isNoD) {
        // close the session
        session.closeNow();
        return;
    }
    switch(response.getType()) {
        case ADD_RESPONSE:
            // Transform the response
            AddResponse addResponse = (AddResponse) response;
            AddFuture addFuture = (AddFuture) responseFuture;
            // remove the listener from the listener map
            if (LOG.isDebugEnabled()) {
                if (addResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
                    // Everything is fine, return the response
                    LOG.debug(I18n.msg(I18n.MSG_03209_ADD_SUCCESSFUL, addResponse));
                } else {
                    // We have had an error
                    LOG.debug(I18n.msg(I18n.MSG_03208_ADD_FAILED, addResponse));
                }
            }
            // Store the response into the future
            addFuture.set(addResponse);
            // Remove the future from the map
            removeFromFutureMaps(messageId);
            break;
        case BIND_RESPONSE:
            // Transform the response
            BindResponse bindResponse = (BindResponse) response;
            BindFuture bindFuture = (BindFuture) responseFuture;
            // remove the listener from the listener map
            if (bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
                authenticated.set(true);
                // Everything is fine, return the response
                if (LOG.isDebugEnabled()) {
                    LOG.debug(I18n.msg(I18n.MSG_03202_BIND_SUCCESSFUL, bindResponse));
                }
            } else {
                // We have had an error
                if (LOG.isDebugEnabled()) {
                    LOG.debug(I18n.msg(I18n.MSG_03201_BIND_FAIL, bindResponse));
                }
            }
            // Store the response into the future
            bindFuture.set(bindResponse);
            // Remove the future from the map
            removeFromFutureMaps(messageId);
            break;
        case COMPARE_RESPONSE:
            // Transform the response
            CompareResponse compareResponse = (CompareResponse) response;
            CompareFuture compareFuture = (CompareFuture) responseFuture;
            // remove the listener from the listener map
            if (LOG.isDebugEnabled()) {
                if (compareResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
                    // Everything is fine, return the response
                    LOG.debug(I18n.msg(I18n.MSG_03215_COMPARE_SUCCESSFUL, compareResponse));
                } else {
                    // We have had an error
                    LOG.debug(I18n.msg(I18n.MSG_03214_COMPARE_FAILED, compareResponse));
                }
            }
            // Store the response into the future
            compareFuture.set(compareResponse);
            // Remove the future from the map
            removeFromFutureMaps(messageId);
            break;
        case DEL_RESPONSE:
            // Transform the response
            DeleteResponse deleteResponse = (DeleteResponse) response;
            DeleteFuture deleteFuture = (DeleteFuture) responseFuture;
            if (LOG.isDebugEnabled()) {
                if (deleteResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
                    // Everything is fine, return the response
                    LOG.debug(I18n.msg(I18n.MSG_03217_DELETE_SUCCESSFUL, deleteResponse));
                } else {
                    // We have had an error
                    LOG.debug(I18n.msg(I18n.MSG_03216_DELETE_FAILED, deleteResponse));
                }
            }
            // Store the response into the future
            deleteFuture.set(deleteResponse);
            // Remove the future from the map
            removeFromFutureMaps(messageId);
            break;
        case EXTENDED_RESPONSE:
            // Transform the response
            ExtendedResponse extendedResponse = (ExtendedResponse) response;
            ExtendedFuture extendedFuture = (ExtendedFuture) responseFuture;
            // remove the listener from the listener map
            if (LOG.isDebugEnabled()) {
                if (extendedResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
                    // Everything is fine, return the response
                    LOG.debug(I18n.msg(I18n.MSG_03219_EXTENDED_SUCCESSFUL, extendedResponse));
                } else {
                    // We have had an error
                    LOG.debug(I18n.msg(I18n.MSG_03218_EXTENDED_FAILED, extendedResponse));
                }
            }
            // Store the response into the future
            extendedFuture.set(extendedResponse);
            // Remove the future from the map
            removeFromFutureMaps(messageId);
            break;
        case INTERMEDIATE_RESPONSE:
            IntermediateResponse intermediateResponse;
            if (responseFuture instanceof SearchFuture) {
                intermediateResponse = new IntermediateResponseImpl(messageId);
                addControls(intermediateResponse, response);
                ((SearchFuture) responseFuture).set(intermediateResponse);
            } else if (responseFuture instanceof ExtendedFuture) {
                intermediateResponse = new IntermediateResponseImpl(messageId);
                addControls(intermediateResponse, response);
                ((ExtendedFuture) responseFuture).set(intermediateResponse);
            } else {
                // currently we only support IR for search and extended operations
                throw new UnsupportedOperationException("Unknown ResponseFuture type " + responseFuture.getClass().getName());
            }
            intermediateResponse.setResponseName(((IntermediateResponse) response).getResponseName());
            intermediateResponse.setResponseValue(((IntermediateResponse) response).getResponseValue());
            break;
        case MODIFY_RESPONSE:
            // Transform the response
            ModifyResponse modifyResponse = (ModifyResponse) response;
            ModifyFuture modifyFuture = (ModifyFuture) responseFuture;
            if (LOG.isDebugEnabled()) {
                if (modifyResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
                    // Everything is fine, return the response
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(I18n.msg(I18n.MSG_03224_MODIFY_SUCCESSFUL, modifyResponse));
                    }
                } else {
                    // We have had an error
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(I18n.msg(I18n.MSG_03223_MODIFY_FAILED, modifyResponse));
                    }
                }
            }
            // Store the response into the future
            modifyFuture.set(modifyResponse);
            // Remove the future from the map
            removeFromFutureMaps(messageId);
            break;
        case MODIFYDN_RESPONSE:
            // Transform the response
            ModifyDnResponse modifyDnResponse = (ModifyDnResponse) response;
            ModifyDnFuture modifyDnFuture = (ModifyDnFuture) responseFuture;
            if (LOG.isDebugEnabled()) {
                if (modifyDnResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
                    // Everything is fine, return the response
                    LOG.debug(I18n.msg(I18n.MSG_03226_MODIFYDN_SUCCESSFUL, modifyDnResponse));
                } else {
                    // We have had an error
                    LOG.debug(I18n.msg(I18n.MSG_03225_MODIFYDN_FAILED, modifyDnResponse));
                }
            }
            // Store the response into the future
            modifyDnFuture.set(modifyDnResponse);
            // Remove the future from the map
            removeFromFutureMaps(messageId);
            break;
        case SEARCH_RESULT_DONE:
            // Store the response into the responseQueue
            SearchResultDone searchResultDone = (SearchResultDone) response;
            SearchFuture searchFuture = (SearchFuture) responseFuture;
            if (LOG.isDebugEnabled()) {
                if (searchResultDone.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
                    // Everything is fine, return the response
                    LOG.debug(I18n.msg(I18n.MSG_03232_SEARCH_SUCCESSFUL, searchResultDone));
                } else {
                    // We have had an error
                    LOG.debug(I18n.msg(I18n.MSG_03230_SEARCH_FAILED, searchResultDone));
                }
            }
            // Store the response into the future
            searchFuture.set(searchResultDone);
            // Remove the future from the map
            removeFromFutureMaps(messageId);
            break;
        case SEARCH_RESULT_ENTRY:
            // Store the response into the responseQueue
            SearchResultEntry searchResultEntry = (SearchResultEntry) response;
            if (schemaManager != null) {
                searchResultEntry.setEntry(new DefaultEntry(schemaManager, searchResultEntry.getEntry()));
            }
            searchFuture = (SearchFuture) responseFuture;
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03229_SEARCH_ENTRY_FOUND, searchResultEntry));
            }
            // Store the response into the future
            searchFuture.set(searchResultEntry);
            break;
        case SEARCH_RESULT_REFERENCE:
            // Store the response into the responseQueue
            SearchResultReference searchResultReference = (SearchResultReference) response;
            searchFuture = (SearchFuture) responseFuture;
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03231_SEARCH_REFERENCE_FOUND, searchResultReference));
            }
            // Store the response into the future
            searchFuture.set(searchResultReference);
            break;
        default:
            throw new IllegalStateException("Unexpected response type " + response.getType());
    }
}
Also used : ModifyFuture(org.apache.directory.ldap.client.api.future.ModifyFuture) HandshakeFuture(org.apache.directory.ldap.client.api.future.HandshakeFuture) Message(org.apache.directory.api.ldap.model.message.Message) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) IntermediateResponseImpl(org.apache.directory.api.ldap.model.message.IntermediateResponseImpl) BindResponse(org.apache.directory.api.ldap.model.message.BindResponse) BindFuture(org.apache.directory.ldap.client.api.future.BindFuture) ModifyDnFuture(org.apache.directory.ldap.client.api.future.ModifyDnFuture) IntermediateResponse(org.apache.directory.api.ldap.model.message.IntermediateResponse) ModifyDnResponse(org.apache.directory.api.ldap.model.message.ModifyDnResponse) CompareFuture(org.apache.directory.ldap.client.api.future.CompareFuture) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) CompareResponse(org.apache.directory.api.ldap.model.message.CompareResponse) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) ExtendedFuture(org.apache.directory.ldap.client.api.future.ExtendedFuture) AddResponse(org.apache.directory.api.ldap.model.message.AddResponse) DeleteFuture(org.apache.directory.ldap.client.api.future.DeleteFuture) DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) AddFuture(org.apache.directory.ldap.client.api.future.AddFuture) SearchFuture(org.apache.directory.ldap.client.api.future.SearchFuture) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry)

Example 5 with SearchResultDone

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

the class SearchResultDoneTest method testResponseWith1Referral.

/**
 * Test parsing of a response with a Referral
 */
@Test
public void testResponseWith1Referral() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResultDoneTest.class.getResource("response_with_1_referral.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResultDone searchResultDone = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getSearchResultDone();
    LdapResult ldapResult = searchResultDone.getLdapResult();
    Collection<String> referrals = ldapResult.getReferral().getLdapUrls();
    assertEquals(1, referrals.size());
    try {
        assertTrue(referrals.contains(new LdapUrl("ldap://www.apache.org/").toString()));
    } catch (LdapURLEncodingException e) {
        fail();
    }
}
Also used : LdapUrl(org.apache.directory.api.ldap.model.url.LdapUrl) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) SearchResponse(org.apache.directory.api.dsmlv2.response.SearchResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Aggregations

SearchResultDone (org.apache.directory.api.ldap.model.message.SearchResultDone)21 Test (org.junit.Test)16 AbstractResponseTest (org.apache.directory.api.dsmlv2.AbstractResponseTest)13 Dsmlv2ResponseParser (org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser)13 SearchResponse (org.apache.directory.api.dsmlv2.response.SearchResponse)13 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)13 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)8 Control (org.apache.directory.api.ldap.model.message.Control)6 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)4 SearchResultDoneDecorator (org.apache.directory.api.ldap.codec.decorators.SearchResultDoneDecorator)4 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)4 SearchResultReference (org.apache.directory.api.ldap.model.message.SearchResultReference)4 ByteBuffer (java.nio.ByteBuffer)3 DecoderException (org.apache.directory.api.asn1.DecoderException)3 EncoderException (org.apache.directory.api.asn1.EncoderException)3 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)3 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)3 IOException (java.io.IOException)2 AddResponse (org.apache.directory.api.ldap.model.message.AddResponse)2