directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r750721 - /directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/LdapProtocolDecoder.java
Date Fri, 06 Mar 2009 01:03:10 GMT
Author: elecharny
Date: Fri Mar  6 01:03:10 2009
New Revision: 750721

URL: http://svn.apache.org/viewvc?rev=750721&view=rev
Log:
Fixed the decoder to accept splitted buffers. Added some logs


Modified:
    directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/LdapProtocolDecoder.java

Modified: directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/LdapProtocolDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/LdapProtocolDecoder.java?rev=750721&r1=750720&r2=750721&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/LdapProtocolDecoder.java
(original)
+++ directory/apacheds/branches/apacheds-replication/mitosis/src/main/java/org/apache/directory/mitosis/syncrepl/LdapProtocolDecoder.java
Fri Mar  6 01:03:10 2009
@@ -19,16 +19,22 @@
  */
 package org.apache.directory.mitosis.syncrepl;
 
+import java.nio.ByteBuffer;
+
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.ber.IAsn1Container;
+import org.apache.directory.shared.asn1.ber.tlv.TLVStateEnum;
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.ldap.codec.LdapDecoder;
 import org.apache.directory.shared.ldap.codec.LdapMessage;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+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;
 
 /**
  * 
@@ -39,6 +45,12 @@
  */
 public class LdapProtocolDecoder implements ProtocolDecoder
 {
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( LdapProtocolDecoder.class
);
+    
+    /** A speedup for logger */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
     /**
      * Decode a Ldap request and write it to the remote server.
      * 
@@ -52,26 +64,55 @@
         // Allocate a LdapMessage Container
         Asn1Decoder ldapDecoder = new LdapDecoder();
         IAsn1Container ldapMessageContainer = (LdapMessageContainer)session.getAttribute(
"LDAP-Container" );
+    	ByteBuffer buf = buffer.buf();
 
-        // Decode a LDAP PDU
-        try
-        {
-            ldapDecoder.decode( buffer.buf(), ldapMessageContainer );
-        }
-        catch ( DecoderException de )
+        
+        while ( buf.hasRemaining() )
         {
-            de.printStackTrace();
+            try
+            {
+                ldapDecoder.decode( buf, ldapMessageContainer );
+    
+                if ( IS_DEBUG )
+                {
+                    LOG.debug( "Decoding the PDU : " );
+                	int size = buf.capacity();
+                	
+                	byte[] b = new byte[size];
+                	
+                	System.arraycopy( buf.array(), 0, b, 0, size );
+                	
+                	System.out.println( "Received buffer : " + StringTools.dumpBytes( b ) );
+                }
+                
+                if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED )
+                {
+                    // get back the decoded message
+                    LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer
).getLdapMessage();
+                    
+                    if ( IS_DEBUG )
+                    {
+                        LOG.debug( "Decoded LdapMessage : " + 
+                        		( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage()
);
+                        buf.mark();
+                    }
+    
+                    // Clean the container for the next decoding
+                    ( ( LdapMessageContainer ) ldapMessageContainer).clean();
+                    
+                    System.out.println( "Decoded message : " + message );
+                    
+                    // Send back the message
+                    out.write( message );
+                }
+            }
+            catch ( DecoderException de )
+            {
+                buf.clear();
+                ( ( LdapMessageContainer ) ldapMessageContainer).clean();
+                throw de;
+            }
         }
-        
-        // get back the decoded message
-        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
-        
-        // Clean the container for the next decoding
-        ( ( LdapMessageContainer ) ldapMessageContainer).clean();
-        
-        // Send back the message
-        out.write( message );
-        
     }
     
     



Mime
View raw message