Package org.apache.directory.shared.ldap.codec

Examples of org.apache.directory.shared.ldap.codec.LdapMessageCodec


                }
               
                if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED )
                {
                    // get back the decoded message
                    LdapMessageCodec message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
                   
                    if ( IS_DEBUG )
                    {
                        LOG.debug( "Decoded LdapMessage : " +
                                ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage() );
View Full Code Here


     */
    public void encode( IoSession session, Object request, ProtocolEncoderOutput out ) throws Exception
    {
        if ( request instanceof LdapMessageCodec )
        {
            LdapMessageCodec ldapRequest = (LdapMessageCodec)request;
            ByteBuffer bb = ldapRequest.encode();
            bb.flip();
           
            IoBuffer buffer = IoBuffer.allocate( bb.limit(), false );
            buffer.setAutoExpand( false );
            buffer.put( bb );
View Full Code Here

        // If the session has not been establish, or is closed, we get out immediately
        checkSession();

        // Create the new message and update the messageId
        LdapMessageCodec bindMessage = createBindMessage( bindRequest );

        int newId = bindMessage.getMessageId();

        LOG.debug( "-----------------------------------------------------------------" );
        LOG.debug( "Sending request \n{}", bindMessage );

        // Create a future for this Bind operation
View Full Code Here

     * requests, or call the listener.
     */
    public void messageReceived( IoSession session, Object message ) throws Exception
    {
        // Feed the response and store it into the session
        LdapMessageCodec response = ( LdapMessageCodec ) message;
       
        LOG.debug( "-------> {} Message received <-------", response );

        // this check is necessary to prevent adding an abandoned operation's
        // result(s) to corresponding queue
        ResponseFuture<? extends Response> responseFuture = peekFromFutureMap( response.getMessageId() );

        if ( responseFuture == null )
        {
            LOG.info( "There is no future associated with the messageId {}, ignoring the message", response
                .getMessageId() );
            return;
        }

        int messageId = response.getMessageId();

        switch ( response.getMessageType() )
        {
            case ADD_RESPONSE:
                // Transform the response
                AddResponseCodec addRespCodec = (AddResponseCodec)response;
                addRespCodec.addControl( response.getCurrentControl() );
                addRespCodec.setMessageId( messageId );

                AddResponse addResponse = convert( addRespCodec );
               
                AddFuture addFuture = (AddFuture)responseFuture;

                if ( addFuture == null )
                {
                    LOG.error( "AddFuture is null" );
                    throw new LdapException( "AddFuture is null"  );
                }
               
                // remove the listener from the listener map
                if ( LOG.isDebugEnabled() )
                {
                    if ( addResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
                    {
                        // Everything is fine, return the response
                        LOG.debug( "Add successful : {}", addResponse );
                    }
                    else
                    {
                        // We have had an error
                        LOG.debug( "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
                BindResponseCodec bindResponseCodec = (BindResponseCodec)response;
                bindResponseCodec.setMessageId( messageId );
                bindResponseCodec.addControl( response.getCurrentControl() );
                BindResponse bindResponse = convert( bindResponseCodec );

                BindFuture bindFuture = (BindFuture)responseFuture;

                if ( bindFuture == null )
                {
                    LOG.error( "BindFuture is null" );
                    throw new LdapException( "BindFuture is null"  );
                }
               
                // remove the listener from the listener map
                if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
                {
                    authenticated.set( true );

                    // Everything is fine, return the response
                    LOG.debug( "Bind successful : {}", bindResponse );
                }
                else
                {
                    // We have had an error
                    LOG.debug( "Bind failed : {}", 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
                CompareResponseCodec compResCodec = (CompareResponseCodec)response;
                compResCodec.setMessageId( messageId );
                compResCodec.addControl( response.getCurrentControl() );

                CompareResponse compareResponse = convert( compResCodec );
               
                CompareFuture compareFuture = (CompareFuture)responseFuture;

                if ( compareFuture == null )
                {
                    LOG.error( "CompareFuture is null" );
                    throw new LdapException( "CompareFuture is null"  );
                }
               
                // remove the listener from the listener map
                if ( LOG.isDebugEnabled() )
                {
                    if ( compareResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
                    {
                        // Everything is fine, return the response
                        LOG.debug( "Compare successful : {}", compareResponse );
                    }
                    else
                    {
                        // We have had an error
                        LOG.debug( "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
                DelResponseCodec delRespCodec = (DelResponseCodec)response;
                delRespCodec.addControl( response.getCurrentControl() );
                delRespCodec.setMessageId( messageId );

                DeleteResponse deleteResponse = convert( delRespCodec );
               
                DeleteFuture deleteFuture = (DeleteFuture)responseFuture;

                if ( deleteFuture == null )
                {
                    LOG.error( "DeleteFuture is null" );
                    throw new LdapException( "DeleteFuture is null"  );
                }
               
                if ( LOG.isDebugEnabled() )
                {
                    if ( deleteResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
                    {
                        // Everything is fine, return the response
                        LOG.debug( "Delete successful : {}", deleteResponse );
                    }
                    else
                    {
                        // We have had an error
                        LOG.debug( "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
                ExtendedResponseCodec extResCodec = (ExtendedResponseCodec)response;
                extResCodec.setMessageId( messageId );
                extResCodec.addControl( response.getCurrentControl() );

                ExtendedResponse extendedResponse = convert( extResCodec );

                ExtendedFuture extendedFuture = (ExtendedFuture)responseFuture;

                if ( extendedFuture == null )
                {
                    LOG.error( "ExtendedFuture is null" );
                    throw new LdapException( "extendedFuture is null"  );
                }

                // remove the listener from the listener map
                if ( LOG.isDebugEnabled() )
                {
                    if ( extendedResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
                    {
                        // Everything is fine, return the response
                        LOG.debug( "Extended successful : {}", extendedResponse );
                    }
                    else
                    {
                        // We have had an error
                        LOG.debug( "Extended failed : {}", extendedResponse );
                    }
                }

                // Store the response into the future
                extendedFuture.set( extendedResponse );

                // Remove the future from the map
                removeFromFutureMaps( messageId );

                break;

            case INTERMEDIATE_RESPONSE:
                IntermediateResponseCodec intermediateResponseCodec = (IntermediateResponseCodec)response;
                intermediateResponseCodec.setMessageId( messageId );
                intermediateResponseCodec.addControl( response.getCurrentControl() );

                setIResponse( intermediateResponseCodec, responseFuture );
               
                break;

            case MODIFY_RESPONSE:
                // Transform the response
                ModifyResponseCodec modRespCodec = (ModifyResponseCodec)response;
                modRespCodec.setMessageId( messageId );
                modRespCodec.addControl( response.getCurrentControl() );

                ModifyResponse modifyResp = convert( modRespCodec );
               
                ModifyFuture modifyFuture = (ModifyFuture)responseFuture;

                if ( modifyFuture == null )
                {
                    LOG.error( "ModifyFuture is null" );
                    throw new LdapException( "ModifyFuture is null"  );
                }
               
                if ( LOG.isDebugEnabled() )
                {
                    if ( modifyResp.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
                    {
                        // Everything is fine, return the response
                        LOG.debug( "ModifyFuture successful : {}", modifyResp );
                    }
                    else
                    {
                        // We have had an error
                        LOG.debug( "ModifyFuture failed : {}", modifyResp );
                    }
                }

                // Store the response into the future
                modifyFuture.set( modifyResp );
               
                // Remove the future from the map
                removeFromFutureMaps( messageId );
               
                break;

            case MODIFYDN_RESPONSE:
                // Transform the response
                ModifyDNResponseCodec modDnRespCodec = (ModifyDNResponseCodec)response;
                modDnRespCodec.setMessageId( messageId );
                modDnRespCodec.addControl( response.getCurrentControl() );

                ModifyDnResponse modifyDnResp = convert( modDnRespCodec );
               
                ModifyDnFuture modifyDnFuture = (ModifyDnFuture)responseFuture;

                if ( modifyDnFuture == null )
                {
                    LOG.error( "ModifyDNFuture is null" );
                    throw new LdapException( "ModifyDNFuture is null"  );
                }
               
                if ( LOG.isDebugEnabled() )
                {
                    if ( modifyDnResp.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
                    {
                        // Everything is fine, return the response
                        LOG.debug( "ModifyDN successful : {}", modifyDnResp );
                    }
                    else
                    {
                        // We have had an error
                        LOG.debug( "ModifyDN failed : {}", modifyDnResp );
                    }
                }

                // Store the response into the future
                modifyDnFuture.set( modifyDnResp );
               
                // Remove the future from the map
                removeFromFutureMaps( messageId );
               
                break;
               
            case SEARCH_RESULT_DONE:
                // Store the response into the responseQueue
                SearchResultDoneCodec searchResultDoneCodec = (SearchResultDoneCodec)response;
                searchResultDoneCodec.setMessageId( messageId );
                searchResultDoneCodec.addControl( response.getCurrentControl() );
                SearchResultDone searchResultDone = convert( searchResultDoneCodec );

                SearchFuture searchFuture = (SearchFuture)responseFuture;
               
                if ( searchFuture == null )
                {
                    LOG.error( "SearchFuture is null" );
                    throw new LdapException( "SearchFuture is null"  );
                }
               
                if ( LOG.isDebugEnabled() )
                {
                    if ( searchResultDone.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
                    {
                        // Everything is fine, return the response
                        LOG.debug( "Search successful : {}", searchResultDone );
                    }
                    else
                    {
                        // We have had an error
                        LOG.debug( "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
                SearchResultEntryCodec searchResultEntryCodec = (SearchResultEntryCodec)response;
                searchResultEntryCodec.setMessageId( messageId );
                searchResultEntryCodec.addControl( response.getCurrentControl() );

                SearchResultEntry srchEntry = convert( searchResultEntryCodec );

                searchFuture = (SearchFuture)responseFuture;
               
                if ( searchFuture == null )
                {
                    LOG.error( "SearchFuture is null" );
                    throw new LdapException( "SearchFuture is null"  );
                }
               
                if ( LOG.isDebugEnabled() )
                {
                    LOG.debug( "Search entry found : {}", srchEntry );
                }

                // Store the response into the future
                searchFuture.set( srchEntry );
               
                break;

            case SEARCH_RESULT_REFERENCE:
                // Store the response into the responseQueue
                SearchResultReferenceCodec searchResultReferenceCodec = (SearchResultReferenceCodec)response;
                searchResultReferenceCodec.setMessageId( messageId );
                searchResultReferenceCodec.addControl( response.getCurrentControl() );

                SearchResultReference searchResultReference = convert( searchResultReferenceCodec );

                searchFuture = (SearchFuture)responseFuture;
               
                if ( searchFuture == null )
                {
                    LOG.error( "SearchFuture is null" );
                    throw new LdapException( "SearchFuture is null"  );
                }
               
                if ( LOG.isDebugEnabled() )
                {
                    LOG.debug( "Search reference found : {}", searchResultReference );
                }

                // Store the response into the future
                searchFuture.set( searchResultReference );
               
                break;

            default:
                LOG.error( "~~~~~~~~~~~~~~~~~~~~~ Unknown message type {} ~~~~~~~~~~~~~~~~~~~~~", response
                    .getMessageTypeName() );
        }
    }
View Full Code Here


    private LdapMessageCodec readResponse( ByteBuffer bb ) throws IOException, DecoderException
    {

        LdapMessageCodec messageResp = null;

        while ( true )
        {
            int nbRead = channel.read( bb );
View Full Code Here

        sendMessage( bb );

        bb.clear();

        // Get the response
        LdapMessageCodec response = readResponse( bb );

        LdapResultCodec result = ((LdapResponseCodec)response).getLdapResult();

        if ( result.getResultCode() == ResultCodeEnum.SUCCESS )
        {
View Full Code Here

        sendMessage( bb );

        bb.clear();

        // Get the response
        LdapMessageCodec response = readResponse( bb );

        LdapResultCodec result = ((LdapResponseCodec)response).getLdapResult();

        if ( result.getResultCode() == ResultCodeEnum.SUCCESS )
        {
View Full Code Here

        sendMessage( bb );

        bb.clear();

        // Get the response
        LdapMessageCodec response = readResponse( bb );

        LdapResultCodec result = ((LdapResponseCodec)response).getLdapResult();

        if ( result.getResultCode() == ResultCodeEnum.SUCCESS )
        {
View Full Code Here

        sendMessage( bb );

        bb.clear();

        // Get the response
        LdapMessageCodec response = readResponse( bb );

        LdapResultCodec result = ((LdapResponseCodec)response).getLdapResult();

        if ( result.getResultCode() == ResultCodeEnum.SUCCESS )
        {
View Full Code Here

        sendMessage( bb );

        bb.clear();

        // Get the bind response
        LdapMessageCodec response = readResponse( bb );

        LdapResultCodec result = ((LdapResponseCodec)response).getLdapResult();

        if ( result.getResultCode() == ResultCodeEnum.SUCCESS )
        {
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.codec.LdapMessageCodec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.