Search in sources :

Example 11 with ExtendedResponse

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

the class LdapNetworkConnection method extended.

/**
 * {@inheritDoc}
 */
@Override
public ExtendedResponse extended(ExtendedRequest extendedRequest) throws LdapException {
    if (extendedRequest == null) {
        String msg = "Cannot process a null extendedRequest";
        LOG.debug(msg);
        throw new IllegalArgumentException(msg);
    }
    ExtendedFuture extendedFuture = extendedAsync(extendedRequest);
    // Get the result from the future
    try {
        // Read the response, waiting for it if not available immediately
        // Get the response, blocking
        ExtendedResponse response = (ExtendedResponse) extendedFuture.get(timeout, TimeUnit.MILLISECONDS);
        if (response == null) {
            // We didn't received anything : this is an error
            if (LOG.isErrorEnabled()) {
                LOG.error(I18n.err(I18n.ERR_03203_OP_FAILED_TIMEOUT, "Extended"));
            }
            throw new LdapException(TIME_OUT_ERROR);
        }
        if (response.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
            // Everything is fine, return the response
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03219_EXTENDED_SUCCESSFUL, response));
            }
        } else {
            // We have had an error
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03218_EXTENDED_FAILED, response));
            }
        }
        // Get back the response. It's still an opaque response
        if (Strings.isEmpty(response.getResponseName())) {
            response.setResponseName(extendedRequest.getRequestName());
        }
        // Decode the payload now
        return codec.decorate(response);
    } catch (Exception ie) {
        // Catch all other exceptions
        LOG.error(NO_RESPONSE_ERROR, ie);
        // Send an abandon request
        if (!extendedFuture.isCancelled()) {
            abandon(extendedRequest.getMessageId());
        }
        throw new LdapException(NO_RESPONSE_ERROR, ie);
    }
}
Also used : ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedFuture(org.apache.directory.ldap.client.api.future.ExtendedFuture) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) InvalidConnectionException(org.apache.directory.ldap.client.api.exception.InvalidConnectionException) LdapOperationException(org.apache.directory.api.ldap.model.exception.LdapOperationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) MessageEncoderException(org.apache.directory.api.ldap.codec.api.MessageEncoderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) ProtocolEncoderException(org.apache.mina.filter.codec.ProtocolEncoderException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 12 with ExtendedResponse

use of org.apache.directory.api.ldap.model.message.ExtendedResponse 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 13 with ExtendedResponse

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

the class WhoAmIFactory method decorate.

/**
 * {@inheritDoc}
 */
@Override
public WhoAmIResponseDecorator decorate(ExtendedResponse decoratedResponse) {
    if (decoratedResponse instanceof WhoAmIResponseDecorator) {
        return (WhoAmIResponseDecorator) decoratedResponse;
    }
    if (decoratedResponse instanceof WhoAmIResponse) {
        return new WhoAmIResponseDecorator(codec, (WhoAmIResponse) decoratedResponse);
    }
    // It's an opaque extended operation
    @SuppressWarnings("unchecked") ExtendedResponseDecorator<ExtendedResponse> response = (ExtendedResponseDecorator<ExtendedResponse>) decoratedResponse;
    // Decode the response, as it's an opaque operation
    Asn1Decoder decoder = new Asn1Decoder();
    byte[] value = response.getResponseValue();
    ByteBuffer buffer = ByteBuffer.wrap(value);
    WhoAmIResponseContainer container = new WhoAmIResponseContainer();
    WhoAmIResponse whoAmIResponse = null;
    try {
        decoder.decode(buffer, container);
        whoAmIResponse = container.getWhoAmIResponse();
        // Now, update the created response with what we got from the extendedResponse
        whoAmIResponse.getLdapResult().setResultCode(response.getLdapResult().getResultCode());
        whoAmIResponse.getLdapResult().setDiagnosticMessage(response.getLdapResult().getDiagnosticMessage());
        whoAmIResponse.getLdapResult().setMatchedDn(response.getLdapResult().getMatchedDn());
        whoAmIResponse.getLdapResult().setReferral(response.getLdapResult().getReferral());
    } catch (DecoderException de) {
        StringWriter sw = new StringWriter();
        de.printStackTrace(new PrintWriter(sw));
        String stackTrace = sw.toString();
        // Error while decoding the value.
        whoAmIResponse = new WhoAmIResponseImpl(decoratedResponse.getMessageId(), ResultCodeEnum.OPERATIONS_ERROR, stackTrace);
    }
    return new WhoAmIResponseDecorator(codec, whoAmIResponse);
}
Also used : WhoAmIResponseImpl(org.apache.directory.api.ldap.extras.extended.whoAmI.WhoAmIResponseImpl) WhoAmIResponse(org.apache.directory.api.ldap.extras.extended.whoAmI.WhoAmIResponse) ByteBuffer(java.nio.ByteBuffer) DecoderException(org.apache.directory.api.asn1.DecoderException) StringWriter(java.io.StringWriter) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) PrintWriter(java.io.PrintWriter)

Example 14 with ExtendedResponse

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

the class PasswordModifyFactory method decorate.

