directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1065460 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/codec/ main/java/org/apache/directory/shared/ldap/codec/controls/ test/java/org/apache/directory/shared/ldap/codec/abandon/
Date Mon, 31 Jan 2011 01:40:50 GMT
Author: elecharny
Date: Mon Jan 31 01:40:50 2011
New Revision: 1065460

URL: http://svn.apache.org/viewvc?rev=1065460&view=rev
Log:
Fixed the control encoding

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/BasicControlDecorator.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlDecorator.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/BasicControlDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/BasicControlDecorator.java?rev=1065460&r1=1065459&r2=1065460&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/BasicControlDecorator.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/BasicControlDecorator.java
Mon Jan 31 01:40:50 2011
@@ -20,11 +20,15 @@
 package org.apache.directory.shared.ldap.codec;
 
 
+import java.nio.ByteBuffer;
+
 import org.apache.directory.shared.asn1.Asn1Object;
 import org.apache.directory.shared.asn1.DecoderException;
+import org.apache.directory.shared.asn1.EncoderException;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.codec.controls.ControlDecorator;
 import org.apache.directory.shared.ldap.model.message.controls.BasicControl;
-import org.apache.directory.shared.util.Strings;
 
 
 /**
@@ -37,9 +41,6 @@ public class BasicControlDecorator exten
 {
     private ILdapCodecService codec;
 
-    /** The control value */
-    private byte[] value;
-
     public BasicControlDecorator( ILdapCodecService codec, BasicControl control )
     {
         super( codec, control );
@@ -49,8 +50,6 @@ public class BasicControlDecorator exten
     @Override
     public Asn1Object decode( byte[] controlBytes ) throws DecoderException
     {
-        setValue( controlBytes );
-        
         return null;
     }
 
@@ -58,32 +57,40 @@ public class BasicControlDecorator exten
     /**
      * {@inheritDoc}
      */
-    public boolean hasValue()
+    public int computeLength()
     {
-        return value != null;
+        // Call the super class to compute the global control length
+        if ( getValue() == null )
+        {
+            valueLength = 0;
+        }
+        else
+        {
+            valueLength = getValue().length;
+        }
+        
+        return super.computeLength( valueLength );
     }
-    
 
-    /**
-     * {@inheritDoc}
-     */
-    public byte[] getValue()
-    {
-        return value;
-    }
-    
 
     /**
      * {@inheritDoc}
      */
-    public void setValue( byte[] value )
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
     {
-        if ( ! Strings.isEmpty( value ) )
+        if ( buffer == null )
         {
-            byte[] copy = new byte[value.length];
-            System.arraycopy( value, 0, copy, 0, value.length );
+            throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
         }
+
+        // Encode the Control envelop
+        super.encode( buffer );
         
-        this.value = value;
+        if ( valueLength != 0 )
+        {
+            Value.encode( buffer, getValue() );
+        }
+
+        return buffer;
     }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlDecorator.java?rev=1065460&r1=1065459&r2=1065460&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlDecorator.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ControlDecorator.java
Mon Jan 31 01:40:50 2011
@@ -179,11 +179,11 @@ public abstract class ControlDecorator<E
         {
             byte[] copy = new byte[ value.length ];
             System.arraycopy( value, 0, copy, 0, value.length );
-            value = copy;
+            this.value = copy;
         } 
         else 
         {
-            value = null;
+            this.value = null;
         }
     }
 

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java?rev=1065460&r1=1065459&r2=1065460&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java
Mon Jan 31 01:40:50 2011
@@ -20,7 +20,7 @@
 package org.apache.directory.shared.ldap.codec.abandon;
 
 
-import static org.junit.Assert.assertEquals; 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -30,20 +30,20 @@ import java.util.Map;
 
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
-import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.DecoderException;
 import org.apache.directory.shared.asn1.EncoderException;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.ldap.codec.DefaultLdapCodecService;
 import org.apache.directory.shared.ldap.codec.ICodecControl;
 import org.apache.directory.shared.ldap.codec.ILdapCodecService;
-import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
-import org.apache.directory.shared.ldap.model.message.AbandonRequest;
-import org.apache.directory.shared.ldap.model.message.AbandonRequestImpl;
-import org.apache.directory.shared.ldap.model.message.Message;
 import org.apache.directory.shared.ldap.codec.LdapEncoder;
+import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.decorators.AbandonRequestDecorator;
 import org.apache.directory.shared.ldap.codec.decorators.MessageDecorator;
+import org.apache.directory.shared.ldap.model.message.AbandonRequest;
+import org.apache.directory.shared.ldap.model.message.AbandonRequestImpl;
 import org.apache.directory.shared.ldap.model.message.Control;
+import org.apache.directory.shared.ldap.model.message.Message;
 import org.apache.directory.shared.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -78,24 +78,27 @@ public class AbandonRequestTest
                 0x02, 0x01, 0x03, // messageID MessageID
                 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
                 // AbandonRequest,...
-                ( byte ) 0xA0, 0x5A, // controls [0] Controls OPTIONAL }
-                0x30, 0x1A, // Control ::= SEQUENCE {
-                // controlType LDAPOID,
-                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
-                // criticality BOOLEAN DEFAULT FALSE,
-                0x01, 0x01, ( byte ) 0xFF,
-                // controlValue OCTET STRING OPTIONAL }
-                0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', 0x30, 0x17, // Control ::= SEQUENCE
{
-                // controlType LDAPOID,
-                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
-                // controlValue OCTET STRING OPTIONAL }
-                0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l', 0x30, 0x12, // Control ::= SEQUENCE
{
-                // controlType LDAPOID,
-                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3',
-                // criticality BOOLEAN DEFAULT FALSE }
-                0x01, 0x01, ( byte ) 0xFF, 0x30, 0x0F, // Control ::= SEQUENCE {
-                // controlType LDAPOID}
-                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4'
} );
+                  ( byte ) 0xA0, 0x5A, // controls [0] Controls OPTIONAL }
+                    0x30, 0x1A, // Control ::= SEQUENCE {
+                                // controlType LDAPOID,
+                      0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5',
'.', '1',
+                                  // criticality BOOLEAN DEFAULT FALSE,
+                      0x01, 0x01, ( byte ) 0xFF,
+                                  // controlValue OCTET STRING OPTIONAL }
+                      0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', 
+                    0x30, 0x17, // Control ::= SEQUENCE {
+                                // controlType LDAPOID,
+                      0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5',
'.', '2',
+                                  // controlValue OCTET STRING OPTIONAL }
+                      0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l', 
+                    0x30, 0x12, // Control ::= SEQUENCE {
+                                // controlType LDAPOID,
+                      0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5',
'.', '3',
+                                  // criticality BOOLEAN DEFAULT FALSE }
+                      0x01, 0x01, ( byte ) 0xFF, 
+                    0x30, 0x0F, // Control ::= SEQUENCE {
+                                // controlType LDAPOID}
+                      0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5',
'.', '4' } );
 
         stream.flip();
 



Mime
View raw message