directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r984452 [2/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
Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.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/MatchedDNAction.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java
Wed Aug 11 15:52:58 2010
@@ -30,6 +30,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.LdapResultCodec;
 import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.message.internal.InternalLdapResult;
+import org.apache.directory.shared.ldap.message.internal.InternalResultResponse;
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -49,72 +51,100 @@ public class MatchedDNAction extends Gra
     /** Speedup for logs */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
 
+
     public MatchedDNAction()
     {
         super( "Store matched DN" );
     }
 
+
     /**
      * 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();
+        DN matchedDN = null;
+        ResultCodeEnum resultCode = null;
+
+        if ( ldapMessageContainer.isInternal() )
+        {
+            InternalResultResponse response = ( InternalResultResponse ) ldapMessageContainer.getInternalMessage();
+            InternalLdapResult ldapResult = response.getLdapResult();
+            resultCode = ldapResult.getResultCode();
+        }
+        else
+        {
+            LdapResponseCodec response = ldapMessageContainer.getLdapResponse();
+            LdapResultCodec ldapResult = response.getLdapResult();
+            resultCode = ldapResult.getResultCode();
+        }
 
         // We have to handle the special case of a 0 length matched
         // DN
         if ( tlv.getLength() == 0 )
         {
-            ldapResult.setMatchedDN( DN.EMPTY_DN );
+            matchedDN = DN.EMPTY_DN;
         }
         else
         {
             // A not null matchedDN is valid for resultCodes
             // NoSuchObject, AliasProblem, InvalidDNSyntax and
             // AliasDreferencingProblem.
-            ResultCodeEnum resultCode = ldapResult.getResultCode();
 
             switch ( resultCode )
             {
-                case NO_SUCH_OBJECT :
-                case ALIAS_PROBLEM :
-                case INVALID_DN_SYNTAX :
-                case ALIAS_DEREFERENCING_PROBLEM :
+                case NO_SUCH_OBJECT:
+                case ALIAS_PROBLEM:
+                case INVALID_DN_SYNTAX:
+                case ALIAS_DEREFERENCING_PROBLEM:
                     byte[] dnBytes = tlv.getValue().getData();
                     String dnStr = StringTools.utf8ToString( dnBytes );
-                    
+
                     try
                     {
-                        ldapResult.setMatchedDN( new DN( dnStr ) );
+                        matchedDN = new DN( dnStr );
                     }
                     catch ( LdapInvalidDnException ine )
                     {
                         // This is for the client side. We will never decode LdapResult on
the server
-                        String msg = I18n.err( I18n.ERR_04013, dnStr, StringTools.dumpBytes(
dnBytes ), ine.getLocalizedMessage() );
+                        String msg = I18n.err( I18n.ERR_04013, dnStr, StringTools.dumpBytes(
dnBytes ), ine
+                            .getLocalizedMessage() );
                         log.error( msg );
-                    
+
                         throw new DecoderException( I18n.err( I18n.ERR_04014, ine.getLocalizedMessage()
) );
                     }
-                    
+
                     break;
-                    
-                default :
-                    log.warn( "The matched DN should not be set when the result code is one
of NoSuchObject," + 
-                        " AliasProblem, InvalidDNSyntax or AliasDreferencingProblem" );
 
-                    ldapResult.setMatchedDN( DN.EMPTY_DN );
+                default:
+                    log.warn( "The matched DN should not be set when the result code is one
of NoSuchObject,"
+                        + " AliasProblem, InvalidDNSyntax or AliasDreferencingProblem" );
+
+                    matchedDN = DN.EMPTY_DN;
                     break;
             }
         }
 
         if ( IS_DEBUG )
         {
-            log.debug( "The matchedDN is " + ldapResult.getMatchedDN() );
+            log.debug( "The matchedDN is " + matchedDN );
+        }
+
+        if ( ldapMessageContainer.isInternal() )
+        {
+            InternalResultResponse response = ( InternalResultResponse ) ldapMessageContainer.getInternalMessage();
+            InternalLdapResult ldapResult = response.getLdapResult();
+            ldapResult.setMatchedDn( matchedDN );
+        }
+        else
+        {
+            LdapResponseCodec response = ldapMessageContainer.getLdapResponse();
+            LdapResultCodec ldapResult = response.getLdapResult();
+            ldapResult.setMatchedDN( matchedDN );
         }
     }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ResultCodeAction.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ResultCodeAction.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/ResultCodeAction.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ResultCodeAction.java
Wed Aug 11 15:52:58 2010
@@ -32,6 +32,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.LdapResponseCodec;
 import org.apache.directory.shared.ldap.codec.LdapResultCodec;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+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;
@@ -50,22 +52,19 @@ public class ResultCodeAction extends Gr
     /** Speedup for logs */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
 
+
     public ResultCodeAction()
     {
         super( "Store resultCode" );
     }
 
+
     /**
      * The initialization action
      */
     public void action( IAsn1Container container ) throws DecoderException
     {
         LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
-        LdapResponseCodec response = ldapMessageContainer.getLdapResponse();
-        LdapResultCodec ldapResult = new LdapResultCodec();
-        response.setLdapResult( ldapResult );
-
-        // We don't have to allocate a LdapResult first.
 
         // The current TLV should be a integer
         // We get it and store it in MessageId
@@ -76,7 +75,8 @@ public class ResultCodeAction extends Gr
 
         try
         {
-            resultCode = ResultCodeEnum.getResultCode( IntegerDecoder.parse( value, 0, ResultCodeEnum.UNKNOWN.getResultCode()
) );
+            resultCode = ResultCodeEnum.getResultCode( IntegerDecoder.parse( value, 0, ResultCodeEnum.UNKNOWN
+                .getResultCode() ) );
         }
         catch ( IntegerDecoderException ide )
         {
@@ -129,12 +129,11 @@ public class ResultCodeAction extends Gr
             case CANNOT_CANCEL:
             case TOO_LATE:
             case NO_SUCH_OPERATION:
-                ldapResult.setResultCode( resultCode );
                 break;
 
             default:
                 log.warn( "The resultCode " + resultCode + " is unknown." );
-                ldapResult.setResultCode( ResultCodeEnum.OTHER );
+                resultCode = ResultCodeEnum.OTHER;
                 break;
         }
 
@@ -142,5 +141,19 @@ public class ResultCodeAction extends Gr
         {
             log.debug( "The result code is set to " + resultCode );
         }
+
+        if ( ldapMessageContainer.isInternal() )
+        {
+            InternalResultResponse response = ( InternalResultResponse ) ldapMessageContainer.getInternalMessage();
+            InternalLdapResult ldapResult = response.getLdapResult();
+            ldapResult.setResultCode( resultCode );
+        }
+        else
+        {
+            LdapResponseCodec response = ldapMessageContainer.getLdapResponse();
+            LdapResultCodec ldapResult = new LdapResultCodec();
+            ldapResult.setResultCode( resultCode );
+            response.setLdapResult( ldapResult );
+        }
     }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ServerSASLCredsAction.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ServerSASLCredsAction.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/ServerSASLCredsAction.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ServerSASLCredsAction.java
Wed Aug 11 15:52:58 2010
@@ -26,6 +26,7 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.bind.BindResponseCodec;
+import org.apache.directory.shared.ldap.message.internal.InternalBindResponse;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -44,11 +45,13 @@ public class ServerSASLCredsAction exten
     /** Speedup for logs */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
 
+
     public ServerSASLCredsAction()
     {
         super( "Store server sasl credentials value" );
     }
 
+
     /**
      * The initialization action
      */
@@ -56,20 +59,31 @@ public class ServerSASLCredsAction exten
     {
         LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
 
-        BindResponseCodec bindResponseMessage = ldapMessageContainer.getBindResponse();
-
         // Get the Value and store it in the BindRequest
         TLV tlv = ldapMessageContainer.getCurrentTLV();
 
         // We have to handle the special case of a 0 length server
         // sasl credentials
+        byte[] serverSaslCreds = null;
+
         if ( tlv.getLength() == 0 )
         {
-            bindResponseMessage.setServerSaslCreds( StringTools.EMPTY_BYTES );
+            serverSaslCreds = StringTools.EMPTY_BYTES;
+        }
+        else
+        {
+            serverSaslCreds = tlv.getValue().getData();
+        }
+
+        if ( ldapMessageContainer.isInternal() )
+        {
+            InternalBindResponse response = ( InternalBindResponse ) ldapMessageContainer.getInternalMessage();
+            response.setServerSaslCreds( serverSaslCreds );
         }
         else
         {
-            bindResponseMessage.setServerSaslCreds( tlv.getValue().getData() );
+            BindResponseCodec bindResponseMessage = ldapMessageContainer.getBindResponse();
+            bindResponseMessage.setServerSaslCreds( serverSaslCreds );
         }
 
         // We can have an END transition
@@ -77,7 +91,7 @@ public class ServerSASLCredsAction exten
 
         if ( IS_DEBUG )
         {
-            log.debug( "The SASL credentials value is : {}", StringTools.dumpBytes( bindResponseMessage.getServerSaslCreds()
) );
+            log.debug( "The SASL credentials value is : {}", StringTools.dumpBytes( serverSaslCreds
) );
         }
     }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindResponseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindResponseTest.java?rev=984452&r1=984451&r2=984452&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindResponseTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindResponseTest.java
Wed Aug 11 15:52:58 2010
@@ -26,7 +26,7 @@ import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
 import java.util.Arrays;
-import java.util.List;
+import java.util.Map;
 
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -35,9 +35,11 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.codec.LdapProtocolEncoder;
 import org.apache.directory.shared.ldap.codec.search.controls.pagedSearch.PagedResultsControl;
 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.util.StringTools;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -50,6 +52,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class BindResponseTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a BindResponse
      */
@@ -94,20 +100,20 @@ public class BindResponseTest
         }
 
         // Check the decoded BindResponse
