directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1005086 - in /directory: apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/ apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/ shared/trunk/ldap/ shared/trunk/ldap/src/main/java...
Date Wed, 06 Oct 2010 15:33:52 GMT
Author: elecharny
Date: Wed Oct  6 15:33:52 2010
New Revision: 1005086

URL: http://svn.apache.org/viewvc?rev=1005086&view=rev
Log:
Reviewed the way the codec is used in the server:
o the provider has been removed (with all the associated classes)
o we inject some configuration in the sessionCreated() event
o the MessageDecoder class has been deleted

Removed:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProvider.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/MessageDecoder.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/spi/Provider.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/spi/ProviderDecoder.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/spi/ProviderEncoder.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/spi/ProviderException.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/spi/ProviderMonitor.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/spi/ProviderObject.java
Modified:
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolCodecFactory.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/bind/SaslBindIT.java
    directory/shared/trunk/ldap/pom.xml
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolCodecFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolCodecFactory.java?rev=1005086&r1=1005085&r2=1005086&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolCodecFactory.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolCodecFactory.java
Wed Oct  6 15:33:52 2010
@@ -22,20 +22,10 @@ package org.apache.directory.server.ldap
 
 import org.apache.directory.ldap.client.api.protocol.LdapProtocolEncoder;
 import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.asn1.codec.stateful.DecoderCallback;
-import org.apache.directory.shared.asn1.codec.stateful.StatefulDecoder;
-import org.apache.directory.shared.ldap.message.MessageDecoder;
-import org.apache.directory.shared.ldap.message.spi.BinaryAttributeDetector;
-import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.schema.SchemaManager;
-import org.apache.directory.shared.ldap.util.StringTools;
-import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.directory.shared.ldap.codec.LdapDecoder;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.ProtocolCodecFactory;
 import org.apache.mina.filter.codec.ProtocolDecoder;
-import org.apache.mina.filter.codec.ProtocolDecoderAdapter;
-import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.apache.mina.filter.codec.ProtocolEncoder;
 
 
@@ -46,50 +36,12 @@ import org.apache.mina.filter.codec.Prot
  */
 final class LdapProtocolCodecFactory implements ProtocolCodecFactory
 {
-    private class Asn1CodecDecoder extends ProtocolDecoderAdapter
-    {
-        /** The stateful decoder */
-        private final StatefulDecoder decoder;
-
-        /** The Output queue */
-        private ProtocolDecoderOutput decOut;
-
-
-        /**
-         * Creates a new instance of Asn1CodecDecoder.
-         * 
-         * @param decoder The associated decoder
-         */
-        public Asn1CodecDecoder( StatefulDecoder decoder )
-        {
-            this.decoder = decoder;
-            this.decoder.setCallback( new DecoderCallback()
-            {
-                public void decodeOccurred( StatefulDecoder decoder, Object decoded )
-                {
-                    decOut.write( decoded );
-                }
-            } );
-        }
-
-
-        /**
-         * {@inheritDoc}
-         */
-        public void decode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws
DecoderException
-        {
-            decOut = out;
-            decoder.decode( in.buf() );
-        }
-    }
-
-
-    /** the directory service for which this factor generates codecs */
-    final private DirectoryService directoryService;
-
     /** The tag stored into the session if we want to set a max PDU size */
     public final static String MAX_PDU_SIZE = "MAX_PDU_SIZE";
 
+    private ProtocolDecoder decoder;
+    private ProtocolEncoder encoder;
+
 
     /**
      * Creates a new instance of LdapProtocolCodecFactory.
@@ -97,9 +49,10 @@ final class LdapProtocolCodecFactory imp
      * @param directoryService the {@link DirectoryService} for which this 
      * factory generates codecs.
      */
-    public LdapProtocolCodecFactory( DirectoryService directoryService )
+    public LdapProtocolCodecFactory( final DirectoryService directoryService )
     {
-        this.directoryService = directoryService;
+        encoder = new LdapProtocolEncoder();
+        decoder = new LdapDecoder();
     }
 
 
@@ -108,7 +61,7 @@ final class LdapProtocolCodecFactory imp
      */
     public ProtocolEncoder getEncoder( IoSession session )
     {
-        return new LdapProtocolEncoder();
+        return encoder;
     }
 
 
@@ -117,27 +70,6 @@ final class LdapProtocolCodecFactory imp
      */
     public ProtocolDecoder getDecoder( IoSession session )
     {
-        return new Asn1CodecDecoder( new MessageDecoder( new BinaryAttributeDetector()
-        {
-            public boolean isBinary( String id )
-            {
-                SchemaManager schemaManager = directoryService.getSchemaManager();
-
-                try
-                {
-                    AttributeType type = schemaManager.lookupAttributeTypeRegistry( id );
-                    return !type.getSyntax().isHumanReadable();
-                }
-                catch ( Exception e )
-                {
-                    if ( StringTools.isEmpty( id ) )
-                    {
-                        return false;
-                    }
-
-                    return id.endsWith( ";binary" );
-                }
-            }
-        }, directoryService.getMaxPDUSize() ) );
+        return decoder;
     }
 }
