directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 36710 - in incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src: java/org/apache/snickers/ldap/encoder java/org/apache/snickers/ldap/encoder/bind test/org/apache/snickers/ldap/encoder/bind
Date Sun, 22 Aug 2004 23:32:27 GMT
Author: akarasulu
Date: Sun Aug 22 16:32:27 2004
New Revision: 36710

Modified:
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/LdapResultEncoder.java
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/ReferralEncoder.java
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/bind/BindResponseEncoder.java
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/bind/BindResponseEncoderTest.java
Log:
Commit changes ...

 o correctly assemble tuple nodes in ReferralEncoder 
 o correctly assemble tuple nodes in LdapResultEncoder
 o implemented BindResponseEncoder
 o wrote test case using Snacc4J on BindResponseEncoder
 
 Need to clean up test case and generalize for easy round trip PDU generation
 and testing.  It might also be a good idea to start assembling the PDU 
 various comparison tests into a JUnit addon for reuse in testing.  This 
 I'll add to the JIRA.
 


Modified: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/LdapResultEncoder.java
==============================================================================
--- incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/LdapResultEncoder.java
(original)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/LdapResultEncoder.java
Sun Aug 22 16:32:27 2004
@@ -45,27 +45,39 @@
      */
     public void encode( DefaultMutableTupleNode top, LdapResult result )
     {
-        top.addLast( ( DefaultMutableTupleNode ) EncoderUtils.encode(
-                UniversalTag.ENUMERATED, result.getResultCode().getValue() ) );
-        top.addLast( ( DefaultMutableTupleNode ) EncoderUtils.encode(
-                result.getMatchedDn() ) );
+        DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+                EncoderUtils.encode( UniversalTag.ENUMERATED,
+                        result.getResultCode().getValue() );
+        top.addLast( child );
+        child.setParent( top );
+
+        child = ( DefaultMutableTupleNode ) EncoderUtils.encode(
+                result.getMatchedDn() );
+        top.addLast( child );
+        child.setParent( top );
 
         if ( result.getErrorMessage() != null )
         {
-            top.addLast( ( DefaultMutableTupleNode ) EncoderUtils.encode(
-                    result.getErrorMessage() ) );
+            child = ( DefaultMutableTupleNode ) EncoderUtils.encode(
+                    result.getErrorMessage() );
+            top.addLast( child );
+            child.setParent( top );
         }
         else
         {
-            top.addLast( ( DefaultMutableTupleNode )
-                    EncoderUtils.encode( "" ) );
+            child = ( DefaultMutableTupleNode ) EncoderUtils.encode( "" );
+            top.addLast( child );
+            child.setParent( top );
         }
 
         if ( result.getReferral() != null &&
                 result.getReferral().getLdapUrls().size() > 0 )
         {
-            top.addLast( ( DefaultMutableTupleNode )
-                    ReferralEncoder.INSTANCE.encode( result.getReferral() ) );
+
+            child = ( DefaultMutableTupleNode )
+                    ReferralEncoder.INSTANCE.encode( result.getReferral() );
+            top.addLast( child );
+            child.setParent( top );
         }
     }
 }

Modified: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/ReferralEncoder.java
==============================================================================
--- incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/ReferralEncoder.java
(original)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/ReferralEncoder.java
Sun Aug 22 16:32:27 2004
@@ -59,8 +59,10 @@
         Iterator list = ref.getLdapUrls().iterator();
         while( list.hasNext() )
         {
-            refs.addLast( ( DefaultMutableTupleNode ) EncoderUtils.encode(
-                ( String ) list.next() ) );
+            DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+                    EncoderUtils.encode( ( String ) list.next() );
+            refs.addLast( child );
+            child.setParent( refs );
         }
 
         return refs;

Modified: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/bind/BindResponseEncoder.java
==============================================================================
--- incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/bind/BindResponseEncoder.java
(original)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/bind/BindResponseEncoder.java
Sun Aug 22 16:32:27 2004
@@ -61,8 +61,10 @@
         top.getTuple().setLength( Length.INDEFINATE );
 
         // Create and add the message id to response PDU
-        top.addLast( ( DefaultMutableTupleNode ) EncoderUtils.encode(
-                response.getMessageId() ) );
+        DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+                EncoderUtils.encode( response.getMessageId() );
+        top.addLast( child );
+        child.setParent( top );
 
         // Create the bind response sequence of TLV tuple
         DefaultMutableTupleNode bindresp =
@@ -79,6 +81,8 @@
             throw new NotImplementedException( "SASL binds not implemented" ) ;
         }
 
+        top.addLast( bindresp );
+        bindresp.setParent( top );
         return top;
     }
 }

Modified: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/bind/BindResponseEncoderTest.java
==============================================================================
--- incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/bind/BindResponseEncoderTest.java
(original)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/bind/BindResponseEncoderTest.java
Sun Aug 22 16:32:27 2004
@@ -17,11 +17,18 @@
 package org.apache.snickers.ldap.encoder.bind;
 
 import junit.framework.TestCase;
-import org.apache.ldap.common.message.BindResponseImpl;
-import org.apache.ldap.common.message.LdapResultImpl;
-import org.apache.ldap.common.message.ResultCodeEnum;
+import org.apache.ldap.common.message.*;
+import org.apache.ldap.common.message.spi.Provider;
 import org.apache.snickers.ber.TupleNode;
 import org.apache.snickers.ber.DeterminateLengthVisitor;
+import org.apache.snickers.ber.TupleEncodingVisitor;
+import org.apache.commons.codec.stateful.CallbackHistory;
+import org.apache.commons.codec.stateful.EncoderCallback;
+import org.apache.commons.codec.stateful.StatefulEncoder;
+
+import java.nio.ByteBuffer;
+import java.util.Properties;
+import java.io.ByteArrayInputStream;
 
 
 /**
@@ -31,7 +38,21 @@
  *         Project</a> $Rev$
  */
 public class BindResponseEncoderTest extends TestCase
+        implements EncoderCallback
 {
+    ByteBuffer accumulator = ByteBuffer.wrap( new byte[128] );
+
+
+    /**
+     * Callback to deliver a fully encoded object.
+     *
+     * @param encoder the stateful encoder driving the callback
+     * @param encoded the object that was encoded
+     */
+    public void encodeOccurred( StatefulEncoder encoder, Object encoded )
+    {
+        accumulator.put( ( ByteBuffer ) encoded );
+    }
 
 
     public void testEncode()
@@ -44,5 +65,19 @@
         TupleNode node = BindResponseEncoder.INSTANCE.encode( response );
         DeterminateLengthVisitor visitor = new DeterminateLengthVisitor();
         node.accept( visitor );
+
+        TupleEncodingVisitor encoder = new TupleEncodingVisitor();
+        encoder.setCallback( this );
+        node.accept( encoder );
+
+        Properties env = new Properties();
+        env.setProperty( Provider.BERLIB_PROVIDER,
+                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
+        MessageDecoder decoder = new MessageDecoder( env );
+
+        ByteArrayInputStream in = new ByteArrayInputStream( accumulator.array(),
+                0, accumulator.position() );
+        Message msg = decoder.decode( null, in );
+        BindResponse decodedResponse = ( BindResponse ) msg;
     }
 }

Mime
View raw message