-        BindResponseCodec bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer
).getBindResponse();
+        InternalBindResponse bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer
).getInternalBindResponse();
 
         assertEquals( 1, bindResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode()
);
-        assertEquals( "", bindResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", bindResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", bindResponse.getLdapResult().getErrorMessage() );
 
-        // Check the length
-        assertEquals( 0x0E, bindResponse.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+
+            // Check the length
+            assertEquals( 0x0E, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -132,32 +138,38 @@ public class BindResponseTest
         ByteBuffer stream = ByteBuffer.allocate( 0x3C );
 
         stream.put( new byte[]
-            { 
-              0x30, 0x3A,                      // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01,              // messageID MessageID
-                0x61, 0x07,                    // CHOICE { ..., bindResponse BindResponse,
...
-                                               // BindResponse ::= APPLICATION[1] SEQUENCE
{
-                                               // COMPONENTS OF LDAPResult,
-                  0x0A, 0x01, 0x00,            // LDAPResult ::= SEQUENCE {
-                                               // resultCode ENUMERATED {
-                                               // success (0), ...
-                                               // },
-                  0x04, 0x00,                  // matchedDN LDAPDN,
-                  0x04, 0x00,                  // errorMessage LDAPString,
-                                               // referral [3] Referral OPTIONAL }
-                                               // serverSaslCreds [7] OCTET STRING OPTIONAL
}
-                  ( byte ) 0xa0, 0x2C,         // controls
-                    0x30, 0x2A,                // The PagedSearchControl
-                      0x04, 0x16,              // Oid : 1.2.840.113556.1.4.319
-                        0x31, 0x2e, 0x32, 0x2e, 0x38, 0x34, 0x30, 0x2e, 
-                        0x31, 0x31, 0x33, 0x35, 0x35, 0x36, 0x2e, 0x31, 
-                        0x2e, 0x34, 0x2e, 0x33, 0x31, 0x39, // control
-                    0x01, 0x01, ( byte ) 0xff, // criticality: false
-                    0x04, 0x0D,
-                      0x30, 0x0B,
-                        0x02, 0x01, 0x05,      // Size = 5, cookie = "abcdef" 
-                        0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f'
-              } );
+            { 0x30,
+                0x3A, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x61,
+                0x07, // CHOICE { ..., bindResponse BindResponse, ...
+                // BindResponse ::= APPLICATION[1] SEQUENCE {
+                // COMPONENTS OF LDAPResult,
+                0x0A,
+                0x01,
+                0x00, // LDAPResult ::= SEQUENCE {
+                // resultCode ENUMERATED {
+                // success (0), ...
+                // },
+                0x04,
+                0x00, // matchedDN LDAPDN,
+                0x04,
+                0x00, // errorMessage LDAPString,
+                // referral [3] Referral OPTIONAL }
+                // serverSaslCreds [7] OCTET STRING OPTIONAL }
+                ( byte ) 0xa0,
+                0x2C, // controls
+                0x30,
+                0x2A, // The PagedSearchControl
+                0x04,
+                0x16, // Oid : 1.2.840.113556.1.4.319
+                0x31, 0x2e, 0x32, 0x2e, 0x38, 0x34, 0x30, 0x2e, 0x31, 0x31, 0x33, 0x35, 0x35,
0x36, 0x2e, 0x31, 0x2e,
+                0x34, 0x2e, 0x33, 0x31, 0x39, // control
+                0x01, 0x01, ( byte ) 0xff, // criticality: false
+                0x04, 0x0D, 0x30, 0x0B, 0x02, 0x01, 0x05, // Size = 5, cookie = "abcdef"

+                0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -177,34 +189,34 @@ public class BindResponseTest
         }
 
         // Check the decoded BindResponse
-        BindResponseCodec bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer
).getBindResponse();
+        InternalBindResponse bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer
).getInternalBindResponse();
 
         assertEquals( 1, bindResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode()
);
-        assertEquals( "", bindResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", bindResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", bindResponse.getLdapResult().getErrorMessage() );
 