\ No newline at end of file

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java?rev=1005086&r1=1005085&r2=1005086&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java
(original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java
Wed Oct  6 15:33:52 2010
@@ -20,6 +20,7 @@
 package org.apache.directory.server.ldap;
 
 
+import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.message.ExtendedRequest;
 import org.apache.directory.shared.ldap.message.ExtendedRequestImpl;
 import org.apache.directory.shared.ldap.message.Request;
@@ -29,6 +30,10 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.ResultResponseRequest;
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.message.extended.NoticeOfDisconnect;
+import org.apache.directory.shared.ldap.message.spi.BinaryAttributeDetector;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.apache.mina.core.service.IoHandler;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.ssl.SslFilter;
@@ -66,14 +71,47 @@ class LdapProtocolHandler extends Demuxi
     }
 
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.mina.common.IoHandlerAdapter#sessionCreated(org.apache.mina.common.IoSession)
+    /**
+     * This method is called when a new session is created. We will store some
+     * informations that the session will need to process incoming requests.
+     * 
+     * @param session the newly created session
      */
     public void sessionCreated( IoSession session ) throws Exception
     {
+        // First, create a new LdapSession and store it i the manager
         LdapSession ldapSession = new LdapSession( session );
         ldapServer.getLdapSessionManager().addLdapSession( ldapSession );
+        
+        // Now, we have to store the DirectoryService instance into the session
+        session.setAttribute( "maxPDUSize", ldapServer.getDirectoryService().getMaxPDUSize()
);
+        
+        // Last, store the message container
+        LdapMessageContainer ldapMessageContainer = new LdapMessageContainer( 
+            new BinaryAttributeDetector()
+            {
+                public boolean isBinary( String id )
+                {
+                    SchemaManager schemaManager = ldapServer.getDirectoryService().getSchemaManager();
+    
+                    try
+                    {
+                        AttributeType type = schemaManager.lookupAttributeTypeRegistry( id
);
+                        return !type.getSyntax().isHumanReadable();
+                    }
+                    catch ( Exception e )
+                    {
+                        if ( StringTools.isEmpty( id ) )
+                        {
+                            return false;
+                        }
+    
+                        return id.endsWith( ";binary" );
+                    }
+                }
+            } );
+
+        session.setAttribute( "messageContainer", ldapMessageContainer );
     }
 
 
@@ -129,9 +167,8 @@ class LdapProtocolHandler extends Demuxi
     }
 
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.mina.handler.demux.DemuxingIoHandler#messageReceived(org.apache.mina.common.IoSession,
java.lang.Object)
+    /**
+     * {@inheritDoc}
      */
     public void messageSent( IoSession session, Object message ) throws Exception
     {
@@ -140,9 +177,8 @@ class LdapProtocolHandler extends Demuxi
     }
 
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.mina.handler.demux.DemuxingIoHandler#messageReceived(org.apache.mina.common.IoSession,
java.lang.Object)
+    /**
+     * {@inheritDoc}
      */
     public void messageReceived( IoSession session, Object message ) throws Exception
     {
@@ -194,9 +230,8 @@ class LdapProtocolHandler extends Demuxi
     }
 
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.mina.common.IoHandlerAdapter#exceptionCaught(org.apache.mina.common.IoSession,
java.lang.Throwable)
+    /**
+     * {@inheritDoc}
      */
     public void exceptionCaught( IoSession session, Throwable cause )
     {

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=1005086&r1=1005085&r2=1005086&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
Wed Oct  6 15:33:52 2010
@@ -58,6 +58,8 @@ import org.apache.directory.server.ldap.
 import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmMechanismHandler;
 import org.apache.directory.server.ldap.handlers.bind.plain.PlainMechanismHandler;
 import org.apache.directory.server.ldap.handlers.extended.StoredProcedureExtendedOperationHandler;
+import org.apache.directory.shared.ldap.codec.LdapDecoder;
+import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms;
 import org.apache.directory.shared.ldap.entry.DefaultEntry;
@@ -67,11 +69,9 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.BindRequestImpl;
 import org.apache.directory.shared.ldap.message.BindResponse;
 import org.apache.directory.shared.ldap.message.LdapEncoder;
-import org.apache.directory.shared.ldap.message.MessageDecoder;
 import org.apache.directory.shared.ldap.message.ModifyRequest;
 import org.apache.directory.shared.ldap.message.ModifyRequestImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.message.spi.BinaryAttributeDetector;
 import org.apache.directory.shared.ldap.name.DN;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -512,13 +512,7 @@ public class SaslBindIT extends Abstract
             request.setVersion3( true );
 
             // Setup the ASN1 Encoder and Decoder
-            MessageDecoder decoder = new MessageDecoder( new BinaryAttributeDetector()
-            {
-                public boolean isBinary( String attributeId )
-                {
-                    return false;
-                }
-            } );
+            LdapDecoder decoder = new LdapDecoder();
 
             // Send encoded request to server
             LdapEncoder encoder = new LdapEncoder();
@@ -535,6 +529,8 @@ public class SaslBindIT extends Abstract
             }
 
             // Retrieve the response back from server to my last request.