/**
 * {@inheritDoc}
 */
@Override
public PasswordModifyResponseDecorator decorate(ExtendedResponse decoratedResponse) {
    if (decoratedResponse instanceof PasswordModifyResponseDecorator) {
        return (PasswordModifyResponseDecorator) decoratedResponse;
    }
    if (decoratedResponse instanceof PasswordModifyResponse) {
        return new PasswordModifyResponseDecorator(codec, (PasswordModifyResponse) decoratedResponse);
    }
    // It's an opaque extended operation
    @SuppressWarnings("unchecked") ExtendedResponseDecorator<ExtendedResponse> response = (ExtendedResponseDecorator<ExtendedResponse>) decoratedResponse;
    // Decode the response, as it's an opaque operation
    Asn1Decoder decoder = new Asn1Decoder();
    byte[] value = response.getResponseValue();
    PasswordModifyResponseContainer container = new PasswordModifyResponseContainer();
    PasswordModifyResponse pwdModifyResponse;
    if (value != null) {
        ByteBuffer buffer = ByteBuffer.wrap(value);
        try {
            decoder.decode(buffer, container);
            pwdModifyResponse = container.getPwdModifyResponse();
            // Now, update the created response with what we got from the extendedResponse
            pwdModifyResponse.getLdapResult().setResultCode(response.getLdapResult().getResultCode());
            pwdModifyResponse.getLdapResult().setDiagnosticMessage(response.getLdapResult().getDiagnosticMessage());
            pwdModifyResponse.getLdapResult().setMatchedDn(response.getLdapResult().getMatchedDn());
            pwdModifyResponse.getLdapResult().setReferral(response.getLdapResult().getReferral());
        } catch (DecoderException de) {
            StringWriter sw = new StringWriter();
            de.printStackTrace(new PrintWriter(sw));
            String stackTrace = sw.toString();
            // Error while decoding the value.
            pwdModifyResponse = new PasswordModifyResponseImpl(decoratedResponse.getMessageId(), ResultCodeEnum.OPERATIONS_ERROR, stackTrace);
        }
    } else {
        pwdModifyResponse = new PasswordModifyResponseImpl();
        // Now, update the created response with what we got from the extendedResponse
        pwdModifyResponse.getLdapResult().setResultCode(response.getLdapResult().getResultCode());
        pwdModifyResponse.getLdapResult().setDiagnosticMessage(response.getLdapResult().getDiagnosticMessage());
        pwdModifyResponse.getLdapResult().setMatchedDn(response.getLdapResult().getMatchedDn());
        pwdModifyResponse.getLdapResult().setReferral(response.getLdapResult().getReferral());
    }
    PasswordModifyResponseDecorator decorated = new PasswordModifyResponseDecorator(codec, pwdModifyResponse);
    Control ppolicyControl = response.getControl(PasswordPolicy.OID);
    if (ppolicyControl != null) {
        decorated.addControl(ppolicyControl);
    }
    return decorated;
}
Also used : ByteBuffer(java.nio.ByteBuffer) DecoderException(org.apache.directory.api.asn1.DecoderException) Control(org.apache.directory.api.ldap.model.message.Control) PasswordModifyResponse(org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponse) StringWriter(java.io.StringWriter) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) PasswordModifyResponseImpl(org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponseImpl) PrintWriter(java.io.PrintWriter)

Example 15 with ExtendedResponse

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

the class MessageDecorator method getDecorator.

/**
 * Gets the decorator associated with a given message
 *
 * @param codec The LdapApiService to use
 * @param decoratedMessage The message to decorate
 * @return The decorator instance
 */
