directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r984452 [1/2] - in /directory: clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/ clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/director...
Date Wed, 11 Aug 2010 15:52:59 GMT
Author: elecharny
Date: Wed Aug 11 15:52:58 2010
New Revision: 984452

URL: http://svn.apache.org/viewvc?rev=984452&view=rev
Log:
Last step : fixed the Ldap-api to handle InternalMessages for BindResponse

Modified:
    directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
    directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolDecoder.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ErrorMessageAction.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ResultCodeAction.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ServerSASLCredsAction.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindResponseTest.java

Modified: directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=984452&r1=984451&r2=984452&view=diff
==============================================================================
--- directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java (original)
+++ directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java Wed Aug 11 15:52:58 2010
@@ -91,7 +91,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.add.AddRequestCodec;
 import org.apache.directory.shared.ldap.codec.add.AddResponseCodec;
 import org.apache.directory.shared.ldap.codec.bind.BindRequestCodec;
-import org.apache.directory.shared.ldap.codec.bind.BindResponseCodec;
 import org.apache.directory.shared.ldap.codec.bind.LdapAuthentication;
 import org.apache.directory.shared.ldap.codec.bind.SaslCredentials;
 import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication;
@@ -129,6 +128,9 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.message.internal.InternalBindResponse;
+import org.apache.directory.shared.ldap.message.internal.InternalLdapResult;
+import org.apache.directory.shared.ldap.message.internal.InternalMessage;
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.name.RDN;
 import org.apache.directory.shared.ldap.schema.AttributeType;
@@ -360,14 +362,14 @@ public class LdapNetworkConnection exten
     /**
      * Convert a BindResponseCodec to a BindResponse message
      */
-    private BindResponse convert( BindResponseCodec bindResponseCodec )
+    private BindResponse convert( InternalBindResponse internalBindResponse )
     {
         BindResponse bindResponse = new BindResponse();
 
-        bindResponse.setMessageId( bindResponseCodec.getMessageId() );
-        bindResponse.setServerSaslCreds( bindResponseCodec.getServerSaslCreds() );
-        bindResponse.setLdapResult( convert( bindResponseCodec.getLdapResult() ) );
-        addControls( bindResponseCodec, bindResponse );
+        bindResponse.setMessageId( internalBindResponse.getMessageId() );
+        bindResponse.setServerSaslCreds( internalBindResponse.getServerSaslCreds() );
+        bindResponse.setLdapResult( convert( internalBindResponse.getLdapResult() ) );
+        addControls( internalBindResponse, bindResponse );
 
         return bindResponse;
     }
@@ -434,6 +436,36 @@ public class LdapNetworkConnection exten
 
 
     /**
+     * Convert a LdapResultCodec to a LdapResult message
+     */
+    private LdapResult convert( InternalLdapResult internalLdapResult )
+    {
+        LdapResult ldapResult = new LdapResult();
+
+        ldapResult.setErrorMessage( internalLdapResult.getErrorMessage() );
+        ldapResult.setMatchedDn( internalLdapResult.getMatchedDn().getName() );
+
+        // Loop on the referrals
+        Referral referral = new Referral();
+
+        if ( internalLdapResult.getReferral() != null )
+        {
+            Collection<String> ldapUrls = internalLdapResult.getReferral().getLdapUrls();
+
+            for ( String url : ldapUrls )
+            {
+                referral.addLdapUrls( url );
+            }
+        }
+
+        ldapResult.setReferral( referral );
+        ldapResult.setResultCode( internalLdapResult.getResultCode() );
+
+        return ldapResult;
+    }
+
+
+    /**
      * Convert a SearchResultEntryCodec to a SearchResultEntry message
      */
     private SearchResultEntry convert( SearchResultEntryCodec searchEntryResultCodec )
@@ -1541,394 +1573,410 @@ public class LdapNetworkConnection exten
     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 )
+        if ( message instanceof InternalMessage )
         {
-            LOG.info( "There is no future associated with the messageId {}, ignoring the message", response
-                .getMessageId() );
-            return;
-        }
+            InternalMessage response = ( InternalMessage ) message;
+            LOG.debug( "-------> {} Message received <-------", response );
+            int messageId = response.getMessageId();
 
-        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 );
 
