directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1073111 - in /directory: apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/ shared/trunk/ldap-codec-standalone/src/test/java/org/apache/directory/shared/ldap/codec/ shared/trunk/ldap-codec/src/main/java/org/apache...
Date Mon, 21 Feb 2011 18:53:04 GMT
Author: elecharny
Date: Mon Feb 21 18:53:04 2011
New Revision: 1073111

URL: http://svn.apache.org/viewvc?rev=1073111&view=rev
Log:
Decoupled the codec classes from the network layer.

Added:
    directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolDecoder.java
Modified:
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolCodecFactory.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/protocol/mina/LdapProtocolCodecFactory.java
    directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolEncoder.java
    directory/shared/trunk/ldap-codec/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.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=1073111&r1=1073110&r2=1073111&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
Mon Feb 21 18:53:04 2011
@@ -21,7 +21,7 @@ package org.apache.directory.server.ldap
 
 
 import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.shared.ldap.codec.LdapDecoder;
+import org.apache.directory.shared.ldap.codec.protocol.mina.LdapProtocolDecoder;
 import org.apache.directory.shared.ldap.codec.protocol.mina.LdapProtocolEncoder;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.ProtocolCodecFactory;
@@ -52,7 +52,7 @@ final class LdapProtocolCodecFactory imp
     public LdapProtocolCodecFactory( final DirectoryService directoryService )
     {
         encoder = new LdapProtocolEncoder( directoryService.getLdapCodecService() );
-        decoder = new LdapDecoder();
+        decoder = new LdapProtocolDecoder( directoryService.getLdapCodecService() );
     }
 
 

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=1073111&r1=1073110&r2=1073111&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 18:53:04 2011
@@ -24,13 +24,11 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Queue;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 import org.apache.directory.shared.asn1.DecoderException;
 import org.apache.directory.shared.asn1.ber.Asn1Container;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
@@ -46,10 +44,12 @@ import org.apache.mina.core.filterchain.
 import org.apache.mina.core.session.DummySession;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.AbstractProtocolDecoderOutput;
-import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * A global Ldap Decoder test
@@ -106,7 +106,7 @@ public class LdapDecoderTest extends Abs
             new LdapMessageContainer<MessageDecorator<? extends Message>>( codec
);
         ldapDecoder.setLdapMessageContainer( container );
 
