directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r749713 - in /directory: apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/lookup/ shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/ shared/trunk/ldap/src/main/java/org/apache/director...
Date Tue, 03 Mar 2009 19:49:18 GMT
Author: elecharny
Date: Tue Mar  3 19:49:17 2009
New Revision: 749713

URL: http://svn.apache.org/viewvc?rev=749713&view=rev
Log:
o Added the IntermediateResponse codec plus tests
o Fixed a tests which was failing after the addition of some operational attributes

Added:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/intermediate/
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/intermediate/IntermediateResponse.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/intermediate/
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/intermediate/IntermediateResponseTest.java
Modified:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/lookup/LookupIT.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapConstants.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessage.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapStatesEnum.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/lookup/LookupIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/lookup/LookupIT.java?rev=749713&r1=749712&r2=749713&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/lookup/LookupIT.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/lookup/LookupIT.java Tue Mar  3 19:49:17 2009
@@ -91,7 +91,7 @@
         assertNotNull( entry );
         
         // We should have 5 attributes
-        assertEquals( 5, entry.size() ); 
+        assertEquals( 7, entry.size() ); 
 
         // Check that all the user attributes are present
         assertEquals( "test", entry.get( "cn" ).getString() );

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapConstants.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapConstants.java?rev=749713&r1=749712&r2=749713&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapConstants.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapConstants.java Tue Mar  3 19:49:17 2009
@@ -99,6 +99,8 @@
 
     public static final byte EXTENDED_RESPONSE_TAG = 0x78;
 
+    public static final byte INTERMEDIATE_RESPONSE_TAG = 0x79;
+
     // The following tags are ints, because bytes above 127 are negative
     // numbers, and we can't use them as array indexes.
     public static final int BIND_REQUEST_SIMPLE_TAG = 0x80;
@@ -135,6 +137,10 @@
 
     public static final int AND_FILTER_TAG = 0xA0;
 
+    public static final int INTERMEDIATE_RESPONSE_NAME_TAG = 0x80;
+
+    public static final int INTERMEDIATE_RESPONSE_VALUE_TAG = 0x81;
+
     public static final int OR_FILTER_TAG = 0xA1;
 
     public static final int NOT_FILTER_TAG = 0xA2;
@@ -195,6 +201,8 @@
     public static final int SEARCH_RESULT_REFERENCE = 18;
 
     public static final int UNBIND_REQUEST = 19;
+    
+    public static final int INTERMEDIATE_RESPONSE = 20;
 
     public static final int UNKNOWN = -1; // Just in case ...
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessage.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessage.java?rev=749713&r1=749712&r2=749713&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessage.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessage.java Tue Mar  3 19:49:17 2009
@@ -43,6 +43,7 @@
 import org.apache.directory.shared.ldap.codec.del.DelResponse;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedRequest;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedResponse;
+import org.apache.directory.shared.ldap.codec.intermediate.IntermediateResponse;
 import org.apache.directory.shared.ldap.codec.modify.ModifyRequest;
 import org.apache.directory.shared.ldap.codec.modify.ModifyResponse;
 import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequest;