-        switch ( response.getMessageType() )
-        {
-            case ADD_RESPONSE:
-                // Transform the response
-                AddResponseCodec addRespCodec = ( AddResponseCodec ) response;
-                addRespCodec.addControls( response.getControls() );
-                addRespCodec.setMessageId( messageId );
+            if ( responseFuture == null )
+            {
+                LOG.info( "There is no future associated with the messageId {}, ignoring the message", messageId );
+                return;
+            }
 
-                AddResponse addResponse = convert( addRespCodec );
+            switch ( response.getType() )
+            {
+                case BIND_RESPONSE:
+                    // Transform the response
+                    BindResponse bindResponse = convert( ( InternalBindResponse ) response );
 
-                AddFuture addFuture = ( AddFuture ) responseFuture;
+                    BindFuture bindFuture = ( BindFuture ) responseFuture;
 
-                if ( addFuture == null )
-                {
-                    LOG.error( "AddFuture is null" );
-                    throw new LdapException( "AddFuture is null" );
-                }
+                    if ( bindFuture == null )
+                    {
+                        LOG.error( "BindFuture is null" );
+                        throw new LdapException( "BindFuture is null" );
+                    }
 
-                // remove the listener from the listener map
-                if ( LOG.isDebugEnabled() )
-                {
-                    if ( addResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
+                    // remove the listener from the listener map
+                    if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
                     {
+                        authenticated.set( true );
+
                         // Everything is fine, return the response
-                        LOG.debug( "Add successful : {}", addResponse );
+                        LOG.debug( "Bind successful : {}", bindResponse );
                     }
                     else
                     {
                         // We have had an error
-                        LOG.debug( "Add failed : {}", addResponse );
+                        LOG.debug( "Bind failed : {}", bindResponse );
                     }
-                }
 
-                // Store the response into the future
-                addFuture.set( addResponse );
+                    // Store the response into the future
+                    bindFuture.set( bindResponse );
 
-                // Remove the future from the map
-                removeFromFutureMaps( messageId );
+                    // Remove the future from the map
+                    removeFromFutureMaps( messageId );
 
-                break;
+                    break;
+            }
+        }
+        else
+        {
+            LdapMessageCodec response = ( LdapMessageCodec ) message;
+            LOG.debug( "-------> {} Message received <-------", response );
+            int messageId = response.getMessageId();
 
-            case BIND_RESPONSE:
-                // Transform the response
-                BindResponseCodec bindResponseCodec = ( BindResponseCodec ) response;
-                bindResponseCodec.setMessageId( messageId );
-                bindResponseCodec.addControls( response.getControls() );
-                BindResponse bindResponse = convert( bindResponseCodec );
+            // this check is necessary to prevent adding an abandoned operation's
+            // result(s) to corresponding queue
+            ResponseFuture<? extends Response> responseFuture = peekFromFutureMap( messageId );
 
-                BindFuture bindFuture = ( BindFuture ) responseFuture;
+            if ( responseFuture == null )
+            {
+                LOG.info( "There is no future associated with the messageId {}, ignoring the message", messageId );
+                return;
+            }
 
-                if ( bindFuture == null )
-                {
-                    LOG.error( "BindFuture is null" );
-                    throw new LdapException( "BindFuture is null" );
-                }
+            switch ( response.getMessageType() )
+            {
+                case ADD_RESPONSE:
+                    // Transform the response
+                    AddResponseCodec addRespCodec = ( AddResponseCodec ) response;
+                    addRespCodec.addControls( response.getControls() );
+                    addRespCodec.setMessageId( messageId );
 
-                // remove the listener from the listener map
-                if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
-                {
-                    authenticated.set( true );
+                    AddResponse addResponse = convert( addRespCodec );
 
-                    // Everything is fine, return the response
-                    LOG.debug( "Bind successful : {}", bindResponse );
-                }
-                else
-                {
-                    // We have had an error
-                    LOG.debug( "Bind failed : {}", bindResponse );
-                }
+                    AddFuture addFuture = ( AddFuture ) responseFuture;
 
-                // Store the response into the future
-                bindFuture.set( bindResponse );
+                    if ( addFuture == null )
+                    {
+                        LOG.error( "AddFuture is null" );
+                        throw new LdapException( "AddFuture is null" );
+                    }
 
-                // Remove the future from the map
-                removeFromFutureMaps( messageId );
+                    // 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 );
+                        }
+                    }
 
-                break;
+                    // Store the response into the future
+                    addFuture.set( addResponse );
 
-            case COMPARE_RESPONSE:
-                // Transform the response
-                CompareResponseCodec compResCodec = ( CompareResponseCodec ) response;
-                compResCodec.setMessageId( messageId );
-                compResCodec.addControls( response.getControls() );
+                    // Remove the future from the map
+                    removeFromFutureMaps( messageId );
 
-                CompareResponse compareResponse = convert( compResCodec );
+                    break;
 
-                CompareFuture compareFuture = ( CompareFuture ) responseFuture;
+                case COMPARE_RESPONSE:
+                    // Transform the response
+                    CompareResponseCodec compResCodec = ( CompareResponseCodec ) response;
+                    compResCodec.setMessageId( messageId );
+                    compResCodec.addControls( response.getControls() );
 
-                if ( compareFuture == null )
-                {
-                    LOG.error( "CompareFuture is null" );
-                    throw new LdapException( "CompareFuture is null" );
-                }
+                    CompareResponse compareResponse = convert( compResCodec );
 
-                // remove the listener from the listener map
-                if ( LOG.isDebugEnabled() )
-                {
-                    if ( compareResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
+                    CompareFuture compareFuture = ( CompareFuture ) responseFuture;
+
+                    if ( compareFuture == null )
                     {
-                        // Everything is fine, return the response
-                        LOG.debug( "Compare successful : {}", compareResponse );
+                        LOG.error( "CompareFuture is null" );
+                        throw new LdapException( "CompareFuture is null" );
                     }
-                    else
+
+                    // remove the listener from the listener map
+                    if ( LOG.isDebugEnabled() )
                     {
-                        // We have had an error
-                        LOG.debug( "Compare failed : {}", compareResponse );
+                        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 );
+                    // Store the response into the future
+                    compareFuture.set( compareResponse );
 
-                // Remove the future from the map
-                removeFromFutureMaps( messageId );
+                    // Remove the future from the map
+                    removeFromFutureMaps( messageId );
 
-                break;
+                    break;
 
-            case DEL_RESPONSE:
-                // Transform the response
-                DelResponseCodec delRespCodec = ( DelResponseCodec ) response;
-                delRespCodec.addControls( response.getControls() );
-                delRespCodec.setMessageId( messageId );
+                case DEL_RESPONSE:
+                    // Transform the response
+                    DelResponseCodec delRespCodec = ( DelResponseCodec ) response;
+                    delRespCodec.addControls( response.getControls() );
+                    delRespCodec.setMessageId( messageId );
 
-                DeleteResponse deleteResponse = convert( delRespCodec );
+                    DeleteResponse deleteResponse = convert( delRespCodec );
 
-                DeleteFuture deleteFuture = ( DeleteFuture ) responseFuture;
+                    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 )
+                    if ( deleteFuture == null )
                     {
-                        // Everything is fine, return the response
-                        LOG.debug( "Delete successful : {}", deleteResponse );
+                        LOG.error( "DeleteFuture is null" );
+                        throw new LdapException( "DeleteFuture is null" );
                     }
-                    else
+
+                    if ( LOG.isDebugEnabled() )
                     {
-                        // We have had an error
-                        LOG.debug( "Delete failed : {}", deleteResponse );
+                        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 );
+                    // Store the response into the future
+                    deleteFuture.set( deleteResponse );
 
-                // Remove the future from the map
-                removeFromFutureMaps( messageId );
+                    // Remove the future from the map
+                    removeFromFutureMaps( messageId );
 
-                break;
+                    break;
 
-            case EXTENDED_RESPONSE:
-                // Transform the response
-                ExtendedResponseCodec extResCodec = ( ExtendedResponseCodec ) response;
-                extResCodec.setMessageId( messageId );
-                extResCodec.addControls( response.getControls() );
+                case EXTENDED_RESPONSE:
+                    // Transform the response
+                    ExtendedResponseCodec extResCodec = ( ExtendedResponseCodec ) response;
+                    extResCodec.setMessageId( messageId );
+                    extResCodec.addControls( response.getControls() );
 
-                ExtendedResponse extendedResponse = convert( extResCodec );
+                    ExtendedResponse extendedResponse = convert( extResCodec );
 
-                ExtendedFuture extendedFuture = ( ExtendedFuture ) responseFuture;
+                    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 )
+                    if ( extendedFuture == null )
                     {
-                        // Everything is fine, return the response
-                        LOG.debug( "Extended successful : {}", extendedResponse );
+                        LOG.error( "ExtendedFuture is null" );
+                        throw new LdapException( "extendedFuture is null" );
                     }
-                    else
+
+                    // remove the listener from the listener map
+                    if ( LOG.isDebugEnabled() )
                     {
-                        // We have had an error
-                        LOG.debug( "Extended failed : {}", extendedResponse );
+                        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 );
+                    // Store the response into the future
+                    extendedFuture.set( extendedResponse );
 
-                // Remove the future from the map
-                removeFromFutureMaps( messageId );
+                    // Remove the future from the map
+                    removeFromFutureMaps( messageId );
 
-                break;
+                    break;
 
-            case INTERMEDIATE_RESPONSE:
-                IntermediateResponseCodec intermediateResponseCodec = ( IntermediateResponseCodec ) response;
-                intermediateResponseCodec.setMessageId( messageId );
-                intermediateResponseCodec.addControls( response.getControls() );
+                case INTERMEDIATE_RESPONSE:
+                    IntermediateResponseCodec intermediateResponseCodec = ( IntermediateResponseCodec ) response;
+                    intermediateResponseCodec.setMessageId( messageId );
+                    intermediateResponseCodec.addControls( response.getControls() );
 
-                setIResponse( intermediateResponseCodec, responseFuture );
+                    setIResponse( intermediateResponseCodec, responseFuture );
 
-                break;
+                    break;
 
-            case MODIFY_RESPONSE:
-                // Transform the response
-                ModifyResponseCodec modRespCodec = ( ModifyResponseCodec ) response;
-                modRespCodec.setMessageId( messageId );
-                modRespCodec.addControls( response.getControls() );
+                case MODIFY_RESPONSE:
+                    // Transform the response
+                    ModifyResponseCodec modRespCodec = ( ModifyResponseCodec ) response;
+                    modRespCodec.setMessageId( messageId );
+                    modRespCodec.addControls( response.getControls() );
 
-                ModifyResponse modifyResp = convert( modRespCodec );
+                    ModifyResponse modifyResp = convert( modRespCodec );
 
-                ModifyFuture modifyFuture = ( ModifyFuture ) responseFuture;
+                    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 )
+                    if ( modifyFuture == null )
                     {
-                        // Everything is fine, return the response
-                        LOG.debug( "ModifyFuture successful : {}", modifyResp );
+                        LOG.error( "ModifyFuture is null" );
+                        throw new LdapException( "ModifyFuture is null" );
                     }
