directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r226689 - in /directory/sandbox/trunk/asn1-new-codec/src: java/org/apache/asn1/ldap/codec/ java/org/apache/asn1/ldap/codec/grammars/ java/org/apache/asn1/ldap/pojo/ test/org/apache/asn1/ldap/codec/
Date Sun, 31 Jul 2005 20:14:32 GMT
Author: elecharny
Date: Sun Jul 31 13:14:24 2005
New Revision: 226689

URL: http://svn.apache.org/viewcvs?rev=226689&view=rev
Log:
Added the encoding of the searchResultEntry message

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultEntryGrammar.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultEntry.java
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultEntryTest.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java?rev=226689&r1=226688&r2=226689&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
Sun Jul 31 13:14:24 2005
@@ -56,6 +56,7 @@
     public static final byte ABANDON_REQUEST_TAG = 0x50;
     public static final byte BIND_REQUEST_TAG = 0x60;
     public static final byte BIND_RESPONSE_TAG = 0x61;
+    public static final byte SEARCH_RESULT_ENTRY_TAG = 0x64;
     public static final byte SEARCH_RESULT_DONE_TAG = 0x65;
     public static final byte MODIFY_RESPONSE_TAG = 0x67;
     public static final byte ADD_RESPONSE_TAG = 0x69;

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultEntryGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultEntryGrammar.java?rev=226689&r1=226688&r2=226689&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultEntryGrammar.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultEntryGrammar.java
Sun Jul 31 13:14:24 2005
@@ -23,6 +23,7 @@
 import org.apache.asn1.ber.grammar.GrammarTransition;
 import org.apache.asn1.ber.grammar.IGrammar;
 import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.LdapMessageContainer;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
@@ -79,14 +80,14 @@
         // LdapMessage ::= ... SearchResultEntry ...
         // SearchResultEntry ::= [APPLICATION 4] SEQUENCE { (Tag)
         // Nothing to do.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_TAG][0x64] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_TAG][LdapConstants.SEARCH_RESULT_ENTRY_TAG]
= new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_TAG, LdapStatesEnum.SEARCH_RESULT_ENTRY_VALUE,
                 null );
 
         // LdapMessage ::= ... SearchResultEntry ...
         // SearchResultEntry ::= [APPLICATION 4] SEQUENCE { (Value)
         // Nothing to do.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_VALUE][0x64] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_VALUE][LdapConstants.SEARCH_RESULT_ENTRY_TAG]
= new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_VALUE,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG,
                 new GrammarAction( "Init SearchResultEntry" )
@@ -110,7 +111,7 @@
         //    objectName      LDAPDN, (Tag)
         //    ...
         // Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG][0x04] =
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_VALUE, null );
@@ -120,7 +121,7 @@
         //    objectName      LDAPDN, (Value)
         //    ...
         // Store the object name.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_VALUE][0x04] =
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_VALUE][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_VALUE,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG,
@@ -157,7 +158,7 @@
         // PartialAttributeList ::= *SEQUENCE* OF SEQUENCE { (Tag)
         //    ...
         // Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG][0x30] =
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG][LdapConstants.SEQUENCE_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE, null );
@@ -167,7 +168,7 @@
         // PartialAttributeList ::= *SEQUENCE* OF SEQUENCE { (Tag)
         //    ...
         // We may have many attributes. Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE][0x30] =
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE][LdapConstants.SEQUENCE_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_TAG, null );
@@ -175,7 +176,7 @@
         // PartialAttributeList ::= SEQUENCE OF *SEQUENCE* { (Tag)
         //    ...
         // Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_TAG][0x30]
=
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_TAG][LdapConstants.SEQUENCE_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_TAG,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE, null );
@@ -185,7 +186,7 @@
         // PartialAttributeList ::= SEQUENCE OF *SEQUENCE* { (Tag)
         //    ...
         // Loop.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG][0x30]
=
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG][LdapConstants.SEQUENCE_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE, null );
@@ -193,7 +194,7 @@
         // PartialAttributeList ::= SEQUENCE OF *SEQUENCE* { (Value)
         //    ...
         // We may have many attributes. We also have to store a previously decoded AttributeValue
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE][0x30]
=
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE][LdapConstants.SEQUENCE_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_TAG,
@@ -217,7 +218,7 @@
         //    type    AttributeDescription, (Tag)
         //    ...
         // Nothing to do.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_TAG][0x04] =
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_TAG][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_TAG,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_VALUE, null );
@@ -226,7 +227,7 @@
         //    type    AttributeDescription, (Value)
         //    ...
         // Store the attribute's name.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_VALUE][0x04] =
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_VALUE][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_VALUE,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_TAG,
@@ -262,7 +263,7 @@
         //    ...
         //    vals    *SET OF* AttributeValue} (Tag)
         // Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_TAG][0x31] =
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_TAG][LdapConstants.SET_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_TAG,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_VALUE, null );
@@ -271,7 +272,7 @@
         //    ...
         //    vals    *SET OF* AttributeValue} (Value)
         // We may have many values. Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_VALUE][0x31] =
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_VALUE][LdapConstants.SET_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_VALUE,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_TAG, null );
@@ -280,7 +281,7 @@
         //    ...
         //    vals    SET OF *AttributeValue*} (Tag)
         // Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_TAG][0x04] =
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_TAG][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_TAG,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE, null );
@@ -289,7 +290,7 @@
         //    ...
         //    vals    SET OF *AttributeValue*} (Tag)
         // The loop.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG][0x04]