@@ -216,44 +217,67 @@
         {
             case LdapConstants.ABANDON_REQUEST:
                 return "ABANDON_REQUEST";
+                
             case LdapConstants.ADD_REQUEST:
                 return "ADD_REQUEST";
+                
             case LdapConstants.ADD_RESPONSE:
                 return "ADD_RESPONSE";
+                
             case LdapConstants.BIND_REQUEST:
                 return "BIND_REQUEST";
+                
             case LdapConstants.BIND_RESPONSE:
                 return "BIND_RESPONSE";
+                
             case LdapConstants.COMPARE_REQUEST:
                 return "COMPARE_REQUEST";
+                
             case LdapConstants.COMPARE_RESPONSE:
                 return "COMPARE_RESPONSE";
+                
             case LdapConstants.DEL_REQUEST:
                 return "DEL_REQUEST";
+                
             case LdapConstants.DEL_RESPONSE:
                 return "DEL_RESPONSE";
+                
             case LdapConstants.EXTENDED_REQUEST:
                 return "EXTENDED_REQUEST";
+                
             case LdapConstants.EXTENDED_RESPONSE:
                 return "EXTENDED_RESPONSE";
+                
+            case LdapConstants.INTERMEDIATE_RESPONSE:
+                return "INTERMEDIATE_RESPONSE";
+                
             case LdapConstants.MODIFYDN_REQUEST:
                 return "MODIFYDN_REQUEST";
+                
             case LdapConstants.MODIFYDN_RESPONSE:
                 return "MODIFYDN_RESPONSE";
+                
             case LdapConstants.MODIFY_REQUEST:
                 return "MODIFY_REQUEST";
+                
             case LdapConstants.MODIFY_RESPONSE:
                 return "MODIFY_RESPONSE";
+                
             case LdapConstants.SEARCH_REQUEST:
                 return "SEARCH_REQUEST";
+                
             case LdapConstants.SEARCH_RESULT_DONE:
                 return "SEARCH_RESULT_DONE";
+                
             case LdapConstants.SEARCH_RESULT_ENTRY:
                 return "SEARCH_RESULT_ENTRY";
+                
             case LdapConstants.SEARCH_RESULT_REFERENCE:
                 return "SEARCH_RESULT_REFERENCE";
+                
             case LdapConstants.UNBIND_REQUEST:
                 return "UNBIND_REQUEST";
+                
             default:
                 return "UNKNOWN";
         }