+            LdapMessageContainer container = new LdapMessageContainer();
+            decoder.setLdapMessageContainer( container );
             return ( BindResponse ) decoder.decode( null, _input_ );
         }
 
@@ -555,13 +551,7 @@ public class SaslBindIT extends Abstract
             request.setVersion3( true );
 
             // Setup the ASN1 Enoder and Decoder
-            MessageDecoder decoder = new MessageDecoder( new BinaryAttributeDetector()
-            {
-                public boolean isBinary( String attributeId )
-                {
-                    return false;
-                }
-            } );
+            LdapDecoder decoder = new LdapDecoder();
 
             // Send encoded request to server
             LdapEncoder encoder = new LdapEncoder();
@@ -577,6 +567,8 @@ public class SaslBindIT extends Abstract
             }
 
             // Retrieve the response back from server to my last request.
+            LdapMessageContainer container = new LdapMessageContainer();
+            decoder.setLdapMessageContainer( container );
             return ( BindResponse ) decoder.decode( null, _input_ );
         }
     }

Modified: directory/shared/trunk/ldap/pom.xml
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/pom.xml?rev=1005086&r1=1005085&r2=1005086&view=diff
==============================================================================
--- directory/shared/trunk/ldap/pom.xml (original)
+++ directory/shared/trunk/ldap/pom.xml Wed Oct  6 15:33:52 2010
@@ -43,6 +43,11 @@
     </dependency> 
 
     <dependency>
+      <groupId>org.apache.mina</groupId>
+      <artifactId>mina-core</artifactId>
+    </dependency>
+    
+    <dependency>
       <groupId>antlr</groupId>
       <artifactId>antlr</artifactId>
     </dependency>

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java?rev=1005086&r1=1005085&r2=1005086&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapDecoder.java
Wed Oct  6 15:33:52 2010
@@ -22,17 +22,19 @@ package org.apache.directory.shared.ldap
 
 import java.io.InputStream;
 import java.nio.ByteBuffer;
+import java.security.ProviderException;
 
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.ber.tlv.TLVStateEnum;
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.codec.stateful.DecoderCallback;
 import org.apache.directory.shared.i18n.I18n;