-                    else
+
+                    if ( LOG.isDebugEnabled() )
                     {
-                        // We have had an error
-                        LOG.debug( "ModifyFuture failed : {}", modifyResp );
+                        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 );
+                    // Store the response into the future
+                    modifyFuture.set( modifyResp );
 
-                // Remove the future from the map
-                removeFromFutureMaps( messageId );
+                    // Remove the future from the map
+                    removeFromFutureMaps( messageId );
 
-                break;
+                    break;
 
-            case MODIFYDN_RESPONSE:
-                // Transform the response
-                ModifyDNResponseCodec modDnRespCodec = ( ModifyDNResponseCodec ) response;
-                modDnRespCodec.setMessageId( messageId );
-                modDnRespCodec.addControls( response.getControls() );
+                case MODIFYDN_RESPONSE:
+                    // Transform the response
+                    ModifyDNResponseCodec modDnRespCodec = ( ModifyDNResponseCodec ) response;
+                    modDnRespCodec.setMessageId( messageId );
+                    modDnRespCodec.addControls( response.getControls() );
 
-                ModifyDnResponse modifyDnResp = convert( modDnRespCodec );
+                    ModifyDnResponse modifyDnResp = convert( modDnRespCodec );
 
-                ModifyDnFuture modifyDnFuture = ( ModifyDnFuture ) responseFuture;
+                    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 )
+                    if ( modifyDnFuture == null )
                     {
-                        // Everything is fine, return the response
-                        LOG.debug( "ModifyDN successful : {}", modifyDnResp );
+                        LOG.error( "ModifyDNFuture is null" );
+                        throw new LdapException( "ModifyDNFuture is null" );
                     }
-                    else
+
+                    if ( LOG.isDebugEnabled() )
                     {
-                        // We have had an error
-                        LOG.debug( "ModifyDN failed : {}", modifyDnResp );
+                        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 );
+                    // Store the response into the future
+                    modifyDnFuture.set( modifyDnResp );
 
-                break;
+                    // Remove the future from the map
+                    removeFromFutureMaps( messageId );
 
-            case SEARCH_RESULT_DONE:
-                // Store the response into the responseQueue
-                SearchResultDoneCodec searchResultDoneCodec = ( SearchResultDoneCodec ) response;
-                searchResultDoneCodec.setMessageId( messageId );
-                searchResultDoneCodec.addControls( response.getControls() );
-                SearchResultDone searchResultDone = convert( searchResultDoneCodec );
+                    break;
 
-                SearchFuture searchFuture = ( SearchFuture ) responseFuture;
+                case SEARCH_RESULT_DONE:
+                    // Store the response into the responseQueue
+                    SearchResultDoneCodec searchResultDoneCodec = ( SearchResultDoneCodec ) response;
+                    searchResultDoneCodec.setMessageId( messageId );
+                    searchResultDoneCodec.addControls( response.getControls() );
+                    SearchResultDone searchResultDone = convert( searchResultDoneCodec );
 
-                if ( searchFuture == null )
-                {
-                    LOG.error( "SearchFuture is null" );
-                    throw new LdapException( "SearchFuture is null" );
-                }
+                    SearchFuture searchFuture = ( SearchFuture ) responseFuture;
 
-                if ( LOG.isDebugEnabled() )
-                {
-                    if ( searchResultDone.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
+                    if ( searchFuture == null )
                     {
-                        // Everything is fine, return the response
-                        LOG.debug( "Search successful : {}", searchResultDone );
+                        LOG.error( "SearchFuture is null" );
+                        throw new LdapException( "SearchFuture is null" );
                     }
-                    else
+
+                    if ( LOG.isDebugEnabled() )
                     {
-                        // We have had an error
-                        LOG.debug( "Search failed : {}", searchResultDone );
+                        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 );
+                    // Store the response into the future
+                    searchFuture.set( searchResultDone );
 
-                // Remove the future from the map
-                removeFromFutureMaps( messageId );
+                    // Remove the future from the map
+                    removeFromFutureMaps( messageId );
 
-                break;
+                    break;
 
-            case SEARCH_RESULT_ENTRY:
-                // Store the response into the responseQueue
-                SearchResultEntryCodec searchResultEntryCodec = ( SearchResultEntryCodec ) response;
-                searchResultEntryCodec.setMessageId( messageId );
-                searchResultEntryCodec.addControls( response.getControls() );
+                case SEARCH_RESULT_ENTRY:
+                    // Store the response into the responseQueue
+                    SearchResultEntryCodec searchResultEntryCodec = ( SearchResultEntryCodec ) response;
+                    searchResultEntryCodec.setMessageId( messageId );
+                    searchResultEntryCodec.addControls( response.getControls() );
 
-                SearchResultEntry srchEntry = convert( searchResultEntryCodec );
+                    SearchResultEntry srchEntry = convert( searchResultEntryCodec );
 
-                searchFuture = ( SearchFuture ) responseFuture;
+                    searchFuture = ( SearchFuture ) responseFuture;
 
-                if ( searchFuture == null )
-                {
-                    LOG.error( "SearchFuture is null" );
-                    throw new LdapException( "SearchFuture is null" );
-                }
+                    if ( searchFuture == null )
+                    {
+                        LOG.error( "SearchFuture is null" );
+                        throw new LdapException( "SearchFuture is null" );
+                    }
 
-                if ( LOG.isDebugEnabled() )
-                {
-                    LOG.debug( "Search entry found : {}", srchEntry );
-                }
+                    if ( LOG.isDebugEnabled() )
+                    {
+                        LOG.debug( "Search entry found : {}", srchEntry );
+                    }
 
-                // Store the response into the future
-                searchFuture.set( srchEntry );
+                    // Store the response into the future
+                    searchFuture.set( srchEntry );
 
-                break;
+                    break;
 
-            case SEARCH_RESULT_REFERENCE:
-                // Store the response into the responseQueue
-                SearchResultReferenceCodec searchResultReferenceCodec = ( SearchResultReferenceCodec ) response;
-                searchResultReferenceCodec.setMessageId( messageId );
-                searchResultReferenceCodec.addControls( response.getControls() );
+                case SEARCH_RESULT_REFERENCE:
+                    // Store the response into the responseQueue
+                    SearchResultReferenceCodec searchResultReferenceCodec = ( SearchResultReferenceCodec ) response;
+                    searchResultReferenceCodec.setMessageId( messageId );
+                    searchResultReferenceCodec.addControls( response.getControls() );
 
-                SearchResultReference searchResultReference = convert( searchResultReferenceCodec );
+                    SearchResultReference searchResultReference = convert( searchResultReferenceCodec );
 
-                searchFuture = ( SearchFuture ) responseFuture;
+                    searchFuture = ( SearchFuture ) responseFuture;
 
-                if ( searchFuture == null )
-                {
-                    LOG.error( "SearchFuture is null" );
-                    throw new LdapException( "SearchFuture is null" );
-                }
+                    if ( searchFuture == null )
+                    {
+                        LOG.error( "SearchFuture is null" );
+                        throw new LdapException( "SearchFuture is null" );
+                    }
 
-                if ( LOG.isDebugEnabled() )
-                {
-                    LOG.debug( "Search reference found : {}", searchResultReference );
-                }
+                    if ( LOG.isDebugEnabled() )
+                    {
+                        LOG.debug( "Search reference found : {}", searchResultReference );
+                    }
 
-                // Store the response into the future
-                searchFuture.set( searchResultReference );
+                    // Store the response into the future
+                    searchFuture.set( searchResultReference );
 
-                break;
+                    break;
 
-            default:
-                LOG.error( "~~~~~~~~~~~~~~~~~~~~~ Unknown message type {} ~~~~~~~~~~~~~~~~~~~~~", response
-                    .getMessageTypeName() );
+                default:
+                    LOG.error( "~~~~~~~~~~~~~~~~~~~~~ Unknown message type {} ~~~~~~~~~~~~~~~~~~~~~", response
+                        .getMessageTypeName() );
+            }
         }
     }
 
