directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1073137 - in /directory: apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/ shared/trunk/ldap-codec-standalone/src/test/java/org/apache/directory/shared/ldap/codec/ shared/trunk/ldap-codec/src/main/java/...
Date Mon, 21 Feb 2011 20:40:10 GMT
Author: elecharny
Date: Mon Feb 21 20:40:10 2011
New Revision: 1073137

URL: http://svn.apache.org/viewvc?rev=1073137&view=rev
Log:
o Some more cleanup (useless methods removal)
o Added some Javadoc

Modified:
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java
    directory/shared/trunk/ldap-codec-standalone/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java
    directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java
    directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
    directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolDecoder.java
    directory/shared/trunk/ldap-codec/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java?rev=1073137&r1=1073136&r2=1073137&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java
Mon Feb 21 20:40:10 2011
@@ -65,6 +65,7 @@ import org.apache.directory.server.ldap.
 import org.apache.directory.shared.ldap.codec.LdapDecoder;
 import org.apache.directory.shared.ldap.codec.LdapEncoder;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.codec.decorators.MessageDecorator;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.constants.SupportedSaslMechanisms;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
@@ -73,6 +74,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.BindRequest;
 import org.apache.directory.shared.ldap.model.message.BindRequestImpl;
 import org.apache.directory.shared.ldap.model.message.BindResponse;
+import org.apache.directory.shared.ldap.model.message.Message;
 import org.apache.directory.shared.ldap.model.message.ModifyRequest;
 import org.apache.directory.shared.ldap.model.message.ModifyRequestImpl;
 import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
@@ -633,10 +635,9 @@ public class SaslBindIT extends Abstract
             }
 
             // Retrieve the response back from server to my last request.
-            LdapMessageContainer container = new LdapMessageContainer(
+            LdapMessageContainer<MessageDecorator<? extends Message>> container
= new LdapMessageContainer(
                 ldapServer.getDirectoryService().getLdapCodecService() );
-            decoder.setLdapMessageContainer( container );
-            return ( BindResponse ) decoder.decode( null, _input_ );
+            return ( BindResponse ) decoder.decode( _input_, container );
         }
 
 
@@ -672,10 +673,9 @@ public class SaslBindIT extends Abstract
             }
 
             // Retrieve the response back from server to my last request.
-            LdapMessageContainer container = new LdapMessageContainer(
-                getLdapServer().getDirectoryService().getLdapCodecService() );
-            decoder.setLdapMessageContainer( container );
-            return ( BindResponse ) decoder.decode( null, _input_ );
+            LdapMessageContainer<MessageDecorator<? extends Message>> container
= new LdapMessageContainer(
+                ldapServer.getDirectoryService().getLdapCodecService() );
+            return ( BindResponse ) decoder.decode( _input_ , container );
         }
     }
 

Modified: directory/shared/trunk/ldap-codec-standalone/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-codec-standalone/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java?rev=1073137&r1=1073136&r2=1073137&view=diff
==============================================================================
--- directory/shared/trunk/ldap-codec-standalone/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java
(original)
+++ directory/shared/trunk/ldap-codec-standalone/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java
Mon Feb 21 20:40:10 2011
@@ -27,7 +27,6 @@ import static org.junit.Assert.fail;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Queue;
 
 import org.apache.directory.shared.asn1.DecoderException;
 import org.apache.directory.shared.asn1.ber.Asn1Container;
@@ -39,11 +38,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.BindRequest;
 import org.apache.directory.shared.ldap.model.message.Message;
 import org.apache.directory.shared.util.Strings;
-import org.apache.mina.core.buffer.IoBuffer;
-import org.apache.mina.core.filterchain.IoFilter.NextFilter;
 import org.apache.mina.core.session.DummySession;
 import org.apache.mina.core.session.IoSession;