-import org.apache.directory.shared.ldap.message.spi.BinaryAttributeDetector;
-import org.apache.directory.shared.ldap.message.spi.Provider;
-import org.apache.directory.shared.ldap.message.spi.ProviderDecoder;
-import org.apache.directory.shared.ldap.message.spi.ProviderException;
+import org.apache.directory.shared.ldap.message.ResponseCarryingMessageException;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,7 +44,7 @@ import org.slf4j.LoggerFactory;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class LdapDecoder implements ProviderDecoder
+public class LdapDecoder implements ProtocolDecoder
 {
     /** The logger */
     private static Logger log = LoggerFactory.getLogger( LdapDecoder.class );
@@ -50,18 +52,15 @@ public class LdapDecoder implements Prov
     /** A speedup for logger */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
 
-    /** The associated Provider */
-    private final Provider provider;
-
     /** The message container for this instance */
-    private final LdapMessageContainer ldapMessageContainer;
-
-    /** The Ldap BDER decoder instance */
-    private final Asn1Decoder ldapDecoder;
+    private LdapMessageContainer ldapMessageContainer;
 
     /** The callback to call when the decoding is done */
     private DecoderCallback decoderCallback;
 
+    /** The ASN 1 deocder instance */
+    private Asn1Decoder asn1Decoder;
+
 
     /**
      * Creates an instance of a Ldap Decoder implementation.
@@ -70,13 +69,9 @@ public class LdapDecoder implements Prov
      * @param binaryAttributeDetector checks for binary attributes 
      * @param maxPDUSize the maximum size a PDU can be
      */
-    public LdapDecoder( Provider provider, BinaryAttributeDetector binaryAttributeDetector,
int maxPDUSize )
+    public LdapDecoder()
     {
-        this.provider = provider;
-        ldapMessageContainer = new LdapMessageContainer( binaryAttributeDetector );
-        ldapDecoder = new Asn1Decoder();
-
-        ldapMessageContainer.setMaxPDUSize( maxPDUSize );
+        asn1Decoder = new Asn1Decoder();
     }
 
 
@@ -85,7 +80,7 @@ public class LdapDecoder implements Prov
      * 
      * @param encoded The PDU containing the LdapMessage to decode
      * @throws DecoderException if anything goes wrong
-     */
+     *
     public void decode( Object encoded ) throws DecoderException
     {
         ByteBuffer buf;
@@ -108,7 +103,7 @@ public class LdapDecoder implements Prov
         {
             try
             {
-                ldapDecoder.decode( buf, ldapMessageContainer );
+                asn1Decoder.decode( buf, ldapMessageContainer );
 
                 if ( IS_DEBUG )
                 {
@@ -166,7 +161,7 @@ public class LdapDecoder implements Prov
      * @param in The InputStream containing the PDU to be decoded
      * @throws ProviderException If the decoding went wrong
      */
-    private void digest( InputStream in ) throws ProviderException
+    private void digest( InputStream in ) throws DecoderException
     {
         byte[] buf;
 
@@ -183,15 +178,14 @@ public class LdapDecoder implements Prov
                     break;
                 }
 
-                ldapDecoder.decode( ByteBuffer.wrap( buf, 0, amount ), ldapMessageContainer
);
+                asn1Decoder.decode( ByteBuffer.wrap( buf, 0, amount ), ldapMessageContainer
);
             }
         }
         catch ( Exception e )
         {
-            log.error( I18n.err( I18n.ERR_04060, e.getLocalizedMessage() ) );
-            ProviderException pe = new ProviderException( provider, I18n.err( I18n.ERR_04061
) );
-            pe.addThrowable( e );
-            throw pe;
+            String message = I18n.err( I18n.ERR_04060, e.getLocalizedMessage() );
+            log.error( message );
+            throw new DecoderException( message, e );
         }
     }
 
@@ -204,7 +198,7 @@ public class LdapDecoder implements Prov
      * @param in The input stream to read and decode PDU bytes from
      * @return return decoded stub
      */
-    public Object decode( Object lock, InputStream in ) throws ProviderException
+    public Object decode( Object lock, InputStream in ) throws DecoderException
     {
         if ( lock == null )
         {
@@ -222,10 +216,7 @@ public class LdapDecoder implements Prov
             else
             {
                 log.error( I18n.err( I18n.ERR_04062 ) );
-                ProviderException pe = new ProviderException( provider, I18n.err( I18n.ERR_04061
) );
-                //noinspection ThrowableInstanceNeverThrown
-                pe.addThrowable( new DecoderException( I18n.err( I18n.ERR_04063 ) ) );
-                throw pe;
+                throw new DecoderException( I18n.err( I18n.ERR_04063 ) );
             }
         }
         else
@@ -244,10 +235,9 @@ public class LdapDecoder implements Prov
             }
             catch ( Exception e )
             {
-                log.error( I18n.err( I18n.ERR_04060, e.getLocalizedMessage() ) );
-                ProviderException pe = new ProviderException( provider, I18n.err( I18n.ERR_04061
) );
-                pe.addThrowable( e );
-                throw pe;
+                String message = I18n.err( I18n.ERR_04060, e.getLocalizedMessage() );
+                log.error( message );
+                throw new DecoderException( message, e );
             }
 
             if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED )
@@ -262,27 +252,13 @@ public class LdapDecoder implements Prov
             else
             {
                 log.error( I18n.err( I18n.ERR_04064 ) );
-                ProviderException pe = new ProviderException( provider, I18n.err( I18n.ERR_04062
) );
-                //noinspection ThrowableInstanceNeverThrown
-                pe.addThrowable( new DecoderException( I18n.err( I18n.ERR_04063 ) ) );
-                throw pe;
+                throw new DecoderException( I18n.err( I18n.ERR_04063 ) );
             }
         }
     }
 
 
     /**
-     * Gets the Provider that this Decoder implementation is part of.
-     * 
-     * @return the owning provider.
-     */
-    public Provider getProvider()
-    {
-        return provider;
-    }
-
-
-    /**
      * Set the callback to call when the PDU has been decoded
      * 
      * @param cb The callback
@@ -300,4 +276,105 @@ public class LdapDecoder implements Prov
     {
         return decoderCallback;
     }
+
+
+    public void decode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws
Exception
+    {
+        ByteBuffer buf = in.buf();
+        int position = 0;
+        LdapMessageContainer messageContainer = ( LdapMessageContainer ) session
+            .getAttribute( "messageContainer" );
+
+        if ( session.containsAttribute( "maxPDUSize" ) )
+        {
+            int maxPDUSize = ( Integer ) session.getAttribute( "maxPDUSize" );
+
+            messageContainer.setMaxPDUSize( maxPDUSize );
+        }
+
+        while ( buf.hasRemaining() )
+        {
+            try
+            {
+                asn1Decoder.decode( buf, messageContainer );
+
+                if ( IS_DEBUG )
+                {
+                    log.debug( "Decoding the PDU : " );
+
+                    int size = buf.position();
+                    buf.flip();
+
+                    byte[] array = new byte[size - position];
+
+                    for ( int i = position; i < size; i++ )
+                    {
+                        array[i] = buf.get();
+                    }
+
+                    position = size;
+
+                    if ( array.length == 0 )
+                    {
+                        log.debug( "NULL buffer, what the HELL ???" );
+                    }
+                    else
+                    {
+                        log.debug( StringTools.dumpBytes( array ) );
+                    }
+                }
+
+                if ( messageContainer.getState() == TLVStateEnum.PDU_DECODED )
+                {
+                    if ( IS_DEBUG )
+                    {
+                        log.debug( "Decoded LdapMessage : " + messageContainer.getMessage()
);
+                        buf.mark();
+                    }
+
+                    out.write( messageContainer.getMessage() );
+
+                    messageContainer.clean();
+                }
+            }
+            catch ( DecoderException de )
+            {
+                buf.clear();
+                messageContainer.clean();
+
+                if ( de instanceof ResponseCarryingException )
+                {
+                    // Transform the DecoderException message to a MessageException
+                    ResponseCarryingMessageException rcme = new ResponseCarryingMessageException(
de.getMessage() );
+                    rcme.setResponse( ( ( ResponseCarryingException ) de ).getResponse()
);
+
+                    throw rcme;
+                }
+                else
+                {
+                    // TODO : This is certainly not the way we should handle such an exception
!
+                    throw new ResponseCarryingException( de.getMessage() );
+                }
+            }
+        }
+    }
+
+
+    public void dispose( IoSession session ) throws Exception
+    {
+    }
+
+
+    public void finishDecode( IoSession session, ProtocolDecoderOutput out ) throws Exception
+    {
+    }
+
+
+    /**
+     * @param ldapMessageContainer the ldapMessageContainer to set
+     */
+    public void setLdapMessageContainer( LdapMessageContainer ldapMessageContainer )
+    {
+        this.ldapMessageContainer = ldapMessageContainer;
+    }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java?rev=1005086&r1=1005085&r2=1005086&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
Wed Oct  6 15:33:52 2010
@@ -22,12 +22,10 @@ package org.apache.directory.shared.ldap
 
 import java.io.OutputStream;
 import java.nio.ByteBuffer;