@@ -3317,6 +3365,30 @@ public class LdapNetworkConnection exten
     }
 
 
+    private void addControls( InternalMessage codec, AbstractMessage message )
+    {
+        Map<String, Control> controls = codec.getControls();
+
+        if ( controls != null )
+        {
+            for ( Control cc : controls.values() )
+            {
+                // FIXME why the cc is coming as null!?
+                if ( cc == null )
+                {
+                    continue;
+                }
+
+                Control control = new ControlImpl( cc.getOid() );
+                control.setValue( cc.getValue() );
+                control.setCritical( cc.isCritical() );
+
+                message.add( control );
+            }
+        }
+    }
+
+
     /**
      * removes the Objects associated with the given message ID
      * from future and response queue maps

Modified: directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolDecoder.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolDecoder.java?rev=984452&r1=984451&r2=984452&view=diff
==============================================================================
--- directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolDecoder.java (original)
+++ directory/clients/ldap/branches/ldap-client-codec-merge/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolDecoder.java Wed Aug 11 15:52:58 2010
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.ldap.client.api.protocol;
 
+
 import java.nio.ByteBuffer;
 
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
@@ -27,6 +28,7 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.message.internal.InternalMessage;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.apache.mina.core.buffer.IoBuffer;
 import org.apache.mina.core.session.IoSession;
@@ -35,6 +37,7 @@ import org.apache.mina.filter.codec.Prot
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 /**
  * 
  * A LDAP message decoder. It is based on shared-ldap decoder.
@@ -45,10 +48,11 @@ public class LdapProtocolDecoder impleme
 {
     /** The logger */
     private static final Logger LOG = LoggerFactory.getLogger( LdapProtocolDecoder.class );
-    
+
     /** A speedup for logger */
     private static final boolean IS_DEBUG = LOG.isDebugEnabled();
 
+
     /**
      * Decode a Ldap request and write it to the remote server.
      * 
@@ -61,71 +65,92 @@ public class LdapProtocolDecoder impleme
     {
         // Allocate a LdapMessage Container
         Asn1Decoder ldapDecoder = new Asn1Decoder();
-        IAsn1Container ldapMessageContainer = (LdapMessageContainer)session.getAttribute( "LDAP-Container" );
+        IAsn1Container ldapMessageContainer = ( LdapMessageContainer ) session.getAttribute( "LDAP-Container" );
         ByteBuffer buf = buffer.buf();
         int currentPos = 0;
-        
+
         while ( buf.hasRemaining() )
         {
             try
             {
                 ldapDecoder.decode( buf, ldapMessageContainer );
-    
+
                 if ( IS_DEBUG )
                 {
                     LOG.debug( "Decoding the PDU : " );
                     int pos = buf.position();
-                    
-                    byte[] b = new byte[pos-currentPos];
-                    
-                    System.arraycopy( buf.array(), currentPos, b, 0, pos-currentPos );
+
+                    byte[] b = new byte[pos - currentPos];
+
+                    System.arraycopy( buf.array(), currentPos, b, 0, pos - currentPos );
                     currentPos = pos;
                     System.out.println( "Received buffer : " + StringTools.dumpBytes( b ) );
                 }
-                
+
                 if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED )
                 {
-                    // get back the decoded message
-                    LdapMessageCodec message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
-                    
-                    if ( IS_DEBUG )
+                    if ( ( ( LdapMessageContainer ) ldapMessageContainer ).isInternal() )
                     {
-                        LOG.debug( "Decoded LdapMessage : " + 
-                                ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage() );
-                        buf.mark();
+                        // get back the decoded message
+                        InternalMessage message = ( ( LdapMessageContainer ) ldapMessageContainer )
+                            .getInternalMessage();
+
+                        if ( IS_DEBUG )
+                        {
+                            LOG.debug( "Decoded LdapMessage : " + message );
+                            buf.mark();
+                        }
+
+                        // Clean the container for the next decoding
+                        ( ( LdapMessageContainer ) ldapMessageContainer ).clean();
+
+                        // Send back the message
+                        out.write( message );
                     }
-    
-                    // Clean the container for the next decoding
-                    ( ( LdapMessageContainer ) ldapMessageContainer).clean();
-                    
-                    if( IS_DEBUG )
+                    else
                     {
-//                        LOG.debug( "######################Decoded message : " + message );
-//                        LOG.debug( "####################################################" );
+                        // get back the decoded message
+                        LdapMessageCodec message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+
+                        if ( IS_DEBUG )
+                        {
+                            LOG.debug( "Decoded LdapMessage : "
+                                + ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage() );
+                            buf.mark();
+                        }
+
+                        // Clean the container for the next decoding
+                        ( ( LdapMessageContainer ) ldapMessageContainer ).clean();
+
+                        if ( IS_DEBUG )
+                        {
+                            //                            LOG.debug( "######################Decoded message : " + message );
+                            //                            LOG.debug( "####################################################" );
+                        }
+
+                        // Send back the message
+                        out.write( message );
                     }
-                    
-                    // Send back the message
-                    out.write( message );
                 }
             }
             catch ( DecoderException de )
             {
                 buf.clear();
-                ( ( LdapMessageContainer ) ldapMessageContainer).clean();
+                ( ( LdapMessageContainer ) ldapMessageContainer ).clean();
                 throw de;
             }
         }
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */
     public void finishDecode( IoSession session, ProtocolDecoderOutput out ) throws Exception
     {
     }
-    
-    
+
+
     /**
      * {@inheritDoc}
      */

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java?rev=984452&r1=984451&r2=984452&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java Wed Aug 11 15:52:58 2010
@@ -223,7 +223,14 @@ public class LdapDecoder implements Prov
                     log.debug( "Decoded LdapMessage : " + ldapMessageContainer.getLdapMessage() );
                 }
 
