directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1137337 - in /directory/shared/trunk/ldap: codec/core/src/main/java/org/apache/directory/shared/ldap/codec/actions/ldapResult/ codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/ codec/core/src/test/java/org/apache/...
Date Sun, 19 Jun 2011 11:10:23 GMT
Author: kayyagari
Date: Sun Jun 19 11:10:22 2011
New Revision: 1137337

URL: http://svn.apache.org/viewvc?rev=1137337&view=rev
Log:
o fixed LdapResult codec to handle result codes of length more than one bye added a test case
for checking this
o removed the switch case from StoreResultCode(this is duplicating the logic of ResultCodeEnum.getResultCode())
o updated the toString() method of LdapResultImpl to show the eSyncRefreshRequired result
code

Modified:
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/actions/ldapResult/StoreResultCode.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java
    directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultDoneTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java

Modified: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/actions/ldapResult/StoreResultCode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/actions/ldapResult/StoreResultCode.java?rev=1137337&r1=1137336&r2=1137337&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/actions/ldapResult/StoreResultCode.java
(original)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/actions/ldapResult/StoreResultCode.java
Sun Jun 19 11:10:22 2011
@@ -79,7 +79,7 @@ public class StoreResultCode extends Gra
 
         try
         {
-            resultCode = ResultCodeEnum.getResultCode( IntegerDecoder.parse(value, 0, ResultCodeEnum.UNKNOWN
+            resultCode = ResultCodeEnum.getResultCode( IntegerDecoder.parse(value, 0, ResultCodeEnum.E_SYNC_REFRESH_REQUIRED
                     .getResultCode()) );
         }
         catch ( IntegerDecoderException ide )
@@ -89,58 +89,6 @@ public class StoreResultCode extends Gra
             throw new DecoderException( ide.getMessage() );
         }
 
-        // Treat the 'normal' cases !
-        switch ( resultCode )
-        {
-            case SUCCESS:
-            case OPERATIONS_ERROR:
-            case PROTOCOL_ERROR:
-            case TIME_LIMIT_EXCEEDED:
-            case SIZE_LIMIT_EXCEEDED:
-            case COMPARE_FALSE:
-            case COMPARE_TRUE:
-            case AUTH_METHOD_NOT_SUPPORTED:
-            case STRONG_AUTH_REQUIRED:
-            case REFERRAL:
-            case ADMIN_LIMIT_EXCEEDED:
-            case UNAVAILABLE_CRITICAL_EXTENSION:
-            case CONFIDENTIALITY_REQUIRED:
-            case SASL_BIND_IN_PROGRESS:
-            case NO_SUCH_ATTRIBUTE:
-            case UNDEFINED_ATTRIBUTE_TYPE:
-            case INAPPROPRIATE_MATCHING:
-            case CONSTRAINT_VIOLATION:
-            case ATTRIBUTE_OR_VALUE_EXISTS:
-            case INVALID_ATTRIBUTE_SYNTAX:
-            case NO_SUCH_OBJECT:
-            case ALIAS_PROBLEM:
-            case INVALID_DN_SYNTAX:
-            case ALIAS_DEREFERENCING_PROBLEM:
-            case INAPPROPRIATE_AUTHENTICATION:
-            case INVALID_CREDENTIALS:
-            case INSUFFICIENT_ACCESS_RIGHTS:
-            case BUSY:
-            case UNAVAILABLE:
-            case UNWILLING_TO_PERFORM:
-            case LOOP_DETECT:
-            case NAMING_VIOLATION:
-            case OBJECT_CLASS_VIOLATION:
-            case NOT_ALLOWED_ON_NON_LEAF:
-            case NOT_ALLOWED_ON_RDN:
-            case ENTRY_ALREADY_EXISTS:
-            case AFFECTS_MULTIPLE_DSAS:
-            case CANCELED:
-            case CANNOT_CANCEL:
-            case TOO_LATE:
-            case NO_SUCH_OPERATION:
-                break;
-
-            default:
-                LOG.warn( "The resultCode " + resultCode + " is unknown." );
-                resultCode = ResultCodeEnum.OTHER;
-                break;
-        }
-
         if ( IS_DEBUG )
         {
             LOG.debug( "The result code is set to " + resultCode );

Modified: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java?rev=1137337&r1=1137336&r2=1137337&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java
(original)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java
Sun Jun 19 11:10:22 2011
@@ -25,7 +25,6 @@ import java.nio.ByteBuffer;
 
 import org.apache.directory.shared.asn1.EncoderException;
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
-import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.codec.api.Decorator;
@@ -234,8 +233,8 @@ public class LdapResultDecorator impleme
     {
         int ldapResultLength = 0;
 
-        // The result code : always 3 bytes
-        ldapResultLength = 1 + 1 + 1;
+        // The result code
+        ldapResultLength = 1 + 1 + Value.getNbBytes( getResultCode().getValue() );
 
         // The matchedDN length
         if ( getMatchedDn() == null )
@@ -282,9 +281,7 @@ public class LdapResultDecorator impleme
         try
         {
             // The result code
-            buffer.put( UniversalTag.ENUMERATED.getValue() );
-            buffer.put( ( byte ) 1 );
-            buffer.put( ( byte ) getResultCode().getValue() );
+            Value.encodeEnumerated( buffer, getResultCode().getValue() );
         }
         catch ( BufferOverflowException boe )
         {

Modified: directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultDoneTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultDoneTest.java?rev=1137337&r1=1137336&r2=1137337&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultDoneTest.java
(original)
+++ directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchResultDoneTest.java
Sun Jun 19 11:10:22 2011
@@ -249,4 +249,73 @@ public class SearchResultDoneTest extend
 
         fail( "We should not reach this point" );
     }
+    
+    
+    /**
+     * Test the decoding of a SearchResultDone with a result code of length 2 bytes
+     */
+    @Test
+    public void testDecodeSearchResultDoneEsyncRefresh()
+    {
+        Asn1Decoder ldapDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x0F );
+
+        stream.put( new byte[]
+            { 0x30, 0x0D, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x65, 0x08, // CHOICE { ..., searchResDone SearchResultDone, ...
+                // SearchResultDone ::= [APPLICATION 5] LDAPResult
+                0x0A, 0x02, 0x10, 0x00, // LDAPResult ::= SEQUENCE {
+                // resultCode ENUMERATED {
+                // success (0), ...
+                // },
+                0x04, 0x00, // matchedDN LDAPDN,
+                0x04, 0x00 // errorMessage LDAPString,
+            // referral [3] Referral OPTIONAL }
+            // }
+            } );
+
+        String decodedPdu = Strings.dumpBytes(stream.array());
+        stream.flip();
+
+        // Allocate a SearchResultDone Container
+        LdapMessageContainer<SearchResultDoneDecorator> ldapMessageContainer = 
+            new LdapMessageContainer<SearchResultDoneDecorator>( codec );
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+
+        SearchResultDone searchResultDone = ldapMessageContainer.getMessage();
+
+        assertEquals( 1, searchResultDone.getMessageId() );
+        assertEquals( ResultCodeEnum.E_SYNC_REFRESH_REQUIRED, searchResultDone.getLdapResult().getResultCode()
);
+        assertEquals( "", searchResultDone.getLdapResult().getMatchedDn().getName() );
+        assertEquals( "", searchResultDone.getLdapResult().getDiagnosticMessage() );
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = encoder.encodeMessage( searchResultDone );
+
+            // Check the length
+            assertEquals( 0x0F, bb.limit() );
+
+            String encodedPdu = Strings.dumpBytes(bb.array());
+
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java?rev=1137337&r1=1137336&r2=1137337&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java
Sun Jun 19 11:10:22 2011
@@ -399,6 +399,10 @@ public class LdapResultImpl implements L
                 sb.append( " affectsMultipleDSAs -- new\n" );
                 break;
 
+            case E_SYNC_REFRESH_REQUIRED:
+                sb.append( " eSyncRefreshRequired\n" );
+                break;
+
             case OTHER:
                 sb.append( " other\n" );
                 break;



Mime
View raw message