=
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE, null );
@@ -298,7 +299,7 @@
         //    ...
         //    vals    SET OF *AttributeValue*} (Value)
         // We may have many values. Store the current one in the current Attribute Value
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE][0x04]
=
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE,
                 LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG,

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultEntry.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultEntry.java?rev=226689&r1=226688&r2=226689&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultEntry.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultEntry.java
Sun Jul 31 13:14:24 2005
@@ -17,13 +17,20 @@
 package org.apache.asn1.ldap.pojo;
 
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
 import org.apache.asn1.primitives.OctetString;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
@@ -66,6 +73,18 @@
 
     /** The current attribute being decoded */
     private transient Attribute currentAttributeValue;
+    
+    /** The search result entry length */
+    private transient int searchResultEntryLength;
+    
+    /** The partial attributes length */
+    private transient int attributesLength;
+    
+    /** The list of all attributes length */
+    private transient List attributeLength;
+    
+    /** The list of all vals length */
+    private transient List valsLength;
 
     //~ Constructors -------------------------------------------------------------------------------
 
@@ -205,27 +224,30 @@
      */
     public int computeLength()
     {
-        int searchResultEntryLength = 0;
+        searchResultEntryLength = 0;
         
         // The entry
-        searchResultEntryLength += 1 + Length.getNbBytes( objectName.getLength() ) + objectName.getLength();
+        searchResultEntryLength = 1 + Length.getNbBytes( objectName.getLength() ) + objectName.getLength();
         
         // The attributes sequence
-        int attributesLength = 0;
+        attributesLength = 0;
         
         if ( ( partialAttributeList != null ) && ( partialAttributeList.size() !=
0 ) )
         {
             Iterator attributeIterator = partialAttributeList.iterator();
+            attributeLength = new LinkedList();
+            valsLength = new LinkedList();
             
             // Compute the attributes length
             while ( attributeIterator.hasNext() )
             {
                 Attribute attribute = (Attribute)attributeIterator.next();
-                int attributeLength = 0;
+                int localAttributeLength = 0;
+                int localValuesLength = 0;
                 
                 // Get the type length
                 int idLength = attribute.getID().getBytes().length;
-                attributeLength = 1 + Length.getNbBytes( idLength ) + idLength;
+                localAttributeLength = 1 + Length.getNbBytes( idLength ) + idLength;
                 
                 // The values
                 try
@@ -234,16 +256,16 @@
 	                
 	                if ( values.hasMoreElements() )
 	                {
-	                    int valuesLength = 0;
+                        localValuesLength = 0;
 	                    
 		                while ( values.hasMoreElements() )
 		                {
 		                    OctetString value = (OctetString)values.next();
 		                    
-		                    valuesLength += 1 + Length.getNbBytes( value.getLength() ) + value.getLength();
+                            localValuesLength += 1 + Length.getNbBytes( value.getLength()
) + value.getLength();
 		                }
 
-	                    attributeLength += 1 + Length.getNbBytes( valuesLength ) + valuesLength;

+                        localAttributeLength += 1 + Length.getNbBytes( localValuesLength
) + localValuesLength; 
 	                }
 	                
                 }
@@ -253,7 +275,10 @@
                 }
                 
                 // add the attribute length to the attributes length
-                attributesLength += 1 + Length.getNbBytes( attributeLength ) + attributeLength;
+                attributesLength += 1 + Length.getNbBytes( localAttributeLength ) + localAttributeLength;
+                
+                attributeLength.add( new Integer( localAttributeLength ) );
+                valsLength.add( new Integer( localValuesLength ) );
             }
         }
         