-                return ldapMessageContainer.getLdapMessage();
+                if ( ldapMessageContainer.isInternal() )
+                {
+                    return ldapMessageContainer.getInternalBindResponse();
+                }
+                else
+                {
+                    return ldapMessageContainer.getLdapMessage();
+                }
             }
             else
             {

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java?rev=984452&r1=984451&r2=984452&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java Wed Aug 11 15:52:58 2010
@@ -22,13 +22,26 @@ package org.apache.directory.shared.ldap
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 import java.nio.channels.Channels;
 import java.nio.channels.WritableByteChannel;
+import java.util.Collection;
+import java.util.Map;
 
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.asn1.codec.stateful.EncoderCallback;
 import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.codec.controls.CodecControl;
+import org.apache.directory.shared.ldap.message.BindResponseImpl;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.message.internal.InternalBindResponse;
+import org.apache.directory.shared.ldap.message.internal.InternalLdapResult;
+import org.apache.directory.shared.ldap.message.internal.InternalMessage;
+import org.apache.directory.shared.ldap.message.internal.InternalReferral;
 import org.apache.directory.shared.ldap.message.spi.Provider;
 import org.apache.directory.shared.ldap.message.spi.ProviderEncoder;
 import org.apache.directory.shared.ldap.message.spi.ProviderException;
@@ -205,10 +218,24 @@ public class LdapEncoder implements Prov
      * @param obj The LdapMessage to encode
      * @throws EncoderException If anything went wrong
      */
-    public void encode( Object obj ) throws EncoderException
+    public void encode( Object request ) throws EncoderException
     {
         //TM long t0 = System.nanoTime();
-        ByteBuffer encoded = encodeBlocking( obj );
+        InternalMessage message = ( InternalMessage ) request;
+        ByteBuffer encoded = null;
+
+        if ( message instanceof InternalBindResponse )
+        {
+            encoded = encodeMessage( message );
+        }
+        else
+        {
+            LdapMessageCodec ldapRequest = ( LdapMessageCodec ) LdapTransformer.transform( ( InternalMessage ) request );
+            encoded = ldapRequest.encode();
+        }
+
+        encoded.flip();
+
         encodeCallback.encodeOccurred( null, encoded );
         //TM long t1 = System.nanoTime();
 
@@ -236,4 +263,404 @@ public class LdapEncoder implements Prov
     {
         encodeCallback = cb;
     }
+
+
+    /**
+     * Generate the PDU which contains the encoded object. 
+     * 
+     * The generation is done in two phases : 
+     * - first, we compute the length of each part and the
+     * global PDU length 
+     * - second, we produce the PDU. 
+     * 
+     * <pre>
+     * 0x30 L1 
+     *   | 
+     *   +--> 0x02 L2 MessageId  
+     *   +--> ProtocolOp 
+     *   +--> Controls 
+     *   
+     * L2 = Length(MessageId)
+     * L1 = Length(0x02) + Length(L2) + L2 + Length(ProtocolOp) + Length(Controls)
+     * LdapMessageLength = Length(0x30) + Length(L1) + L1
+     * </pre>
+     * 
+     * @param message The message to encode
+     * @return A ByteBuffer that contains the PDU
+     * @throws EncoderException If anything goes wrong.
+     */
+    private ByteBuffer encodeMessage( InternalMessage message ) throws EncoderException
+    {
+        int length = computeMessageLength( message );
+
+        try
+        {
+            ByteBuffer buffer = ByteBuffer.allocate( length );
+
+            try
+            {
+                // The LdapMessage Sequence
+                buffer.put( UniversalTag.SEQUENCE_TAG );
+
+                // The length has been calculated by the computeLength method
+                buffer.put( TLV.getBytes( message.getMessageLength() ) );
+            }
+            catch ( BufferOverflowException boe )
+            {
+                throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
+            }
+
+            // The message Id
+            Value.encode( buffer, message.getMessageId() );
+
+            // Add the protocolOp part
+            encodeProtocolOp( buffer, message );
+
+            // Do the same thing for Controls, if any.
+            Map<String, Control> controls = message.getControls();
+
+            if ( ( controls != null ) && ( controls.size() > 0 ) )
+            {
+                // Encode the controls
+                buffer.put( ( byte ) LdapConstants.CONTROLS_TAG );
+                buffer.put( TLV.getBytes( message.getControlsLength() ) );
+
+                // Encode each control
+                for ( Control control : controls.values() )
+                {
+                    ( ( CodecControl ) control ).encode( buffer );
+                }
+            }
+
+            return buffer;
+        }
+        catch ( EncoderException ee )
+        {
+            MessageEncoderException exception = new MessageEncoderException( message.getMessageId(), ee.getMessage() );
+
+            throw exception;
+        }
+    }
+
+
+    /**
+     * Compute the LdapMessage length LdapMessage : 
+     * 0x30 L1 
+     *   | 
+     *   +--> 0x02 0x0(1-4) [0..2^31-1] (MessageId) 
+     *   +--> protocolOp 
+     *   [+--> Controls] 
+     *   
+     * MessageId length = Length(0x02) + length(MessageId) + MessageId.length 
+     * L1 = length(ProtocolOp) 
+     * LdapMessage length = Length(0x30) + Length(L1) + MessageId length + L1
+     */
+    private int computeMessageLength( InternalMessage message )
+    {
+        // The length of the MessageId. It's the sum of
+        // - the tag (0x02), 1 byte
+        // - the length of the Id length, 1 byte
+        // - the Id length, 1 to 4 bytes
+        int ldapMessageLength = 1 + 1 + Value.getNbBytes( message.getMessageId() );
+
+        // Get the protocolOp length
+        ldapMessageLength += computeProtocolOpLength( message );
+        message.setMessageLength( ldapMessageLength );
+
+        Map<String, Control> controls = message.getControls();
+
+        // Do the same thing for Controls, if any.
+        if ( controls.size() > 0 )
+        {
+            // Controls :
+            // 0xA0 L3
+            //   |
+            //   +--> 0x30 L4
+            //   +--> 0x30 L5
+            //   +--> ...
+            //   +--> 0x30 Li
+            //   +--> ...
+            //   +--> 0x30 Ln
+            //
+            // L3 = Length(0x30) + Length(L5) + L5
+            // + Length(0x30) + Length(L6) + L6
+            // + ...
+            // + Length(0x30) + Length(Li) + Li
+            // + ...
+            // + Length(0x30) + Length(Ln) + Ln
+            //
+            // LdapMessageLength = LdapMessageLength + Length(0x90)
+            // + Length(L3) + L3
+            int controlsSequenceLength = 0;
+
+            // We may have more than one control. ControlsLength is L4.
+            for ( Control control : controls.values() )
+            {
+                controlsSequenceLength += ( ( CodecControl ) control ).computeLength();
+            }
+
+            // Computes the controls length
+            // 1 + Length.getNbBytes( controlsSequenceLength ) + controlsSequenceLength;
+            message.setControlsLength( controlsSequenceLength );
+
+            // Now, add the tag and the length of the controls length
+            ldapMessageLength += 1 + TLV.getNbBytes( controlsSequenceLength ) + controlsSequenceLength;
+        }
+
+        // finally, calculate the global message size :
+        // length(Tag) + Length(length) + length
+
+        return 1 + ldapMessageLength + TLV.getNbBytes( ldapMessageLength );
+    }
+
+
+    /**
+     * Compute the LdapResult length 
+     * 
+     * LdapResult : 
+     * 0x0A 01 resultCode (0..80)
+     *   0x04 L1 matchedDN (L1 = Length(matchedDN)) 
+     *   0x04 L2 errorMessage (L2 = Length(errorMessage)) 
+     *   [0x83 L3] referrals 
+     *     | 
+     *     +--> 0x04 L4 referral 
+     *     +--> 0x04 L5 referral 
+     *     +--> ... 
+     *     +--> 0x04 Li referral 
+     *     +--> ... 
+     *     +--> 0x04 Ln referral 
+     *     
+     * L1 = Length(matchedDN) 
+     * L2 = Length(errorMessage) 
+     * L3 = n*Length(0x04) + sum(Length(L4) .. Length(Ln)) + sum(L4..Ln) 
+     * L4..n = Length(0x04) + Length(Li) + Li 
+     * Length(LdapResult) = Length(0x0x0A) +
+     *      Length(0x01) + 1 + Length(0x04) + Length(L1) + L1 + Length(0x04) +
+     *      Length(L2) + L2 + Length(0x83) + Length(L3) + L3
+     */
+    private int computeLdapResultLength( InternalLdapResult ldapResult )
+    {
+        int ldapResultLength = 0;
+
+        // The result code : always 3 bytes
+        ldapResultLength = 1 + 1 + 1;
+
+        // The matchedDN length
+        if ( ldapResult.getMatchedDn() == null )
+        {
+            ldapResultLength += 1 + 1;
+        }
+        else
+        {
+            byte[] matchedDNBytes = StringTools.getBytesUtf8( StringTools
+                .trimLeft( ldapResult.getMatchedDn().getName() ) );
+            ldapResultLength += 1 + TLV.getNbBytes( matchedDNBytes.length ) + matchedDNBytes.length;
+        }
+
+        // The errorMessage length
+        byte[] errorMessageBytes = StringTools.getBytesUtf8( ldapResult.getErrorMessage() );
+        ldapResultLength += 1 + TLV.getNbBytes( errorMessageBytes.length ) + errorMessageBytes.length;
+        ldapResult.setErrorMessageBytes( errorMessageBytes );
+
+        InternalReferral referral = ldapResult.getReferral();
+
+        if ( referral != null )
+        {
+            Collection<String> ldapUrls = referral.getLdapUrls();
+
+            if ( ( ldapUrls != null ) && ( ldapUrls.size() != 0 ) )
+            {
+                int referralsLength = 0;
+
+                // Each referral
+                for ( String ldapUrl : ldapUrls )
+                {
+                    byte[] ldapUrlBytes = StringTools.getBytesUtf8( ldapUrl );
+                    referralsLength += 1 + TLV.getNbBytes( ldapUrlBytes.length ) + ldapUrlBytes.length;
+                    referral.addLdapUrlBytes( ldapUrlBytes );
+                }
+
+                // The referrals
+                ldapResultLength += 1 + TLV.getNbBytes( referralsLength ) + referralsLength;
+            }
+        }
+
+        return ldapResultLength;
+    }
+
+
+    /**
+     * Encode the LdapResult message to a PDU.
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    private ByteBuffer encodeLdapResult( ByteBuffer buffer, InternalLdapResult ldapResult ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
+        }
+
+        try
+        {
+            // The result code
+            buffer.put( UniversalTag.ENUMERATED_TAG );
+            buffer.put( ( byte ) 1 );
+            buffer.put( ( byte ) ldapResult.getResultCode().getValue() );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
+        }
+
+        // The matchedDN
+        Value.encode( buffer, ldapResult.getMatchedDnBytes() );
+
+        // The error message
+        Value.encode( buffer, ldapResult.getErrorMessageBytes() );
+
+        // The referrals, if any
+        InternalReferral referral = ldapResult.getReferral();
+
+        if ( referral != null )
+        {
+            Collection<String> ldapUrls = referral.getLdapUrls();
+
+            if ( ( ldapUrls != null ) && ( ldapUrls.size() != 0 ) )
+            {
+                // Encode the referrals sequence
+                // The referrals length MUST have been computed before !
+                buffer.put( ( byte ) LdapConstants.LDAP_RESULT_REFERRAL_SEQUENCE_TAG );
+                //buffer.put( TLV.getBytes( referralsLength ) );
+
+                // Each referral
+                for ( String ldapUrl : ldapUrls )
+                {
+                    // Encode the current referral
+                    //Value.encode( buffer, referral.getBytesReference() );
+                }
+            }
+        }
+
+        return buffer;
+    }
+
+
+    /**
+     * Compute the BindResponse length 
+     * 
+     * BindResponse : 
+     * <pre>
+     * 0x61 L1 
+     *   | 
+     *   +--> LdapResult
+     *   +--> [serverSaslCreds] 
+     *   
+     * L1 = Length(LdapResult) [ + Length(serverSaslCreds) ] 
+     * Length(BindResponse) = Length(0x61) + Length(L1) + L1
+     * </pre>
+     */
+    private int computeBindResponseLength( BindResponseImpl bindResponse )
+    {
+        int ldapResultLength = computeLdapResultLength( bindResponse.getLdapResult() );
+
+        int bindResponseLength = ldapResultLength;
+
+        byte[] serverSaslCreds = bindResponse.getServerSaslCreds();
+
+        if ( serverSaslCreds != null )
+        {
+            bindResponseLength += 1 + TLV.getNbBytes( serverSaslCreds.length ) + serverSaslCreds.length;
+        }
+
+        bindResponse.setBindResponseLength( bindResponseLength );
+
+        return 1 + TLV.getNbBytes( bindResponseLength ) + bindResponseLength;
+    }
+
+
+    /**
+     * Encode the BindResponse message to a PDU.
+     * 
+     * BindResponse :
+     * <pre>
+     * LdapResult.encode 
+     * [0x87 LL serverSaslCreds]
+     * </pre>
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    private void encodeBindResponse( ByteBuffer bb, BindResponseImpl bindResponse ) throws EncoderException
+    {
+        try
+        {
+            // The BindResponse Tag
+            bb.put( LdapConstants.BIND_RESPONSE_TAG );
+            bb.put( TLV.getBytes( bindResponse.getBindResponseLength() ) );
+
+            // The LdapResult
+            encodeLdapResult( bb, bindResponse.getLdapResult() );
+
+            // The serverSaslCredential, if any
+            byte[] serverSaslCreds = bindResponse.getServerSaslCreds();
+
+            if ( serverSaslCreds != null )
+            {
+                bb.put( ( byte ) LdapConstants.SERVER_SASL_CREDENTIAL_TAG );
+
+                bb.put( TLV.getBytes( serverSaslCreds.length ) );
+
+                if ( serverSaslCreds.length != 0 )
+                {
+                    bb.put( serverSaslCreds );
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
+        }
+    }
+
+
+    /**
+     * Compute the BindRequest length 
+     * 
+     * BindRequest : 
+     * <pre>
+     * 0x60 L1 
+     *   | 
+     *   +--> 0x02 0x01 (1..127) version 
+     *   +--> 0x04 L2 name 
+     *   +--> authentication 
+     *   
+     * L2 = Length(name)
+     * L3/4 = Length(authentication) 
+     * Length(BindRequest) = Length(0x60) + Length(L1) + L1 + Length(0x02) + 1 + 1 + 
+     *      Length(0x04) + Length(L2) + L2 + Length(authentication)
+     * </pre>
+     */
+    private int computeProtocolOpLength( InternalMessage message )
+    {
+        switch ( message.getType() )
+        {
+            case BIND_RESPONSE:
+                return computeBindResponseLength( ( BindResponseImpl ) message );
+
+            default:
+                return 0;
+        }
+    }
+
+
+    private void encodeProtocolOp( ByteBuffer bb, InternalMessage message ) throws EncoderException
+    {
+        switch ( message.getType() )
+        {
+            case BIND_RESPONSE:
+                encodeBindResponse( bb, ( BindResponseImpl ) message );
+        }
+    }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java?rev=984452&r1=984451&r2=984452&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageContainer.java Wed Aug 11 15:52:58 2010
@@ -46,6 +46,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.InternalAbandonRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalAddRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalBindRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalBindResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
@@ -218,6 +219,15 @@ public class LdapMessageContainer extend
 
 
     /**
+     * @return Returns the BindResponse stored in the container
+     */
+    public InternalBindResponse getInternalBindResponse()
+    {
+        return ( InternalBindResponse ) internalMessage;
+    }
+
+
+    /**
      * @return Returns the CompareRequest stored in the container
      */
     public CompareRequestCodec getCompareRequest()

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java?rev=984452&r1=984451&r2=984452&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java Wed Aug 11 15:52:58 2010
@@ -71,7 +71,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.actions.StoreTypeMatchingRuleAction;
 import org.apache.directory.shared.ldap.codec.actions.ValueAction;
 import org.apache.directory.shared.ldap.codec.add.AddResponseCodec;
-import org.apache.directory.shared.ldap.codec.bind.BindResponseCodec;
 import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec;
 import org.apache.directory.shared.ldap.codec.controls.ControlEnum;
 import org.apache.directory.shared.ldap.codec.controls.ControlImpl;
@@ -110,6 +109,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.internal.InternalAbandonRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalAddRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalBindRequest;
+import org.apache.directory.shared.ldap.message.internal.InternalBindResponse;
 import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
@@ -825,9 +825,8 @@ public class LdapMessageGrammar extends 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
 
                     // Now, we can allocate the BindResponse Object
-                    BindResponseCodec bindResponse = new BindResponseCodec();
-                    bindResponse.setMessageId( ldapMessageContainer.getMessageId() );
-                    ldapMessageContainer.setLdapMessage( bindResponse );
+                    InternalBindResponse bindResponse = new BindResponseImpl( ldapMessageContainer.getMessageId() );
+                    ldapMessageContainer.setInternalMessage( bindResponse );
                 }
             } );
 

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java?rev=984452&r1=984451&r2=984452&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java Wed Aug 11 15:52:58 2010
@@ -55,29 +55,16 @@ public class LdapProtocolEncoder extends
      * Encode a Ldap request and write it to the remote server.
      * 
      * @param session The session containing the LdapMessageContainer