+import java.security.ProviderException;
 
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.asn1.codec.stateful.EncoderCallback;
-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;
 
 
 /**
@@ -35,20 +33,15 @@ import org.apache.directory.shared.ldap.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class LdapEncoder implements ProviderEncoder
+public class LdapEncoder
 {
-    /** The associated Provider */
-    final Provider provider;
-
-
     /**
      * Creates an instance of a Ldap Encoder implementation.
      * 
      * @param provider The associated Provider
      */
-    public LdapEncoder( Provider provider )
+    public LdapEncoder()
     {
-        this.provider = provider;
     }
 
 
@@ -60,7 +53,7 @@ public class LdapEncoder implements Prov
      * @param obj The LdapMessage to encode
      * @throws ProviderException If anything went wrong
      */
-    public void encodeBlocking( Object lock, OutputStream out, Object obj ) throws ProviderException
+    public void encodeBlocking( Object lock, OutputStream out, Object obj ) throws EncoderException
     {
     }
 
@@ -80,17 +73,6 @@ public class LdapEncoder implements Prov
 
 
     /**
-     * Gets the Provider associated with this SPI implementation object.
-     * 
-     * @return Provider The provider
-     */
-    public Provider getProvider()
-    {
-        return provider;
-    }
-
-
-    /**
      * Encodes a LdapMessage, and calls the callback
      * 
      * @param obj The LdapMessage to encode



Mime
View raw message