-import org.apache.mina.filter.codec.AbstractProtocolDecoderOutput;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -61,40 +57,6 @@ import com.mycila.junit.concurrent.Concu
 public class LdapDecoderTest extends AbstractCodecServiceTest
 {
     
-    private static class LdapProtocolDecoderOutput extends AbstractProtocolDecoderOutput

-    {
-        public LdapProtocolDecoderOutput()
-        {
-            // Do nothing
-        }
-        
-        public void flush( NextFilter nextFilter, IoSession session ) 
-        {
-            // Do nothing
-            Queue<Object> messageQueue = getMessageQueue();
-            
-            while ( !messageQueue.isEmpty() ) 
-            {
-                nextFilter.messageReceived( session, messageQueue.poll()) ;
-            }
-        }
-
-
-        public Object getMessage()
-        {
-            Queue<Object> messageQueue = getMessageQueue();
-
-            if ( !messageQueue.isEmpty() )
-            {
-                return messageQueue.poll();
-            }
-            else
-            {
-                return null;
-            }
-        }
-    }
-    
     /**
      * Test the decoding of a full PDU
      */
@@ -104,9 +66,8 @@ public class LdapDecoderTest extends Abs
         LdapDecoder ldapDecoder = new LdapDecoder();
         LdapMessageContainer<MessageDecorator<? extends Message>> container =

             new LdapMessageContainer<MessageDecorator<? extends Message>>( codec
);
-        ldapDecoder.setLdapMessageContainer( container );
 
-        IoBuffer stream = IoBuffer.allocate( 0x35 );
+        ByteBuffer stream = ByteBuffer.allocate( 0x35 );
         stream.put( new byte[]
             { 
                 0x30, 0x33,                     // LDAPMessage ::=SEQUENCE {
@@ -159,12 +120,11 @@ public class LdapDecoderTest extends Abs
         LdapDecoder ldapDecoder = new LdapDecoder();
         LdapMessageContainer<MessageDecorator<? extends Message>> container =

             new LdapMessageContainer<MessageDecorator<? extends Message>>( codec
);
-        ldapDecoder.setLdapMessageContainer( container );
 
         IoSession dummySession = new DummySession();
         dummySession.setAttribute( "messageContainer", container );
 
-        IoBuffer stream = IoBuffer.allocate( 0x6A );
+        ByteBuffer stream = ByteBuffer.allocate( 0x6A );
         stream.put( new byte[]
             { 
                 0x30, 0x33,                     // LDAPMessage ::=SEQUENCE {

Modified: directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java?rev=1073137&r1=1073136&r2=1073137&view=diff
==============================================================================
--- directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java
(original)
+++ directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java
Mon Feb 21 20:40:10 2011
@@ -22,7 +22,6 @@ package org.apache.directory.shared.ldap
 
 import java.io.InputStream;
 import java.nio.ByteBuffer;
-import java.security.ProviderException;
 import java.util.List;
 
 import org.apache.directory.shared.asn1.DecoderException;
@@ -34,13 +33,12 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.exception.ResponseCarryingMessageException;
 import org.apache.directory.shared.ldap.model.message.Message;
 import org.apache.directory.shared.util.Strings;
-import org.apache.mina.core.buffer.IoBuffer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
 /**
- * The LdapDecoder decodes ASN.1 BER encoded PDUs.
+ * The LdapDecoder decodes ASN.1 BER encoded PDUs into LDAP messages
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -58,7 +56,6 @@ public class LdapDecoder
     /** The ASN 1 decoder instance */
     private Asn1Decoder asn1Decoder;
 
-
     /**
      * Creates an instance of a Ldap Decoder implementation.
      */
@@ -69,30 +66,28 @@ public class LdapDecoder
 
 
     /**
-     * Feeds the bytes within the input stream to the digester to generate the
-     * resultant decoded Message.
+     * Decodes a PDU from an input stream into a Ldap message container. We can only
+     * decode one complete message.
      *
-     * @param in The InputStream containing the PDU to be decoded
-     * @throws ProviderException If the decoding went wrong
+     * @param in The input stream to read and decode PDU bytes from
+     * @return return The decoded message
      */
-    private void digest( InputStream in ) throws DecoderException
+    public Message decode( InputStream in, LdapMessageContainer<MessageDecorator<?
extends Message>> container ) throws DecoderException
     {
-        byte[] buf;
-
         try
         {
             int amount;
 
             while ( in.available() > 0 )
             {
-                buf = new byte[in.available()];
+                byte[]buf = new byte[in.available()];
 
                 if ( ( amount = in.read( buf ) ) == -1 )
                 {
                     break;
                 }
 
-                asn1Decoder.decode( ByteBuffer.wrap( buf, 0, amount ), ldapMessageContainer
);
+                asn1Decoder.decode( ByteBuffer.wrap( buf, 0, amount ), container );
             }
         }
         catch ( Exception e )
@@ -101,103 +96,59 @@ public class LdapDecoder
             LOG.error( message );
             throw new DecoderException( message, e );
         }
-    }
-
 
-    /**
-     * Decodes a PDU from an input stream into a Snickers compiler generated
-     * stub envelope.
-     *
-     * @param lock Lock object used to exclusively read from the input stream
-     * @param in The input stream to read and decode PDU bytes from
-     * @return return decoded stub
-     */
-    public Object decode( Object lock, InputStream in ) throws DecoderException
-    {
-        if ( lock == null )
+        if ( container.getState() == TLVStateEnum.PDU_DECODED )
         {
-            digest( in );
-
-            if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED )
+            if ( IS_DEBUG )
             {
-                if ( IS_DEBUG )
-                {
-                    LOG.debug( "Decoded LdapMessage : " + ldapMessageContainer.getMessage()
);
-                }
-
-                return ldapMessageContainer.getMessage();
-            }
-            else
-            {
-                LOG.error( I18n.err( I18n.ERR_04062 ) );
-                throw new DecoderException( I18n.err( I18n.ERR_04063 ) );
+                LOG.debug( "Decoded LdapMessage : " + container );
             }
+
+            return container.getMessage();
         }
         else
         {
-            try
-            {
-                // Synchronize on the input lock object to prevent concurrent
-                // reads
-                synchronized ( lock )
-                {
-                    digest( in );
-
-                    // Notify/awaken threads waiting to read from input stream
-                    lock.notifyAll();
-                }
-            }
-            catch ( Exception e )
-            {
-                String message = I18n.err( I18n.ERR_04060, e.getLocalizedMessage() );
-                LOG.error( message );
-                throw new DecoderException( message, e );
-            }
-
-            if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED )
-            {
-                if ( IS_DEBUG )
-                {
-                    LOG.debug( "Decoded LdapMessage : " + ldapMessageContainer.getMessage()
);
-                }
-
-                return ldapMessageContainer.getMessage();
-            }
-            else
-            {
-                LOG.error( I18n.err( I18n.ERR_04064 ) );
-                throw new DecoderException( I18n.err( I18n.ERR_04063 ) );
-            }
+            LOG.error( I18n.err( I18n.ERR_04062 ) );
+            throw new DecoderException( I18n.err( I18n.ERR_04063 ) );
         }
     }
 
 
-    @SuppressWarnings("unchecked")
-    public void decode( IoBuffer in, LdapMessageContainer<MessageDecorator<? extends
Message>> messageContainer, List<Message> decodedMessages ) throws Exception
+    /**
+     * Decode an incoming buffer into LDAP messages. The result can be 0, 1 or many 
+     * LDAP messages, which will be stored into the array the caller has created.
+     * 
+     * @param buffer The incoming byte buffer
+     * @param messageContainer The LdapMessageContainer which will be used to store the
+     * message being decoded. If the message is not fully decoded, the ucrrent state
+     * is stored into this container
+     * @param decodedMessages The list of decoded messages
+     * @throws Exception If the decoding failed
+     */
+    public void decode( ByteBuffer buffer, LdapMessageContainer<MessageDecorator<?
extends Message>> messageContainer, List<Message> decodedMessages ) throws DecoderException
     {
-        ByteBuffer buf = in.buf();
-        buf.mark();
+        buffer.mark();
 
-        while ( buf.hasRemaining() )
+        while ( buffer.hasRemaining() )
         {
             try
             {
-                asn1Decoder.decode( buf, messageContainer );
+                asn1Decoder.decode( buffer, messageContainer );
 
                 if ( IS_DEBUG )
                 {
                     LOG.debug( "Decoding the PDU : " );
 
-                    int size = buf.position();
-                    buf.reset();
-                    int position = buf.position();
+                    int size = buffer.position();
+                    buffer.reset();
+                    int position = buffer.position();
                     int pduLength = size - position;
 
                     byte[] array = new byte[pduLength];
 
-                    System.arraycopy(buf.array(), position, array, 0, pduLength);
+                    System.arraycopy(buffer.array(), position, array, 0, pduLength);
 
-                    buf.position( size );
+                    buffer.position( size );
 
                     if ( array.length == 0 )
                     {
@@ -209,7 +160,7 @@ public class LdapDecoder
                     }
                 }
 
-                buf.mark();
+                buffer.mark();
 
                 if ( messageContainer.getState() == TLVStateEnum.PDU_DECODED )
                 {
@@ -227,7 +178,7 @@ public class LdapDecoder
             }
             catch ( DecoderException de )
             {
-                buf.clear();
+                buffer.clear();
                 messageContainer.clean();
 
                 if ( de instanceof ResponseCarryingException )
@@ -246,13 +197,4 @@ public class LdapDecoder
             }
         }
     }
-
-
-    /**
-     * @param ldapMessageContainer the ldapMessageContainer to set
-     */
-    public void setLdapMessageContainer( LdapMessageContainer<MessageDecorator<? extends
Message>> ldapMessageContainer )
-    {
-        this.ldapMessageContainer = ldapMessageContainer;
-    }
 }

Modified: directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java?rev=1073137&r1=1073136&r2=1073137&view=diff
==============================================================================
--- directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
(original)
+++ directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
Mon Feb 21 20:40:10 2011
@@ -52,12 +52,21 @@ public class LdapEncoder
     private LdapCodecService codec;
     
     
+    /**
+     * Creates an instance of Ldap message encoder
+     * 
+     * @param codec The Codec service to use to handle Controls and extended operations,
+     * plus to get access to the underlying services.
+     */
     public LdapEncoder( LdapCodecService codec )
     {
         this.codec = codec;
     }
     
     
+    /**
+     * Compute the control's encoded length
+     */
     private int computeControlLength( Control control )
     {
         // First, compute the control's value length
@@ -84,7 +93,7 @@ public class LdapEncoder
     
     
     /**
-     * {@inheritDoc}
+     * Encode a control to a byte[]
      */
     private ByteBuffer encodeControl( ByteBuffer buffer, Control control ) throws EncoderException
     {
@@ -293,7 +302,9 @@ public class LdapEncoder
      * Encode the Referral message to a PDU.
      * 
      * @param buffer The buffer where to put the PDU
-     * @return The PDU.
+     * @param referral The referral to encode
+     * @return The encoded referral
+     * @exception EncoderException If the encoding failed
      */
     public static void encodeReferral( ByteBuffer buffer, Referral referral ) throws EncoderException
     {
@@ -316,6 +327,11 @@ public class LdapEncoder
     }
 
 
+    /**
+     * Compute the referral's encoded length
+     * @param referral The referral to encode
+     * @return The length of the encoded PDU
+     */
     public static int computeReferralLength( Referral referral )
     {
         if ( referral != null )

Modified: directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolDecoder.java?rev=1073137&r1=1073136&r2=1073137&view=diff
==============================================================================
--- directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolDecoder.java
(original)
+++ directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolDecoder.java
Mon Feb 21 20:40:10 2011
@@ -20,6 +20,7 @@
 package org.apache.directory.shared.ldap.codec.protocol.mina;
 
 
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -72,7 +73,9 @@ public class LdapProtocolDecoder impleme
         }
 
         List<Message> decodedMessages = new ArrayList<Message>();
-        decoder.decode( in, messageContainer, decodedMessages );
+        ByteBuffer buf = in.buf();
+
+        decoder.decode( buf, messageContainer, decodedMessages );
         
         for ( Message message : decodedMessages )
         {

Modified: directory/shared/trunk/ldap-codec/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-codec/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java?rev=1073137&r1=1073136&r2=1073137&view=diff
==============================================================================
--- directory/shared/trunk/ldap-codec/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java
(original)
+++ directory/shared/trunk/ldap-codec/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java
Mon Feb 21 20:40:10 2011
@@ -27,7 +27,6 @@ import static org.junit.Assert.fail;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Queue;
 
 import org.apache.directory.shared.asn1.DecoderException;
 import org.apache.directory.shared.asn1.ber.Asn1Container;
@@ -39,11 +38,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.BindRequest;
 import org.apache.directory.shared.ldap.model.message.Message;
 import org.apache.directory.shared.util.Strings;
-import org.apache.mina.core.buffer.IoBuffer;
-import org.apache.mina.core.filterchain.IoFilter.NextFilter;
 import org.apache.mina.core.session.DummySession;
 import org.apache.mina.core.session.IoSession;
-import org.apache.mina.filter.codec.AbstractProtocolDecoderOutput;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -60,41 +56,6 @@ import com.mycila.junit.concurrent.Concu
 @Concurrency()
 public class LdapDecoderTest extends AbstractCodecServiceTest
 {
-    
-    private static class LdapProtocolDecoderOutput extends AbstractProtocolDecoderOutput

-    {
-        public LdapProtocolDecoderOutput()
-        {
-            // Do nothing
-        }
-        
-        public void flush( NextFilter nextFilter, IoSession session ) 
-        {
-            // Do nothing
-            Queue<Object> messageQueue = getMessageQueue();
-            
-            while ( !messageQueue.isEmpty() ) 
-            {
-                nextFilter.messageReceived( session, messageQueue.poll()) ;
-            }
-        }
-
-
-        public Object getMessage()
-        {
-            Queue<Object> messageQueue = getMessageQueue();
-
-            if ( !messageQueue.isEmpty() )
-            {
-                return messageQueue.poll();
-            }
-            else
-            {
-                return null;
-            }
-        }
-    }
-    
     /**
      * Test the decoding of a full PDU
      */
@@ -158,12 +119,11 @@ public class LdapDecoderTest extends Abs
         LdapDecoder ldapDecoder = new LdapDecoder();
         LdapMessageContainer<MessageDecorator<? extends Message>> container =

             new LdapMessageContainer<MessageDecorator<? extends Message>>( codec
);
-        ldapDecoder.setLdapMessageContainer( container );
 
         IoSession dummySession = new DummySession();
         dummySession.setAttribute( "messageContainer", container );
 
-        IoBuffer stream = IoBuffer.allocate( 0x6A );
+        ByteBuffer stream = ByteBuffer.allocate( 0x6A );
         stream.put( new byte[]
             { 
                 0x30, 0x33,                     // LDAPMessage ::=SEQUENCE {



Mime
View raw message