-     * @param request The LDAP message we have to encode to a Byte stream
+     * @param message The LDAP message we have to encode to a Byte stream
      * @param out The callback we have to invoke when the message has been encoded 
      */
-    public void encode( IoSession session, Object request, ProtocolEncoderOutput out ) throws Exception
+    public void encode( IoSession session, Object message, ProtocolEncoderOutput out ) throws Exception
     {
-        InternalMessage message = ( InternalMessage ) request;
-        ByteBuffer bb = null;
+        ByteBuffer buffer = encodeMessage( ( InternalMessage ) message );
 
-        if ( message instanceof InternalBindResponse )
-        {
-            bb = encodeMessage( message );
-        }
-        else
-        {
-            LdapMessageCodec ldapRequest = ( LdapMessageCodec ) LdapTransformer.transform( ( InternalMessage ) request );
-            bb = ldapRequest.encode();
-        }
-
-        bb.flip();
-
-        IoBuffer buffer = IoBuffer.wrap( bb );
+        IoBuffer ioBuffer = IoBuffer.wrap( buffer );
 
-        out.write( buffer );
+        out.write( ioBuffer );
     }
 
 
@@ -105,57 +92,67 @@ public class LdapProtocolEncoder extends
      * @return A ByteBuffer that contains the PDU
      * @throws EncoderException If anything goes wrong.
      */