-        // Check the length
-        assertEquals( 0x3C, bindResponse.computeLength() );
-
         // Check the Control
-        List<Control> controls = bindResponse.getControls();
+        Map<String, Control> controls = bindResponse.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = bindResponse.getControls( 0 );
+        Control control = controls.get( "1.2.840.113556.1.4.319" );
         assertEquals( "1.2.840.113556.1.4.319", control.getOid() );
         assertTrue( control instanceof PagedResultsControl );
-        
-        PagedResultsControl pagedSearchControl = (PagedResultsControl)control;
-        
+
+        PagedResultsControl pagedSearchControl = ( PagedResultsControl ) control;
+
         assertEquals( 5, pagedSearchControl.getSize() );
         assertTrue( Arrays.equals( "abcdef".getBytes(), pagedSearchControl.getCookie() )
);
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+
+            // Check the length
+            assertEquals( 0x3C, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -242,7 +254,7 @@ public class BindResponseTest
                 0x04, 0x00, // errorMessage LDAPString,
                 // referral [3] Referral OPTIONAL }
                 ( byte ) 0x87, 0x00 // serverSaslCreds [7] OCTET STRING OPTIONAL
-                                    // }
+            // }
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -263,21 +275,21 @@ public class BindResponseTest
         }
 
         // Check the decoded BindResponse