@@ -264,6 +289,108 @@
     }
     
     /**
+     * Encode the SearchResultEntry message to a PDU.
+     * 
+     * SearchResultEntry :
+     * 
+     * 0x64 LL
+     *   0x04 LL objectName
+     *   0x30 LL attributes
+     *     0x30 LL partialAttributeList
+     *       0x04 LL type
+     *       0x31 LL vals
+     *         0x04 LL attributeValue
+     *         ... 
+     *         0x04 LL attributeValue
+     *     ... 
+     *     0x30 LL partialAttributeList
+     *       0x04 LL type
+     *       0x31 LL vals
+     *         0x04 LL attributeValue
+     *         ... 
+     *         0x04 LL attributeValue 
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            // The SearchResultEntry Tag
+            buffer.put( LdapConstants.SEARCH_RESULT_ENTRY_TAG );
+            buffer.put( Length.getBytes( searchResultEntryLength ) ) ;
+            
+            // The objectName
+            Value.encode( buffer, objectName );
+            
+            // The attributes sequence
+            buffer.put( LdapConstants.SEQUENCE_TAG );
+            buffer.put( Length.getBytes( attributesLength ) ) ;
+
+            // The partial attribute list
+            if ( ( partialAttributeList != null ) && ( partialAttributeList.size()
!= 0 ) )
+            {
+                Iterator attributeIterator = partialAttributeList.iterator();
+                int attributeNumber = 0;
+                
+                // Compute the attributes length
+                while ( attributeIterator.hasNext() )
+                {
+                    Attribute attribute = (Attribute)attributeIterator.next();
+                    
+                    // The partial attribute list sequence
+                    buffer.put( LdapConstants.SEQUENCE_TAG );
+                    int localAttributeLength = ( (Integer)attributeLength.get( attributeNumber
) ).intValue();
+                    buffer.put( Length.getBytes( localAttributeLength ) );
+
+                    // The attribute type
+                    Value.encode( buffer, attribute.getID() );
+                    
+                    // The values
+                    buffer.put( LdapConstants.SET_TAG );
+                    int localValuesLength = ( (Integer)valsLength.get( attributeNumber )
).intValue();
+                    buffer.put( Length.getBytes( localValuesLength ) );
+                    
+                    try
+                    {
+                        NamingEnumeration values = attribute.getAll();
+                        
+                        if ( values.hasMoreElements() )
+                        {
+                            while ( values.hasMoreElements() )
+                            {
+                                OctetString value = (OctetString)values.next();
+                                
+                                Value.encode( buffer, value );
+                            }
+                        }
+                        
+                    }
+                    catch (NamingException ne)
+                    {
+                        throw new EncoderException("Cannot enumerate the values");
+                    }
+                    
+                    // Go to the next attribute number;
+                    attributeNumber++;
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return buffer;
+    }
+
+    /**
      * Returns the Search Result Entry string
      *
      * @return The Search Result Entry string 
@@ -314,7 +441,6 @@
                     else
                     {
                         sb.append( "            No Values\n" );
-
                     }
                 }
                 catch ( NamingException ne )

Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultEntryTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultEntryTest.java?rev=226689&r1=226688&r2=226689&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultEntryTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultEntryTest.java
Sun Jul 31 13:14:24 2005
@@ -25,11 +25,13 @@
 import javax.naming.directory.BasicAttribute;
 
 import org.apache.asn1.DecoderException;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.Asn1Decoder;
 import org.apache.asn1.ber.containers.IAsn1Container;
 import org.apache.asn1.ldap.pojo.LdapMessage;
 import org.apache.asn1.ldap.pojo.SearchResultEntry;
 import org.apache.asn1.primitives.OctetString;
+import org.apache.asn1.util.StringUtils;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
@@ -52,7 +54,7 @@
 
     /**
      * Test the decoding of a SearchResultEntry
-     *//*
+     */
     public void testDecodeSearchResultEntrySuccess() throws NamingException
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
@@ -84,6 +86,7 @@
                 0x04, 0x12, 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a', 't', 'i', 'o', 'n', 'a',
'l', 'U', 'n', 'i', 't'
             } );
 
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a BindRequest Container
@@ -134,11 +137,26 @@
         
         // Check the length
         Assert.assertEquals(0x50, message.computeLength());
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
     }
-*/
+
     /**
      * Test the decoding of a SearchResultEntry
-     */ /*
+     */
     public void testDecodeSearchResultEntry2AttrsSuccess() throws NamingException
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
@@ -148,8 +166,6 @@
         stream.put(
             new byte[]
             {
-                 
-                
                 0x30, 0x79, 		// LDAPMessage ::=SEQUENCE {
 				0x02, 0x01, 0x01, 	//     messageID MessageID
 				0x64, 0x74, 		//     CHOICE { ..., searchResEntry  SearchResultEntry, ...
@@ -179,6 +195,7 @@
 				0x04, 0x12, 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a', 't', 'i', 'o', 'n', 'a', 'l', 'U',
'n', 'i', 't'
             } );
 
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a BindRequest Container
@@ -231,8 +248,23 @@
         
         // Check the length
         Assert.assertEquals(0x7b, message.computeLength());
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
     }
-*/    
+    
     /**
      * Test the decoding of a SearchResultEntry with more bytes
      * to be decoded at the end
@@ -270,6 +302,7 @@
                   0x02, 0x01, 0x02  // messageID MessageID ...
             } );
                 
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a BindRequest Container
@@ -329,5 +362,22 @@
         Assert.assertEquals(0x02, stream.get(stream.position() + 2));
         Assert.assertEquals(0x01, stream.get(stream.position() + 3));
         Assert.assertEquals(0x02, stream.get(stream.position() + 4));
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            // We have to supress the last 5 chars from the decodedPDU, as they
+            // belongs to the next message.
+            Assert.assertEquals(encodedPdu, decodedPdu.substring(0, 0x61 * 5) );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
     }
 }



Mime
View raw message