-    private ByteBuffer encodeMessage( InternalMessage message ) throws EncoderException
+    public ByteBuffer encodeMessage( InternalMessage message ) throws EncoderException
     {
         int length = computeMessageLength( message );
+        ByteBuffer buffer = ByteBuffer.allocate( length );
 
-        try
+        if ( message instanceof InternalBindResponse )
         {
-            ByteBuffer buffer = ByteBuffer.allocate( length );
-
             try
             {
-                // The LdapMessage Sequence
-                buffer.put( UniversalTag.SEQUENCE_TAG );
-
-                // The length has been calculated by the computeLength method
-                buffer.put( TLV.getBytes( message.getMessageLength() ) );
-            }
-            catch ( BufferOverflowException boe )
-            {
-                throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
-            }
+                try
+                {
+                    // The LdapMessage Sequence
+                    buffer.put( UniversalTag.SEQUENCE_TAG );
 
-            // The message Id
-            Value.encode( buffer, message.getMessageId() );
+                    // The length has been calculated by the computeLength method
+                    buffer.put( TLV.getBytes( message.getMessageLength() ) );
+                }
+                catch ( BufferOverflowException boe )
+                {
+                    throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
+                }
 
-            // Add the protocolOp part
-            encodeProtocolOp( buffer, message );
+                // The message Id
+                Value.encode( buffer, message.getMessageId() );
 
-            // Do the same thing for Controls, if any.
-            Map<String, Control> controls = message.getControls();
+                // Add the protocolOp part
+                encodeProtocolOp( buffer, message );
 
-            if ( ( controls != null ) && ( controls.size() > 0 ) )
-            {
-                // Encode the controls
-                buffer.put( ( byte ) LdapConstants.CONTROLS_TAG );
-                buffer.put( TLV.getBytes( message.getControlsLength() ) );
+                // Do the same thing for Controls, if any.
+                Map<String, Control> controls = message.getControls();
 
-                // Encode each control
-                for ( Control control : controls.values() )
+                if ( ( controls != null ) && ( controls.size() > 0 ) )
                 {
-                    ( ( CodecControl ) control ).encode( buffer );
+                    // Encode the controls
+                    buffer.put( ( byte ) LdapConstants.CONTROLS_TAG );
+                    buffer.put( TLV.getBytes( message.getControlsLength() ) );
+
+                    // Encode each control
+                    for ( Control control : controls.values() )
+                    {
+                        ( ( CodecControl ) control ).encode( buffer );
+                    }
                 }
             }
+            catch ( EncoderException ee )
+            {
+                MessageEncoderException exception = new MessageEncoderException( message.getMessageId(), ee
+                    .getMessage() );
 
-            return buffer;
+                throw exception;
+            }
         }
-        catch ( EncoderException ee )
+        else
         {
-            MessageEncoderException exception = new MessageEncoderException( message.getMessageId(), ee.getMessage() );
-
-            throw exception;
+            LdapMessageCodec ldapRequest = ( LdapMessageCodec ) LdapTransformer.transform( message );
+            buffer = ldapRequest.encode();
         }
+
+        buffer.flip();
+
+        return buffer;
     }
 
 
@@ -181,7 +178,6 @@ public class LdapProtocolEncoder extends
 
         // Get the protocolOp length
         ldapMessageLength += computeProtocolOpLength( message );
-        message.setMessageLength( ldapMessageLength );
 
         Map<String, Control> controls = message.getControls();
 
@@ -223,6 +219,9 @@ public class LdapProtocolEncoder extends
             ldapMessageLength += 1 + TLV.getNbBytes( controlsSequenceLength ) + controlsSequenceLength;
         }
 
+        // Store the messageLength
+        message.setMessageLength( ldapMessageLength );
+
         // finally, calculate the global message size :
         // length(Tag) + Length(length) + length
 

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java?rev=984452&r1=984451&r2=984452&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapTransformer.java Wed Aug 11 15:52:58 2010
@@ -29,7 +29,6 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.codec.add.AddResponseCodec;
 import org.apache.directory.shared.ldap.codec.bind.BindRequestCodec;
-import org.apache.directory.shared.ldap.codec.bind.BindResponseCodec;
 import org.apache.directory.shared.ldap.codec.bind.SaslCredentials;
 import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication;
 import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec;
@@ -58,7 +57,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.Value;
-import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.filter.AndNode;
 import org.apache.directory.shared.ldap.filter.ApproximateNode;
 import org.apache.directory.shared.ldap.filter.BranchNode;
@@ -76,7 +74,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.AddResponseImpl;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.message.BindRequestImpl;
-import org.apache.directory.shared.ldap.message.BindResponseImpl;
 import org.apache.directory.shared.ldap.message.CompareResponseImpl;
 import org.apache.directory.shared.ldap.message.DeleteResponseImpl;
 import org.apache.directory.shared.ldap.message.ExtendedRequestImpl;
