You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/05/30 18:27:49 UTC

svn commit: rev 20654 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap test/org/apache/snickers/ldap

Author: akarasulu
Date: Sun May 30 09:27:48 2004
New Revision: 20654

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedResponseOidRule.java   (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedResponsePayloadRule.java   (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedResponseRule.java   (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/ExtendedResponseRuleTest.java   (contents, props changed)
Modified:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
Log:
finished and tested the extended response rules

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedResponseOidRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedResponseOidRule.java	Sun May 30 09:27:48 2004
@@ -0,0 +1,79 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.snickers.ldap ;
+
+
+import java.nio.ByteBuffer ;
+
+import org.apache.ldap.common.message.ExtendedResponse ;
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
+
+
+/**
+ * A BERDigester rule to set the OID of the ExtendedResponse's ASN.1 name field.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class ExtendedResponseOidRule extends PrimitiveOctetStringRule
+{
+    public ExtendedResponseOidRule()
+    {
+        super( LdapTag.EXTENDED_RESPONSE_NAME_TAG ) ;
+    }
+
+    
+    /**
+     * Allows the super method to push a ByteBuffer onto the top of the stack
+     * which contains the drained contents of the superclass' ByteAccumulator.
+     * This ByteBuffer is popped first then used to populate the credentials.
+     * There is no need to copy this buffer since it will not be used again
+     * by the ByteAccumulator of the superclass so we should be able to use
+     * the byte[] based backing store if one is present.  However it might
+     * have to be copied even then.  Situations requiring a copy are when the
+     * buffer has a limit less than the capacity or when there is no
+     * accessible array to the buffer.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        // pushes a ByteBuffer onto the stack
+        super.finish() ;
+
+        // pop the ByteBuffer the super method pushed
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+        // peek at the ExtendedResponse underneath whose octets we set
+        ExtendedResponse resp = ( ExtendedResponse ) getDigester().peek() ;
+
+        byte[] octets = null ;
+        if ( buf.limit() == buf.capacity() && buf.hasArray() )
+        {
+            // use the backing store
+            octets = buf.array() ;
+        }
+        else
+        {
+            // copy because we don't have accessible array or data < array
+            octets = new byte[buf.remaining()] ;
+            buf.get( octets ) ;
+        }
+
+        resp.setResponseName( new String( octets ) ) ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedResponsePayloadRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedResponsePayloadRule.java	Sun May 30 09:27:48 2004
@@ -0,0 +1,80 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.snickers.ldap ;
+
+
+import java.nio.ByteBuffer ;
+
+import org.apache.ldap.common.message.ExtendedResponse ;
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
+
+
+/**
+ * A BERDigester rule to set the payload of the ExtendedResponse's ASN.1
+ * response value field.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class ExtendedResponsePayloadRule extends PrimitiveOctetStringRule
+{
+    public ExtendedResponsePayloadRule()
+    {
+        super( LdapTag.EXTENDED_RESPONSE_VALUE_TAG ) ;
+    }
+
+    
+    /**
+     * Allows the super method to push a ByteBuffer onto the top of the stack
+     * which contains the drained contents of the superclass' ByteAccumulator.
+     * This ByteBuffer is popped first then used to populate the credentials.
+     * There is no need to copy this buffer since it will not be used again
+     * by the ByteAccumulator of the superclass so we should be able to use
+     * the byte[] based backing store if one is present.  However it might
+     * have to be copied even then.  Situations requiring a copy are when the
+     * buffer has a limit less than the capacity or when there is no
+     * accessible array to the buffer.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        // pushes a ByteBuffer onto the stack
+        super.finish() ;
+
+        // pop the ByteBuffer the super method pushed
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+        // peek at the ExtendedResponse underneath whose octets we set
+        ExtendedResponse resp = ( ExtendedResponse ) getDigester().peek() ;
+
+        byte[] octets = null ;
+        if ( buf.limit() == buf.capacity() && buf.hasArray() )
+        {
+            // use the backing store
+            octets = buf.array() ;
+        }
+        else
+        {
+            // copy because we don't have accessible array or data < array
+            octets = new byte[buf.remaining()] ;
+            buf.get( octets ) ;
+        }
+
+        resp.setResponse( octets ) ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedResponseRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedResponseRule.java	Sun May 30 09:27:48 2004
@@ -0,0 +1,37 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.snickers.ldap ;
+
+
+/**
+ * A digester rule which fires to build ExtendedRespond containment trees.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class ExtendedResponseRule extends ResultResponseRule
+{
+    /**
+     * Creates a digester rule which fires to build ExtendedRespond containment
+     * trees.
+     */
+    public ExtendedResponseRule()
+    {
+        super( LdapTag.EXTENDED_RESPONSE ) ;
+    }
+}

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java	(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java	Sun May 30 09:27:48 2004
@@ -19,7 +19,6 @@
 
 import org.apache.snickers.ber.digester.BERDigester ;
 import org.apache.snickers.ber.primitives.UniversalTag ;
-import org.apache.snickers.ber.primitives.ContextSpecificTag;
 import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
 import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
 
@@ -88,6 +87,7 @@
         addDeleteRequestRules( digester ) ;
         addDeleteResponseRules( digester ) ;
         addExtendedRequestRules( digester ) ;
+        addExtendedResponseRules( digester ) ;
 
         return digester ;
     }
@@ -108,6 +108,50 @@
 
         pattern[2] = LdapTag.EXTENDED_REQUEST_VALUE_TAG.getPrimitiveTag() ;
         digester.addRule( pattern, new ExtendedRequestPayloadRule() ) ;
+    }
+
+
+    private void addExtendedResponseRules( BERDigester digester )
+    {
+        int[] pattern = new int[2] ;
+
+        // modify pattern and addRule for the ExtendedResponse
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.EXTENDED_RESPONSE.getPrimitiveTag() ;
+        digester.addRule( pattern, new ExtendedResponseRule() ) ;
+
+        // modify pattern and addRule for the ExtendedResponse
+        pattern = new int[3] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.EXTENDED_RESPONSE.getPrimitiveTag() ;
+
+        // for the resultCode
+        pattern[2] = UniversalTag.ENUMERATED.getPrimitiveTag() ;
+
+        // for matchedDN and errorMessage
+        pattern[2] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
+        digester.addRule( pattern, new ResultMatchedDNRule() ) ;
+        digester.addRule( pattern, new ErrorMessageRule() ) ;
+
+        // for referral
+        pattern[2] = LdapTag.REFERRAL_TAG.getPrimitiveTag() ;
+        digester.addRule( pattern, new ReferralRule() ) ;
+
+        // for responseName
+        pattern[2] = LdapTag.EXTENDED_RESPONSE_NAME_TAG.getPrimitiveTag() ;
+        digester.addRule( pattern, new ExtendedResponseOidRule() ) ;
+
+        // for response value
+        pattern[2] = LdapTag.EXTENDED_RESPONSE_VALUE_TAG.getPrimitiveTag() ;
+        digester.addRule( pattern, new ExtendedResponsePayloadRule() ) ;
+
+        // for LDAPURLs of referral
+        pattern = new int[4] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.EXTENDED_RESPONSE.getPrimitiveTag() ;
+        pattern[2] = LdapTag.REFERRAL_TAG.getPrimitiveTag() ;
+        pattern[3] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
+        digester.addRule( pattern, new ReferralUrlRule() ) ;
     }
 
 

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java	(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java	Sun May 30 09:27:48 2004
@@ -209,13 +209,21 @@
     public static final ContextSpecificTag SERVER_SASL_CREDS_TAG =
             new ContextSpecificTag( 7, true ) ;
 
-    /** Context specific tag used for BindResponse serverSaslCreds */
+    /** Context specific tag used for ExtendedRequest requestName */
     public static final ContextSpecificTag EXTENDED_REQUEST_NAME_TAG =
             new ContextSpecificTag( 0, false ) ;
 
-    /** Context specific tag used for BindResponse serverSaslCreds */
+    /** Context specific tag used for ExtendedRequest request value */
     public static final ContextSpecificTag EXTENDED_REQUEST_VALUE_TAG =
             new ContextSpecificTag( 1, false ) ;
+
+    /** Context specific tag used for ExtendedResponse responseName */
+    public static final ContextSpecificTag EXTENDED_RESPONSE_NAME_TAG =
+            new ContextSpecificTag( 10, false ) ;
+
+    /** Context specific tag used for ExtendedResponse response value */
+    public static final ContextSpecificTag EXTENDED_RESPONSE_VALUE_TAG =
+            new ContextSpecificTag( 11, false ) ;
 
 
 

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/ExtendedResponseRuleTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/ExtendedResponseRuleTest.java	Sun May 30 09:27:48 2004
@@ -0,0 +1,84 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.snickers.ldap ;
+
+
+import java.util.Iterator ;
+
+import org.apache.snickers.ldap.testutils.TestUtils ;
+import org.apache.snickers.ldap.testutils.RuleTestCase ;
+
+import org.apache.ldap.common.message.* ;
+import org.apache.commons.lang.ArrayUtils ;
+
+
+/**
+ * Tests the population of an LdapResult using a ResultRule.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class ExtendedResponseRuleTest extends RuleTestCase
+{
+    public void testExtendedResponse() throws Exception
+    {
+        // build the PDU
+        ExtendedResponseImpl resp = new ExtendedResponseImpl( 8 ) ;
+        resp.setResponseName( "0.0.0.0" ) ;
+        byte[] payload = new byte[2] ;
+        payload[0] = 5 ;
+        payload[1] = 6 ;
+        resp.setResponse( payload ) ;
+        LdapResultImpl result = new LdapResultImpl( resp ) ;
+        result.setResultCode( ResultCodeEnum.BUSY ) ;
+        result.setErrorMessage( "An Error Message!" ) ;
+        result.setMatchedDn( "uid=akarasulu,dc=example,dc=com" ) ;
+        ReferralImpl referral = new ReferralImpl( result ) ;
+        referral.addLdapUrl( "hello" ) ;
+        referral.addLdapUrl( "world" ) ;
+        result.setReferral( referral ) ;
+        resp.setLdapResult( result ) ;
+        System.out.println( "Generated ExtendedResponse for test:" ) ;
+        System.out.println( TestUtils.printTupleTree( resp ) ) ;
+
+        ExtendedResponse decoded = ( ExtendedResponse )
+                snickersDecode( snaccEncode( resp ) ) ;
+
+        assertNotNull( decoded ) ;
+        assertEquals( resp.getMessageId(), decoded.getMessageId() ) ;
+        assertEquals( resp.getResponseName(), decoded.getResponseName() ) ;
+        assertTrue( ArrayUtils.isEquals( payload, decoded.getResponse() ) ) ;
+        LdapResult decodedResult = resp.getLdapResult() ;
+        assertEquals( result.getResultCode(), decodedResult.getResultCode() ) ;
+        assertEquals( result.getErrorMessage(),
+                decodedResult.getErrorMessage() ) ;
+        assertEquals( result.getMatchedDn(),
+                decodedResult.getMatchedDn() ) ;
+        Referral decodedRef = result.getReferral() ;
+        Iterator urls = referral.getLdapUrls().iterator() ;
+        Iterator decodedUrls = decodedRef.getLdapUrls().iterator() ;
+
+        while( urls.hasNext() && decodedUrls.hasNext() )
+        {
+            assertEquals( urls.next(), decodedUrls.next() ) ;
+        }
+
+        assertFalse( urls.hasNext() ) ;
+        assertFalse( decodedUrls.hasNext() ) ;
+    }
+}
\ No newline at end of file