-        ByteBuffer stream = ByteBuffer.allocate( 0x35 );
+        IoBuffer stream = IoBuffer.allocate( 0x35 );
         stream.put( new byte[]
             { 
                 0x30, 0x33,                     // LDAPMessage ::=SEQUENCE {
@@ -126,22 +126,21 @@ public class LdapDecoderTest extends Abs
 
         stream.flip();
 
-        InputStream is = new ByteArrayInputStream(stream.array());
-        Object result = null;
+        List<Message> result = new ArrayList<Message>();
 
         // Decode a BindRequest PDU
         try
         {
-            result = ldapDecoder.decode(null, is);
+            ldapDecoder.decode( stream, container, result );
         }
-        catch ( DecoderException de )
+        catch ( Exception de )
         {
             de.printStackTrace();
             fail( de.getMessage() );
         }
 
         // Check the decoded PDU
-        BindRequest bindRequest = (BindRequest) result;
+        BindRequest bindRequest = (BindRequest) result.get( 0 );
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
@@ -198,12 +197,12 @@ public class LdapDecoderTest extends Abs
 
         stream.flip();
 
-        ProtocolDecoderOutput result = new LdapProtocolDecoderOutput();
+        List<Message> result = new ArrayList<Message>();
 
         // Decode a BindRequest PDU
         try
         {
-            ldapDecoder.decode( dummySession, stream, result );
+            ldapDecoder.decode( stream, container, result );
         }
         catch ( DecoderException de )
         {
@@ -212,7 +211,7 @@ public class LdapDecoderTest extends Abs
         }
 
         // Check the decoded PDU
-        BindRequest bindRequest = (BindRequest) ( ( LdapProtocolDecoderOutput ) result ).getMessage();
+        BindRequest bindRequest = (BindRequest) ( result.get( 0 ) );
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
@@ -221,7 +220,7 @@ public class LdapDecoderTest extends Abs
         assertEquals( "password", Strings.utf8ToString(bindRequest.getCredentials()) );
         
         // The second message
-        bindRequest = ( BindRequest ) ( ( LdapProtocolDecoderOutput ) result ).getMessage();
+        bindRequest = ( BindRequest ) ( result.get( 1 ) );
 
         assertEquals( 2, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );

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=1073111&r1=1073110&r2=1073111&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 18:53:04 2011
@@ -23,6 +23,7 @@ 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;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
@@ -34,9 +35,6 @@ import org.apache.directory.shared.ldap.
 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.session.IoSession;
-import org.apache.mina.filter.codec.ProtocolDecoder;
-import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,7 +44,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class LdapDecoder implements ProtocolDecoder
+public class LdapDecoder
 {
     /** The logger */
     private static Logger LOG = LoggerFactory.getLogger( LdapDecoder.class );
@@ -175,19 +173,9 @@ public class LdapDecoder implements Prot
 
 
     @SuppressWarnings("unchecked")
-    public void decode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws
Exception
+    public void decode( IoBuffer in, LdapMessageContainer<MessageDecorator<? extends
Message>> messageContainer, List<Message> decodedMessages ) throws Exception
     {
         ByteBuffer buf = in.buf();
-        LdapMessageContainer<MessageDecorator<? extends Message>> messageContainer
=
-            ( LdapMessageContainer<MessageDecorator<? extends Message>> ) session.getAttribute(
"messageContainer" );
-
-        if ( session.containsAttribute( "maxPDUSize" ) )
-        {
-            int maxPDUSize = ( Integer ) session.getAttribute( "maxPDUSize" );
-
-            messageContainer.setMaxPDUSize( maxPDUSize );
-        }
-
         buf.mark();
 
         while ( buf.hasRemaining() )
@@ -232,7 +220,7 @@ public class LdapDecoder implements Prot
 
                     Message message = messageContainer.getMessage();
 
-                    out.write( message );
+                    decodedMessages.add( message );
 
                     messageContainer.clean();
                 }
@@ -260,16 +248,6 @@ public class LdapDecoder implements Prot
     }
 
 
-    public void dispose( IoSession session ) throws Exception
-    {
-    }
-
-
-    public void finishDecode( IoSession session, ProtocolDecoderOutput out ) throws Exception
-    {
-    }
-
-
     /**
      * @param ldapMessageContainer the ldapMessageContainer to set
      */

Modified: directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolCodecFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolCodecFactory.java?rev=1073111&r1=1073110&r2=1073111&view=diff
==============================================================================
--- directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolCodecFactory.java
(original)
+++ directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolCodecFactory.java
Mon Feb 21 18:53:04 2011
@@ -20,7 +20,6 @@
 package org.apache.directory.shared.ldap.codec.protocol.mina;
 
 
-import org.apache.directory.shared.ldap.codec.LdapDecoder;
 import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.ProtocolCodecFactory;
@@ -65,7 +64,7 @@ public class LdapProtocolCodecFactory im
      */
     public ProtocolDecoder getDecoder( IoSession session )
     {
-        return new LdapDecoder();
+        return new LdapProtocolDecoder( codec );
     }
 
 

Added: 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=1073111&view=auto
==============================================================================
--- directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolDecoder.java
(added)
+++ directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolDecoder.java
Mon Feb 21 18:53:04 2011
@@ -0,0 +1,100 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.codec.protocol.mina;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.codec.LdapDecoder;
+import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
+import org.apache.directory.shared.ldap.codec.decorators.MessageDecorator;
+import org.apache.directory.shared.ldap.model.message.Message;
+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;
+
+
+/**
+ * A LDAP message decoder. It is based on shared-ldap decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapProtocolDecoder implements ProtocolDecoder
+{
+    /** The stateful decoder */
+    private LdapDecoder decoder;
+    
+    
+    /**
+     * Creates a new instance of LdapProtocolEncoder.
+     *
+     * @param codec The LDAP codec service associated with this encoder.
+     */
+    public LdapProtocolDecoder( LdapCodecService codec )
+    {
+        this.decoder = new LdapDecoder();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void decode( IoSession session, IoBuffer in, ProtocolDecoderOutput out ) throws
Exception
+    {
+        LdapMessageContainer<MessageDecorator<? extends Message>> messageContainer
=
+            ( LdapMessageContainer<MessageDecorator<? extends Message>> ) session.getAttribute(
"messageContainer" );
+
+        if ( session.containsAttribute( "maxPDUSize" ) )
+        {
+            int maxPDUSize = ( Integer ) session.getAttribute( "maxPDUSize" );
+
+            messageContainer.setMaxPDUSize( maxPDUSize );
+        }
+
+        List<Message> decodedMessages = new ArrayList<Message>();
+        decoder.decode( in, messageContainer, decodedMessages );
+        
+        for ( Message message : decodedMessages )
+        {
+            out.write( message );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void finishDecode( IoSession session, ProtocolDecoderOutput out ) throws Exception
+    {
+        // Nothing to do
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose( IoSession session ) throws Exception
+    {
+        // Nothing to do
+    }
+}

Modified: directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolEncoder.java?rev=1073111&r1=1073110&r2=1073111&view=diff
==============================================================================
--- directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolEncoder.java
(original)
+++ directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/protocol/mina/LdapProtocolEncoder.java
Mon Feb 21 18:53:04 2011
@@ -32,7 +32,7 @@ import org.apache.mina.filter.codec.Prot
 
 
 /**
- * A LDAP message decoder. It is based on shared-ldap decoder.
+ * A LDAP message encoder. It is based on shared-ldap encoder.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */

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=1073111&r1=1073110&r2=1073111&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 18:53:04 2011
@@ -24,13 +24,11 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Queue;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 import org.apache.directory.shared.asn1.DecoderException;
 import org.apache.directory.shared.asn1.ber.Asn1Container;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
@@ -46,10 +44,12 @@ import org.apache.mina.core.filterchain.
 import org.apache.mina.core.session.DummySession;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.AbstractProtocolDecoderOutput;
-import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * A global Ldap Decoder test
@@ -101,10 +101,9 @@ public class LdapDecoderTest extends Abs
     @Test
     public void testDecodeFull()
     {
-        LdapDecoder ldapDecoder = new LdapDecoder();
+        Asn1Decoder ldapDecoder = new Asn1Decoder();
         LdapMessageContainer<MessageDecorator<? extends Message>> container =

             new LdapMessageContainer<MessageDecorator<? extends Message>>( codec
);
-        ldapDecoder.setLdapMessageContainer( container );
 
         ByteBuffer stream = ByteBuffer.allocate( 0x35 );
         stream.put( new byte[]
@@ -126,13 +125,10 @@ public class LdapDecoderTest extends Abs
 
         stream.flip();
 
-        InputStream is = new ByteArrayInputStream(stream.array());
-        Object result = null;
-
         // Decode a BindRequest PDU
         try
         {
-            result = ldapDecoder.decode(null, is);
+            ldapDecoder.decode( stream, container );
         }
         catch ( DecoderException de )
         {
@@ -140,8 +136,10 @@ public class LdapDecoderTest extends Abs
             fail( de.getMessage() );
         }
 
+        assertEquals( TLVStateEnum.PDU_DECODED, container.getState() );
+
         // Check the decoded PDU
-        BindRequest bindRequest = (BindRequest) result;
+        BindRequest bindRequest = (BindRequest)container.getMessage();
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
@@ -198,12 +196,12 @@ public class LdapDecoderTest extends Abs
 
         stream.flip();
 
-        ProtocolDecoderOutput result = new LdapProtocolDecoderOutput();
+        List<Message> result = new ArrayList<Message>();
 
         // Decode a BindRequest PDU
         try
         {
-            ldapDecoder.decode( dummySession, stream, result );
+            ldapDecoder.decode( stream, container, result );
         }
         catch ( DecoderException de )
         {
@@ -212,7 +210,7 @@ public class LdapDecoderTest extends Abs
         }
 
         // Check the decoded PDU
-        BindRequest bindRequest = (BindRequest) ( ( LdapProtocolDecoderOutput ) result ).getMessage();
+        BindRequest bindRequest = (BindRequest) ( result.get( 0 ) );
 
         assertEquals( 1, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );
@@ -221,7 +219,7 @@ public class LdapDecoderTest extends Abs
         assertEquals( "password", Strings.utf8ToString(bindRequest.getCredentials()) );
         
         // The second message
-        bindRequest = ( BindRequest ) ( ( LdapProtocolDecoderOutput ) result ).getMessage();
+        bindRequest = ( BindRequest ) ( result.get( 1 ) );
 
         assertEquals( 2, bindRequest.getMessageId() );
         assertTrue( bindRequest.isVersion3() );



Mime
View raw message