@@ -94,10 +91,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.SearchResponseReferenceImpl;
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.message.extended.GracefulShutdownRequest;
-import org.apache.directory.shared.ldap.message.internal.InternalLdapResult;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
 import org.apache.directory.shared.ldap.message.internal.InternalReferral;
-import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -120,66 +115,6 @@ public class LdapTransformer
 
 
     /**
-     * Transform a BindResponse message from a CodecMessage to a 
-     * InternalMessage.  This is used by clients which are receiving a 
-     * BindResponse PDU and must decode it to return the Internal 
-     * representation.
-     * 
-     * @param bindResponse The message to transform
-     * @param messageId The message Id
-     * @return a Internal BindResponseImpl
-     */
-    private static InternalMessage transformBindResponse( BindResponseCodec bindResponse, int messageId )
-    {
-        BindResponseImpl internalMessage = new BindResponseImpl( messageId );
-
-        // Codec : byte[] serverSaslcreds -> Internal : byte[] serverSaslCreds
-        internalMessage.setServerSaslCreds( bindResponse.getServerSaslCreds() );
-        //transformControlsCodecToInternal( codecMessage, internalMessage );
-        transformLdapResultCodecToInternal( bindResponse.getLdapResult(), internalMessage.getLdapResult() );
-
-        return internalMessage;
-    }
-
-
-    /**
-     * Transforms parameters of a Codec LdapResult into a Internal LdapResult.
-     *
-     * @param codecLdapResult the codec LdapResult representation
-     * @param InternalResult the Internal LdapResult representation
-     */
-    private static void transformLdapResultCodecToInternal( LdapResultCodec codecLdapResult,
-        InternalLdapResult internalLdapResult )
-    {
-        internalLdapResult.setErrorMessage( codecLdapResult.getErrorMessage() );
-
-        try
-        {
-            internalLdapResult.setMatchedDn( new DN( codecLdapResult.getMatchedDN() ) );
-        }
-        catch ( LdapInvalidDnException e )
-        {
-            LOG.error( I18n.err( I18n.ERR_04111, codecLdapResult.getMatchedDN() ) );
-            internalLdapResult.setMatchedDn( new DN() );
-        }
-
-        internalLdapResult.setResultCode( codecLdapResult.getResultCode() );
-
-        if ( codecLdapResult.getReferrals() != null )
-        {
-            ReferralImpl referral = new ReferralImpl();
-
-            for ( LdapURL url : codecLdapResult.getReferrals() )
-            {
-                referral.addLdapUrl( url.toString() );
-            }
-
-            internalLdapResult.setReferral( referral );
-        }
-    }
-
-
-    /**
      * Transform an ExtendedRequest message from a CodecMessage to a
      * InternalMessage
      * 
@@ -635,6 +570,11 @@ public class LdapTransformer
      */
     public static InternalMessage transform( Object obj )
     {
+        if ( obj instanceof InternalMessage )
+        {
+            return ( InternalMessage ) obj;
+        }
+
         LdapMessageCodec codecMessage = ( LdapMessageCodec ) obj;
         int messageId = codecMessage.getMessageId();
 
@@ -666,10 +606,6 @@ public class LdapTransformer
                 internalMessage = transformExtendedRequest( ( ExtendedRequestCodec ) codecMessage, messageId );
                 break;
 
-            case BIND_RESPONSE:
-                internalMessage = transformBindResponse( ( BindResponseCodec ) codecMessage, messageId );
-                break;
-
             case SEARCH_RESULT_ENTRY:
             case SEARCH_RESULT_DONE:
             case SEARCH_RESULT_REFERENCE:
@@ -761,35 +697,6 @@ public class LdapTransformer
 
 
     /**
-     * Transform a Internal BindResponse to a Codec BindResponse
-     * 
-     * @param internalMessage The incoming Internal BindResponse
-     * @return The BindResponseCodec instance
-     */
-    private static LdapMessageCodec transformBindResponse( InternalMessage internalMessage )
-    {
-        BindResponseImpl internalBindResponse = ( BindResponseImpl ) internalMessage;
-
-        BindResponseCodec bindResponseCodec = new BindResponseCodec();
-
-        // Internal : byte [] serverSaslCreds -> Codec : OctetString
-        // serverSaslCreds
-        byte[] serverSaslCreds = internalBindResponse.getServerSaslCreds();
-
-        if ( serverSaslCreds != null )
-        {
-            bindResponseCodec.setServerSaslCreds( serverSaslCreds );
-        }
-
-        // Transform the ldapResult
-        bindResponseCodec
-            .setLdapResult( transformLdapResult( ( LdapResultImpl ) internalBindResponse.getLdapResult() ) );
-
-        return bindResponseCodec;
-    }
-
-
-    /**
      * Transform a Internal BindRequest to a Codec BindRequest
      * 
      * @param internalMessage The incoming Internal BindRequest
@@ -1078,10 +985,6 @@ public class LdapTransformer
                 codecMessage = transformSearchResultReference( msg );
                 break;
 
-            case BIND_RESPONSE:
-                codecMessage = transformBindResponse( msg );
-                break;
-
             case BIND_REQUEST:
                 codecMessage = transformBindRequest( msg );
                 break;

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ErrorMessageAction.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ErrorMessageAction.java?rev=984452&r1=984451&r2=984452&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ErrorMessageAction.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ErrorMessageAction.java Wed Aug 11 15:52:58 2010
@@ -27,6 +27,8 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.LdapResponseCodec;
 import org.apache.directory.shared.ldap.codec.LdapResultCodec;
+import org.apache.directory.shared.ldap.message.internal.InternalLdapResult;
+import org.apache.directory.shared.ldap.message.internal.InternalResultResponse;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -45,32 +47,46 @@ public class ErrorMessageAction extends 
     /** Speedup for logs */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
 
+
     public ErrorMessageAction()
     {
         super( "Store error message" );
     }
 
+
     /**
      * The initialization action
      */
     public void action( IAsn1Container container ) throws DecoderException
     {
         LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
-        LdapResponseCodec response = ldapMessageContainer.getLdapResponse();
-        LdapResultCodec ldapResult = response.getLdapResult();
 
         // Get the Value and store it in the BindResponse
         TLV tlv = ldapMessageContainer.getCurrentTLV();
+        String errorMessage = null;
 
         // We have to handle the special case of a 0 length error
         // message
         if ( tlv.getLength() == 0 )
         {
-            ldapResult.setErrorMessage( "" );
+            errorMessage = "";
+        }
+        else
+        {
+            errorMessage = StringTools.utf8ToString( tlv.getValue().getData() );
+        }
+
+        if ( ldapMessageContainer.isInternal() )
+        {
+            InternalResultResponse response = ( InternalResultResponse ) ldapMessageContainer.getInternalMessage();
+            InternalLdapResult ldapResult = response.getLdapResult();
+            ldapResult.setErrorMessage( errorMessage );
         }
         else
         {
-            ldapResult.setErrorMessage( StringTools.utf8ToString( tlv.getValue().getData() ) );
+            LdapResponseCodec response = ldapMessageContainer.getLdapResponse();
+            LdapResultCodec ldapResult = response.getLdapResult();
+            ldapResult.setErrorMessage( errorMessage );
         }
 
         // We can have an END transition
@@ -78,7 +94,7 @@ public class ErrorMessageAction extends 
 
         if ( IS_DEBUG )
         {
-            log.debug( "The error message is : " + ldapResult.getErrorMessage() );
+            log.debug( "The error message is : " + errorMessage );
         }
     }
 }



Mime
View raw message