@@ -404,6 +428,18 @@
 
 
     /**
+     * Get a IntermediateResponse ldapObject, assuming that the caller knows that it
+     * is the LdapMessage exact type.
+     * 
+     * @return Returns the IntermediateResponse ldapObject.
+     */
+    public IntermediateResponse getIntermediateResponse()
+    {
+        return ( IntermediateResponse ) protocolOp;
+    }
+
+
+    /**
      * Get a ModifyDNRequest ldapObject, assuming that the caller knows that it
      * is the LdapMessage exact type.
      * 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java?rev=749713&r1=749712&r2=749713&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java Tue Mar  3 19:49:17 2009
@@ -83,6 +83,7 @@
 import org.apache.directory.shared.ldap.codec.del.DelResponse;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedRequest;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedResponse;
+import org.apache.directory.shared.ldap.codec.intermediate.IntermediateResponse;
 import org.apache.directory.shared.ldap.codec.modify.ModifyRequest;
 import org.apache.directory.shared.ldap.codec.modify.ModifyResponse;
 import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequest;
@@ -3250,6 +3251,208 @@
             LdapStatesEnum.RESPONSE_STATE, LdapStatesEnum.CONTROLS_STATE, LdapConstants.CONTROLS_TAG,
             new ControlsInitAction() );
 
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from Message Id to IntermediateResponse Message
+        // --------------------------------------------------------------------------------------------
+        // LdapMessage ::= ... IntermediateResponse ...
+        // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+        //
+        // Creates the IntermediateResponse object
+        super.transitions[LdapStatesEnum.MESSAGE_ID_STATE][LdapConstants.INTERMEDIATE_RESPONSE_TAG] = new GrammarTransition(
+            LdapStatesEnum.MESSAGE_ID_STATE, LdapStatesEnum.INTERMEDIATE_RESPONSE_STATE, LdapConstants.INTERMEDIATE_RESPONSE_TAG,
+            new GrammarAction( "Init Intermediate Response" )
+            {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+
+                    LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
+                    LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage();
+
+                    // We can allocate the IntermediateResponse Object
+                    ldapMessage.setProtocolOP( new IntermediateResponse() );
+                }
+            } );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from IntermediateResponse Message to ResponseName
+        // --------------------------------------------------------------------------------------------
+        // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+        //     responseName [0] LDAPOID OPTIONAL,
+        //     ...
+        //
+        // Stores the name
+        super.transitions[LdapStatesEnum.INTERMEDIATE_RESPONSE_STATE][LdapConstants.INTERMEDIATE_RESPONSE_NAME_TAG] = new GrammarTransition(
+            LdapStatesEnum.INTERMEDIATE_RESPONSE_STATE, LdapStatesEnum.INTERMEDIATE_RESPONSE_NAME_STATE,
+            LdapConstants.INTERMEDIATE_RESPONSE_NAME_TAG, new GrammarAction( "Store response name" )
+            {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+
+                    LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
+                    LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage();
+
+                    // We can get the IntermediateResponse Object
+                    IntermediateResponse intermediateResponse = ldapMessage.getIntermediateResponse();
+
+                    // Get the Value and store it in the IntermediateResponse
+                    TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+                    // We have to handle the special case of a 0 length matched
+                    // OID.
+                    if ( tlv.getLength() == 0 )
+                    {
+                        log.error( "The name must not be null" );
+                        // This will generate a PROTOCOL_ERROR                        
+                        throw new DecoderException( "The name must not be null" );
+                    }
+                    else
+                    {
+                        byte[] responseNameBytes = tlv.getValue().getData();
+
+                        try
+                        {
+                            OID oid = new OID( StringTools.utf8ToString( responseNameBytes ) );
+                            intermediateResponse.setResponseName( oid );
+                        }
+                        catch ( DecoderException de )
+                        {
+                            String msg = "The Intermediate Response name is not a valid OID : "
+                                + StringTools.utf8ToString( responseNameBytes ) + " ("
+                                + StringTools.dumpBytes( responseNameBytes ) + ") is invalid";
+                            log.error( "{} : {}", msg, de.getMessage() );
+
+                            // Rethrow the exception, we will get a PROTOCOL_ERROR
+                            throw de;
+                        }
+                    }
+
+                    // We can have an END transition
+                    ldapMessageContainer.grammarEndAllowed( true );
+
+                    if ( IS_DEBUG )
+                    {
+                        log.debug( "OID read : {}", intermediateResponse.getResponseName() );
+                    }
+                }
+            } );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from IntermediateResponse Message to ResponseValue (ResponseName is null)
+        // --------------------------------------------------------------------------------------------
+        // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+        //     ...
+        //     responseValue [1] OCTET STRING OPTIONAL
+        //     }
+        //
+        // Stores the value
+        super.transitions[LdapStatesEnum.INTERMEDIATE_RESPONSE_STATE][LdapConstants.INTERMEDIATE_RESPONSE_VALUE_TAG] = new GrammarTransition(
+            LdapStatesEnum.INTERMEDIATE_RESPONSE_STATE, LdapStatesEnum.INTERMEDIATE_RESPONSE_VALUE_STATE,
+            LdapConstants.INTERMEDIATE_RESPONSE_VALUE_TAG, new GrammarAction( "Store response value" )
+            {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+
+                    LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
+                    LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage();
+
+                    // We can get the IntermediateResponse Object
+                    IntermediateResponse intermediateResponse = ldapMessage.getIntermediateResponse();
+
+                    // Get the Value and store it in the IntermediateResponse
+                    TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+                    // We have to handle the special case of a 0 length matched
+                    // value
+                    if ( tlv.getLength() == 0 )
+                    {
+                        intermediateResponse.setResponseValue( StringTools.EMPTY_BYTES );
+                    }
+                    else
+                    {
+                        intermediateResponse.setResponseValue( tlv.getValue().getData() );
+                    }
+
+                    // We can have an END transition
+                    ldapMessageContainer.grammarEndAllowed( true );
+
+                    if ( IS_DEBUG )
+                    {
+                        log.debug( "Value read : {}", StringTools.dumpBytes( intermediateResponse.getResponseValue() ) );
+                    }
+                }
+            } );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from ResponseName to ResponseValue
+        // --------------------------------------------------------------------------------------------
+        // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+        //     ...
+        //     responseValue  [1] OCTET STRING OPTIONAL }
+        //
+        // Stores the value
+        super.transitions[LdapStatesEnum.INTERMEDIATE_RESPONSE_NAME_STATE][LdapConstants.INTERMEDIATE_RESPONSE_VALUE_TAG] = new GrammarTransition(
+            LdapStatesEnum.INTERMEDIATE_RESPONSE_NAME_STATE, LdapStatesEnum.INTERMEDIATE_RESPONSE_VALUE_STATE,
+            LdapConstants.INTERMEDIATE_RESPONSE_VALUE_TAG, new GrammarAction( "Store value" )
+            {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+
+                    LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
+                    LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage();
+
+                    // We can allocate the ExtendedRequest Object
+                    IntermediateResponse intermediateResponse = ldapMessage.getIntermediateResponse();
+
+                    // Get the Value and store it in the IntermediateResponse
+                    TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+                    // We have to handle the special case of a 0 length matched
+                    // value
+                    if ( tlv.getLength() == 0 )
+                    {
+                        intermediateResponse.setResponseValue( StringTools.EMPTY_BYTES );
+                    }
+                    else
+                    {
+                        intermediateResponse.setResponseValue( tlv.getValue().getData() );
+                    }
+
+                    // We can have an END transition
+                    ldapMessageContainer.grammarEndAllowed( true );
+
+                    if ( IS_DEBUG )
+                    {
+                        log.debug( "Response value : {}", intermediateResponse.getResponseValue() );
+                    }
+                }
+            } );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from ResponseName to Controls
+        // --------------------------------------------------------------------------------------------
+        //         intermediateResponse   IntermediateResponse,
+        //         ... },
+        //     controls       [0] Controls OPTIONAL }
+        //
+        // Stores the value
+        super.transitions[LdapStatesEnum.INTERMEDIATE_RESPONSE_NAME_STATE][LdapConstants.CONTROLS_TAG] = new GrammarTransition(
+            LdapStatesEnum.INTERMEDIATE_RESPONSE_NAME_STATE, LdapStatesEnum.CONTROLS_STATE, LdapConstants.CONTROLS_TAG,
+            new ControlsInitAction() );
+
+        // --------------------------------------------------------------------------------------------
+        // Transition from ResponseValue to Controls
+        // --------------------------------------------------------------------------------------------
+        //         intermediateResponse   IntermediateResponse,
+        //         ... },
+        //     controls       [0] Controls OPTIONAL }
+        //
+        // Stores the value
+        super.transitions[LdapStatesEnum.INTERMEDIATE_RESPONSE_VALUE_STATE][LdapConstants.CONTROLS_TAG] = new GrammarTransition(
+            LdapStatesEnum.INTERMEDIATE_RESPONSE_VALUE_STATE, LdapStatesEnum.CONTROLS_STATE, LdapConstants.CONTROLS_TAG,
+            new ControlsInitAction() );
+
+
         // --------------------------------------------------------------------------------------------
         // Controls
         // --------------------------------------------------------------------------------------------

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapStatesEnum.java?rev=749713&r1=749712&r2=749713&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapStatesEnum.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapStatesEnum.java Tue Mar  3 19:49:17 2009
@@ -147,8 +147,12 @@
     public static final int CONTROL_TYPE_STATE =                109;
     public static final int CRITICALITY_STATE =                 110;
     public static final int CONTROL_VALUE_STATE =               111;
+    public static final int INTERMEDIATE_RESPONSE_STATE =       112;
+    public static final int INTERMEDIATE_RESPONSE_NAME_STATE =  113;
+    public static final int INTERMEDIATE_RESPONSE_VALUE_STATE = 114;
     
-    public static final int LAST_LDAP_STATE = 112;
+    
+    public static final int LAST_LDAP_STATE = 115;
 
     // =========================================================================
     // States debug strings
@@ -269,6 +273,9 @@
         "CONTROL_TYPE_STATE",
         "CRITICALITY_STATE",
         "CONTROL_VALUE_STATE",
+        "INTERMEDIATE_RESPONSE_STATE",
+        "INTERMEDIATE_RESPONSE_NAME_STATE",
+        "INTERMEDIATE_RESPONSE_VALUE_STATE",
         "LAST_LDAP_STATE",
         };
 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java?rev=749713&r1=749712&r2=749713&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java Tue Mar  3 19:49:17 2009
@@ -899,15 +899,16 @@
                 snickersMessage = transformBindResponse( twixMessage, messageId );
                 break;
 
-            case ( LdapConstants.SEARCH_RESULT_ENTRY  ):
-            case ( LdapConstants.SEARCH_RESULT_DONE  ):
-            case ( LdapConstants.SEARCH_RESULT_REFERENCE  ):
-            case ( LdapConstants.MODIFY_RESPONSE  ):
-            case ( LdapConstants.ADD_RESPONSE  ):
-            case ( LdapConstants.DEL_RESPONSE  ):
-            case ( LdapConstants.MODIFYDN_RESPONSE  ):
-            case ( LdapConstants.COMPARE_RESPONSE  ):
-            case ( LdapConstants.EXTENDED_RESPONSE  ):
+            case ( LdapConstants.SEARCH_RESULT_ENTRY ):
+            case ( LdapConstants.SEARCH_RESULT_DONE ):
+            case ( LdapConstants.SEARCH_RESULT_REFERENCE ):
+            case ( LdapConstants.MODIFY_RESPONSE ):
+            case ( LdapConstants.ADD_RESPONSE ):
+            case ( LdapConstants.DEL_RESPONSE ):
+            case ( LdapConstants.MODIFYDN_RESPONSE ):
+            case ( LdapConstants.COMPARE_RESPONSE ):
+            case ( LdapConstants.EXTENDED_RESPONSE ):
+            case ( LdapConstants.INTERMEDIATE_RESPONSE ):
                 // Nothing to do !
                 break;
 

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/intermediate/IntermediateResponse.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/intermediate/IntermediateResponse.java?rev=749713&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/intermediate/IntermediateResponse.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/intermediate/IntermediateResponse.java Tue Mar  3 19:49:17 2009
@@ -0,0 +1,252 @@
+/*
+ *  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.intermediate;
+
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.codec.LdapConstants;
+import org.apache.directory.shared.ldap.codec.LdapResponse;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A IntermediateResponse Message. Its syntax is :
+ *   IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+ *              responseName     [0] LDAPOID OPTIONAL,
+ *              responseValue    [1] OCTET STRING OPTIONAL }
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 664290 $, $Date: 2008-06-07 08:28:06 +0200 (Sat, 07 Jun 2008) $, 
+ */
+public class IntermediateResponse extends LdapResponse
+{
+    // ~ Instance fields
+    // ----------------------------------------------------------------------------
+
+    /** The name */
+    private OID responseName;
+
+    /** The response */
+    private byte[] responseValue;
+
+    /** The extended response length */
+    private int intermediateResponseLength;
+
+    /** The OID length */
+    private int responseNameLength;
+
+
+    // ~ Constructors
+    // -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new IntermediateResponse object.
+     */
+    public IntermediateResponse()
+    {
+        super();
+    }
+
+
+    // ~ Methods
+    // ------------------------------------------------------------------------------------
+
+    /**
+     * Get the message type
+     * 
+     * @return Returns the type.
+     */
+    public int getMessageType()
+    {
+        return LdapConstants.INTERMEDIATE_RESPONSE;
+    }
+
+
+    /**
+     * Get the intermediate response name
+     * 
+     * @return Returns the name.
+     */
+    public String getResponseName()
+    {
+        return ( ( responseName == null ) ? "" : responseName.toString() );
+    }
+
+
+    /**
+     * Set the intermediate response name
+     * 
+     * @param responseName The name to set.
+     */
+    public void setResponseName( OID responseName )
+    {
+        this.responseName = responseName;
+    }
+
+
+    /**
+     * Get the intermediate response value
+     * 
+     * @return Returns the intermediate response value.
+     */
+    public byte[] getResponseValue()
+    {
+        return responseValue;
+    }
+
+
+    /**
+     * Set the intermediate response value
+     * 
+     * @param responseValue The intermediate response value to set.
+     */
+    public void setResponseValue( byte[] responseValue )
+    {
+        this.responseValue = responseValue;
+    }
+
+
+    /**
+     * Compute the intermediateResponse length
+     * 
+     * intermediateResponse :
+     * 
+     * 0x79 L1
+     *  |
+     * [+--> 0x80 L2 name
+     * [+--> 0x81 L3 response]]
+     * 
+     * L1 = [ + Length(0x80) + Length(L2) + L2
+     *      [ + Length(0x81) + Length(L3) + L3]]
+     * 
+     * Length(IntermediateResponse) = Length(0x79) + Length(L1) + L1
+     * 
+     * @return The IntermediateResponse length
+     */
+    public int computeLength()
+    {
+        intermediateResponseLength = 0;
+
+        if ( responseName != null )
+        {
+            responseNameLength = responseName.toString().length();
+            intermediateResponseLength += 1 + TLV.getNbBytes( responseNameLength ) + responseNameLength;
+        }
+
+        if ( responseValue != null )
+        {
+            intermediateResponseLength += 1 + TLV.getNbBytes( responseValue.length )
+                    + responseValue.length;
+        }
+
+        return 1 + TLV.getNbBytes( intermediateResponseLength ) + intermediateResponseLength;
+    }
+
+
+    /**
+     * Encode the IntermediateResponse message to a PDU. 
+     * IntermediateResponse :
+     *   0x79 LL
+     *     [0x80 LL response name]
+     *     [0x81 LL responseValue]
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try
+        {
+            // The IntermediateResponse Tag
+            buffer.put( LdapConstants.INTERMEDIATE_RESPONSE_TAG );
+            buffer.put( TLV.getBytes( intermediateResponseLength ) );
+
+            // The responseName, if any
+            if ( responseName != null )
+            {
+                buffer.put( ( byte ) LdapConstants.INTERMEDIATE_RESPONSE_NAME_TAG );
+                buffer.put( TLV.getBytes( responseNameLength ) );
+
+                if ( responseName.getOIDLength() != 0 )
+                {
+                    buffer.put( StringTools.getBytesUtf8( responseName.toString() ) );
+                }
+            }
+
+            // The response, if any
+            if ( responseValue != null )
+            {
+                buffer.put( ( byte ) LdapConstants.INTERMEDIATE_RESPONSE_VALUE_TAG );
+
+                buffer.put( TLV.getBytes( responseValue.length ) );
+
+                if ( responseValue.length != 0 )
+                {
+                    buffer.put( responseValue );
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( "The PDU buffer size is too small !" );
+        }
+
+        return buffer;
+    }
+
+
+    /**
+     * Get a String representation of an IntermediateResponse
+     * 
+     * @return An IntermediateResponse String
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    Intermediate Response\n" );
+        sb.append( super.toString() );
+
+        if ( responseName != null )
+        {
+            sb.append( "        Response name :'" ).append( responseName ).append( "'\n" );
+        }
+
+        if ( responseValue != null )
+        {
+            sb.append( "        ResponseValue :'" );
+            sb.append( StringTools.dumpBytes( responseValue ) );
+            sb.append( "'\n" );
+        }
+
+        return sb.toString();
+    }
+}

Added: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/intermediate/IntermediateResponseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/intermediate/IntermediateResponseTest.java?rev=749713&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/intermediate/IntermediateResponseTest.java (added)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/intermediate/IntermediateResponseTest.java Tue Mar  3 19:49:17 2009
@@ -0,0 +1,636 @@
+/*
+ *  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.intermediate;
+
+
+import java.nio.ByteBuffer;
+import java.util.List;
+
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.ber.IAsn1Container;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.Control;
+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 junit.framework.TestCase;
+
+
+/**
+ * Test the IntermediateResponse codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class IntermediateResponseTest extends TestCase
+{
+    /**
+     * Test the decoding of a full IntermediateResponse
+     */
+    public void testDecodeIntermediateResponseSuccess()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x1D );
+
+        stream.put( new byte[]
+            { 
+              0x30, 0x1B,               // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01, 0x01,       // messageID MessageID
+                                        // CHOICE { ..., intermediateResponse IntermediateResponse, ...
+                0x79, 0x16,             // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+                                        // responseName [0] LDAPOID,
+                  ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+                                        // responseValue [1] OCTET STRING OPTIONAL }
+                  ( byte ) 0x81, 0x05, 'v', 'a', 'l', 'u', 'e' 
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the IntermediateResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+
+        // Check the decoded IntermediateResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        IntermediateResponse intermediateResponse = message.getIntermediateResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "1.3.6.1.5.5.2", intermediateResponse.getResponseName() );
+        assertEquals( "value", StringTools.utf8ToString( intermediateResponse.getResponseValue() ) );
+
+        // Check the length
+        assertEquals( 0x1D, message.computeLength() );
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+
+    /**
+     * Test the decoding of a full IntermediateResponse with controls
+     */
+    public void testDecodeIntermediateResponseWithControls()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x3A );
+
+        stream.put( new byte[]
+            { 
+            0x30, 0x38,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., intermediateResponse IntermediateResponse, ...
+              0x79, 0x16,               // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+                                        // responseName [0] LDAPOID,
+                ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+                                        // requestValue [1] OCTET STRING OPTIONAL }
+                ( byte ) 0x81, 0x05, 'v', 'a', 'l', 'u', 'e', 
+              ( byte ) 0xA0, 0x1B,      // A control
+                0x30, 0x19, 
+                  0x04, 0x17,
+                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3', 
+                    '0', '.', '3', '.', '4', '.', '2'
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the IntermediateResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+
+        // Check the decoded IntermediateResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        IntermediateResponse intermediateResponse = message.getIntermediateResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "1.3.6.1.5.5.2", intermediateResponse.getResponseName() );
+        assertEquals( "value", StringTools.utf8ToString( intermediateResponse.getResponseValue() ) );
+
+        // Check the Control
+        List<Control> controls = message.getControls();
+
+        assertEquals( 1, controls.size() );
+
+        Control control = message.getControls( 0 );
+        assertEquals( "2.16.840.1.113730.3.4.2", control.getControlType() );
+        assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getControlValue() ) );
+
+        // Check the length
+        assertEquals( 0x3A, message.computeLength() );
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+
+    /**
+     * Test the decoding of a full IntermediateResponse with no value and with
+     * controls
+     */
+    public void testDecodeIntermediateResponseNoValueWithControls()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x33 );
+
+        stream.put( new byte[]
+            { 
+            0x30, 0x31,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., intermediateResponse IntermediateResponse, ...
+              0x79, 0x0F,               // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+                                        // responseName [0] LDAPOID,
+                ( byte ) 0x80, 0x0D, 
+                  '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+                                        // requestValue [1] OCTET STRING OPTIONAL }
+              ( byte ) 0xA0, 0x1B,      // A control
+                0x30, 0x19, 
+                  0x04, 0x17, 
+                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3', 
+                    '0', '.', '3', '.', '4', '.', '2'
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the IntermediateResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+
+        // Check the decoded IntermediateResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        IntermediateResponse intermediateResponse = message.getIntermediateResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "1.3.6.1.5.5.2", intermediateResponse.getResponseName() );
+        assertEquals( "", StringTools.utf8ToString( intermediateResponse.getResponseValue() ) );
+
+        // Check the Control
+        List<Control> controls = message.getControls();
+
+        assertEquals( 1, controls.size() );
+
+        Control control = message.getControls( 0 );
+        assertEquals( "2.16.840.1.113730.3.4.2", control.getControlType() );
+        assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getControlValue() ) );
+
+        // Check the length
+        assertEquals( 0x33, message.computeLength() );
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+
+    /**
+     * Test the decoding of an empty IntermediateResponse
+     */
+    public void testDecodeIntermediateResponseEmpty()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x07 );
+
+        stream.put( new byte[]
+            { 
+            0x30, 0x05,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., intermediateResponse IntermediateResponse, ...
+              0x79, 0x00,               // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a IntermediateResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            fail( "We should never reach this point !!!" );
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test the decoding of an empty OID
+     */
+    public void testDecodeEmptyOID()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x09 );
+
+        stream.put( new byte[]
+            { 
+            0x30, 0x07,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., intermediateResponse IntermediateResponse, ...
+              0x79, 0x02,               // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+                ( byte ) 0x80, 0x00 
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a IntermediateResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            fail( "We should never reach this point !!!" );
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( true );
+        }
+    }
+
+    /**
+     * Test the decoding of a bad name 
+     */
+    public void testDecodeExtendedBadRequestName()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x16 );
+
+        stream.put( new byte[]
+            { 
+            0x30, 0x14,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., intermediateResponse IntermediateResponse, ...
+              0x79, 0x0F,               // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+                                        // responseName [0] LDAPOID,
+                ( byte ) 0x80, 0x0D, 
+                  '1', '-', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', 
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a IntermediateResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            fail( "We should never reach this point !!!" );
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( true );
+        }
+    }    
+
+    /**
+     * Test the decoding of a name only IntermediateResponse
+     */
+    public void testDecodeIntermediateResponseName()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x16 );
+
+        stream.put( new byte[]
+            { 
+            0x30, 0x14,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., intermediateResponse IntermediateResponse, ...
+              0x79, 0x0F,               // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+                                        // responseName [0] LDAPOID,
+                ( byte ) 0x80, 0x0D, 
+                  '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', 
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the IntermediateResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+
+        // Check the decoded IntermediateResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        IntermediateResponse intermediateResponse = message.getIntermediateResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "1.3.6.1.5.5.2", intermediateResponse.getResponseName() );
+
+        // Check the length
+        assertEquals( 0x16, message.computeLength() );
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+
+    /**
+     * Test the decoding of an empty value IntermediateResponse
+     */
+    public void testDecodeIntermediateResponseEmptyValue()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x18 );
+
+        stream.put( new byte[]
+            { 
+            0x30, 0x16,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., intermediateResponse IntermediateResponse, ...
+              0x79, 0x11,               // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+                                        // responseName [0] LDAPOID,
+                ( byte ) 0x80, 0x0D, 
+                  '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', 
+                ( byte ) 0x81, 0x00 
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the IntermediateResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+
+        // Check the decoded IntermediateResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        IntermediateResponse intermediateResponse = message.getIntermediateResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "1.3.6.1.5.5.2", intermediateResponse.getResponseName() );
+        assertEquals( "", StringTools.utf8ToString( intermediateResponse.getResponseValue() ) );
+
+        // Check the length
+        assertEquals( 0x18, message.computeLength() );
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+
+    /**
+     * Test the decoding of an IntermediateResponse without name
+     */
+    public void testDecodeIntermediateResponseNoName()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x0E );
+
+        stream.put( new byte[]
+            { 
+              0x30, 0x0C,               // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01, 0x01,       // messageID MessageID
+                                        // CHOICE { ..., intermediateResponse IntermediateResponse, ...
+                0x79, 0x07,             // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+                                        // responseValue [1] OCTET STRING OPTIONAL,
+                  ( byte ) 0x81, 0x05, 'v', 'a', 'l', 'u', 'e' 
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the IntermediateResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+
+        // Check the decoded IntermediateResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        IntermediateResponse intermediateResponse = message.getIntermediateResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "", intermediateResponse.getResponseName() );
+        assertEquals( "value", StringTools.utf8ToString( intermediateResponse.getResponseValue() ) );
+
+        // Check the length
+        assertEquals( 0x0E, message.computeLength() );
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+
+    /**
+     * Test the decoding of an IntermediateResponse with no value
+     */
+    public void testDecodeIntermediateResponseNoValue()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x16 );
+
+        stream.put( new byte[]
+            { 
+              0x30, 0x14,               // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01, 0x01,       // messageID MessageID
+                                        // CHOICE { ..., intermediateResponse IntermediateResponse, ...
+                0x79, 0x0F,             // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
+                                        // responseName [0] LDAPOID,
+                  ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the IntermediateResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+
+        // Check the decoded IntermediateResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        IntermediateResponse intermediateResponse = message.getIntermediateResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "1.3.6.1.5.5.2", intermediateResponse.getResponseName() );
+        assertEquals( "", StringTools.utf8ToString( intermediateResponse.getResponseValue() ) );
+
+        // Check the length
+        assertEquals( 0x16, message.computeLength() );
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+}



Mime
View raw message