public static MessageDecorator<? extends Message> getDecorator(LdapApiService codec, Message decoratedMessage) {
    if (decoratedMessage instanceof MessageDecorator) {
        return (MessageDecorator<?>) decoratedMessage;
    }
    MessageDecorator<?> decorator;
    switch(decoratedMessage.getType()) {
        case ABANDON_REQUEST:
            decorator = new AbandonRequestDecorator(codec, (AbandonRequest) decoratedMessage);
            break;
        case ADD_REQUEST:
            decorator = new AddRequestDecorator(codec, (AddRequest) decoratedMessage);
            break;
        case ADD_RESPONSE:
            decorator = new AddResponseDecorator(codec, (AddResponse) decoratedMessage);
            break;
        case BIND_REQUEST:
            decorator = new BindRequestDecorator(codec, (BindRequest) decoratedMessage);
            break;
        case BIND_RESPONSE:
            decorator = new BindResponseDecorator(codec, (BindResponse) decoratedMessage);
            break;
        case COMPARE_REQUEST:
            decorator = new CompareRequestDecorator(codec, (CompareRequest) decoratedMessage);
            break;
        case COMPARE_RESPONSE:
            decorator = new CompareResponseDecorator(codec, (CompareResponse) decoratedMessage);
            break;
        case DEL_REQUEST:
            decorator = new DeleteRequestDecorator(codec, (DeleteRequest) decoratedMessage);
            break;
        case DEL_RESPONSE:
            decorator = new DeleteResponseDecorator(codec, (DeleteResponse) decoratedMessage);
            break;
        case EXTENDED_REQUEST:
            decorator = codec.decorate((ExtendedRequest) decoratedMessage);
            break;
        case EXTENDED_RESPONSE:
            decorator = codec.decorate((ExtendedResponse) decoratedMessage);
            break;
        case INTERMEDIATE_RESPONSE:
            decorator = new IntermediateResponseDecorator(codec, (IntermediateResponse) decoratedMessage);
            break;
        case MODIFY_REQUEST:
            decorator = new ModifyRequestDecorator(codec, (ModifyRequest) decoratedMessage);
            break;
        case MODIFY_RESPONSE:
            decorator = new ModifyResponseDecorator(codec, (ModifyResponse) decoratedMessage);
            break;
        case MODIFYDN_REQUEST:
            decorator = new ModifyDnRequestDecorator(codec, (ModifyDnRequest) decoratedMessage);
            break;
        case MODIFYDN_RESPONSE:
            decorator = new ModifyDnResponseDecorator(codec, (ModifyDnResponse) decoratedMessage);
            break;
        case SEARCH_REQUEST:
            decorator = new SearchRequestDecorator(codec, (SearchRequest) decoratedMessage);
            break;
        case SEARCH_RESULT_DONE:
            decorator = new SearchResultDoneDecorator(codec, (SearchResultDone) decoratedMessage);
            break;
        case SEARCH_RESULT_ENTRY:
            decorator = new SearchResultEntryDecorator(codec, (SearchResultEntry) decoratedMessage);
            break;
        case SEARCH_RESULT_REFERENCE:
            decorator = new SearchResultReferenceDecorator(codec, (SearchResultReference) decoratedMessage);
            break;
        case UNBIND_REQUEST:
            decorator = new UnbindRequestDecorator(codec, (UnbindRequest) decoratedMessage);
            break;
        default:
            return null;
    }
    Map<String, Control> controls = decoratedMessage.getControls();
    if (controls != null) {
        for (Control control : controls.values()) {
            decorator.addControl(control);
        }
    }
    return decorator;
}
Also used : ModifyRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) DeleteRequestDecorator(org.apache.directory.api.ldap.codec.decorators.DeleteRequestDecorator) SearchResultEntryDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator) AbandonRequest(org.apache.directory.api.ldap.model.message.AbandonRequest) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) DeleteResponseDecorator(org.apache.directory.api.ldap.codec.decorators.DeleteResponseDecorator) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) BindResponseDecorator(org.apache.directory.api.ldap.codec.decorators.BindResponseDecorator) BindResponse(org.apache.directory.api.ldap.model.message.BindResponse) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) AbandonRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AbandonRequestDecorator) AddResponseDecorator(org.apache.directory.api.ldap.codec.decorators.AddResponseDecorator) AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) IntermediateResponseDecorator(org.apache.directory.api.ldap.codec.decorators.IntermediateResponseDecorator) IntermediateResponse(org.apache.directory.api.ldap.model.message.IntermediateResponse) Control(org.apache.directory.api.ldap.model.message.Control) BindRequestDecorator(org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator) UnbindRequestDecorator(org.apache.directory.api.ldap.codec.decorators.UnbindRequestDecorator) CompareRequestDecorator(org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator) ModifyDnRequestDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyDnRequestDecorator) ModifyDnResponse(org.apache.directory.api.ldap.model.message.ModifyDnResponse) SearchResultReferenceDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultReferenceDecorator) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) UnbindRequest(org.apache.directory.api.ldap.model.message.UnbindRequest) CompareResponse(org.apache.directory.api.ldap.model.message.CompareResponse) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) ModifyDnRequest(org.apache.directory.api.ldap.model.message.ModifyDnRequest) AddResponse(org.apache.directory.api.ldap.model.message.AddResponse) CompareResponseDecorator(org.apache.directory.api.ldap.codec.decorators.CompareResponseDecorator) CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) ModifyResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyResponseDecorator) ModifyDnResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyDnResponseDecorator) ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest) SearchResultDoneDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultDoneDecorator) AddRequestDecorator(org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry)

Aggregations

ExtendedResponse (org.apache.directory.api.ldap.model.message.ExtendedResponse)30 DecoderException (org.apache.directory.api.asn1.DecoderException)22 Test (org.junit.Test)19 AbstractResponseTest (org.apache.directory.api.dsmlv2.AbstractResponseTest)17 Dsmlv2ResponseParser (org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser)17 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)15 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)8 ExtendedResponseDecorator (org.apache.directory.api.ldap.codec.decorators.ExtendedResponseDecorator)7 Control (org.apache.directory.api.ldap.model.message.Control)6 ByteBuffer (java.nio.ByteBuffer)4 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)4 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)4 LdapUrl (org.apache.directory.api.ldap.model.url.LdapUrl)3 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 ConnectException (java.net.ConnectException)2 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)2 EncoderException (org.apache.directory.api.asn1.EncoderException)2 BatchResponseDsml (org.apache.directory.api.dsmlv2.response.BatchResponseDsml)2