-        BindResponseCodec bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer
).getBindResponse();
+        InternalBindResponse bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer
).getInternalBindResponse();
 
         assertEquals( 1, bindResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode()
);
-        assertEquals( "", bindResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", bindResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", bindResponse.getLdapResult().getErrorMessage() );
         assertEquals( "", StringTools.utf8ToString( bindResponse.getServerSaslCreds() ) );
 
-        // Check the length
-        assertEquals( 0x10, bindResponse.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+
+            // Check the length
+            assertEquals( 0x10, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -303,21 +315,31 @@ public class BindResponseTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2D );
 
         stream.put( new byte[]
-            { 0x30, 0x2B, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x61, 0x09, // CHOICE { ..., bindResponse BindResponse, ...
+            { 0x30,
+                0x2B, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x61,
+                0x09, // CHOICE { ..., bindResponse BindResponse, ...
                 // BindResponse ::= APPLICATION[1] SEQUENCE {
                 // COMPONENTS OF LDAPResult,
-                0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+                0x0A,
+                0x01,
+                0x00, // LDAPResult ::= SEQUENCE {
                 // resultCode ENUMERATED {
                 // success (0), ...
                 // },
-                0x04, 0x00, // matchedDN LDAPDN,
-                0x04, 0x00, // errorMessage LDAPString,
+                0x04,
+                0x00, // matchedDN LDAPDN,
+                0x04,
+                0x00, // errorMessage LDAPString,
                 // referral [3] Referral OPTIONAL }
-                ( byte ) 0x87, 0x00, // serverSaslCreds [7] OCTET STRING
-                                        // OPTIONAL }
-                ( byte ) 0xA0, 0x1B, // A control
+                ( byte ) 0x87,
+                0x00, // serverSaslCreds [7] OCTET STRING
+                // OPTIONAL }
+                ( byte ) 0xA0,
+                0x1B, // A control
                 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E,
0x31, 0x2E, 0x31, 0x31,
                 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
 
@@ -339,30 +361,30 @@ public class BindResponseTest
         }
 
         // Check the decoded BindResponse
-        BindResponseCodec bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer
).getBindResponse();
+        InternalBindResponse bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer
).getInternalBindResponse();
 
         assertEquals( 1, bindResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode()
);
-        assertEquals( "", bindResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", bindResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", bindResponse.getLdapResult().getErrorMessage() );
         assertEquals( "", StringTools.utf8ToString( bindResponse.getServerSaslCreds() ) );
 
         // Check the Control
-        List<Control> controls = bindResponse.getControls();
+        Map<String, Control> controls = bindResponse.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = bindResponse.getControls( 0 );
+        Control control = controls.get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
         assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
 
-        // Check the length
-        assertEquals( 0x2D, bindResponse.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+
+            // Check the length
+            assertEquals( 0x2D, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -400,7 +422,7 @@ public class BindResponseTest
                 0x04, 0x00, // errorMessage LDAPString,
                 // referral [3] Referral OPTIONAL }
                 ( byte ) 0x87, 0x02, 'A', 'B' // serverSaslCreds [7] OCTET
-                                                // STRING OPTIONAL }
+            // STRING OPTIONAL }
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -421,21 +443,21 @@ public class BindResponseTest
         }
 
         // Check the decoded BindResponse
-        BindResponseCodec bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer
).getBindResponse();
+        InternalBindResponse bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer
).getInternalBindResponse();
 
         assertEquals( 1, bindResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode()
);
-        assertEquals( "", bindResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", bindResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", bindResponse.getLdapResult().getErrorMessage() );
         assertEquals( "AB", StringTools.utf8ToString( bindResponse.getServerSaslCreds() )
);
 
-        // Check the length
-        assertEquals( 0x12, bindResponse.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+
+            // Check the length
+            assertEquals( 0x12, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 



Mime
View raw message