You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/07/20 00:56:03 UTC

svn commit: r965668 - in /directory/shared/branches/shared-subtree/ldap/src/main/java/org/apache/directory/shared/ldap/codec: LdapMessageCodec.java MessageEncoderException.java

Author: elecharny
Date: Mon Jul 19 22:56:03 2010
New Revision: 965668

URL: http://svn.apache.org/viewvc?rev=965668&view=rev
Log:
o Added an exception to deal with encoding errors : the message ID is stored in the exception in order to abort the asynchronous requests
o The LdapMessageCodec throws a MessageEncoderException if the encoding failed

Added:
    directory/shared/branches/shared-subtree/ldap/src/main/java/org/apache/directory/shared/ldap/codec/MessageEncoderException.java
Modified:
    directory/shared/branches/shared-subtree/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java

Modified: directory/shared/branches/shared-subtree/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-subtree/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java?rev=965668&r1=965667&r2=965668&view=diff
==============================================================================
--- directory/shared/branches/shared-subtree/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java (original)
+++ directory/shared/branches/shared-subtree/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageCodec.java Mon Jul 19 22:56:03 2010
@@ -365,43 +365,52 @@ public abstract class LdapMessageCodec e
      */
     public ByteBuffer encode() throws EncoderException
     {
-        // Allocate the bytes buffer.
-        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
-
         try
-        {
-            // The LdapMessage Sequence
-            bb.put( UniversalTag.SEQUENCE_TAG );
-
-            // The length has been calculated by the computeLength method
-            bb.put( TLV.getBytes( ldapMessageLength ) );
-        }
-        catch ( BufferOverflowException boe )
-        {
-            throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
-        }
-
-        // The message Id
-        Value.encode( bb, messageId );
-
-        // Add the protocolOp part
-        encodeProtocolOp( bb );
-
-        // Do the same thing for Controls, if any.
-        if ( controls != null )
-        {
-            // Encode the controls
-            bb.put( ( byte ) LdapConstants.CONTROLS_TAG );
-            bb.put( TLV.getBytes( controlsLength ) );
-
-            // Encode each control
-            for ( Control control:controls )
+        {     
+            // Allocate the bytes buffer.
+            ByteBuffer bb = ByteBuffer.allocate( computeLength() );
+    
+            try
+            {
+                // The LdapMessage Sequence
+                bb.put( UniversalTag.SEQUENCE_TAG );
+    
+                // The length has been calculated by the computeLength method
+                bb.put( TLV.getBytes( ldapMessageLength ) );
+            }
+            catch ( BufferOverflowException boe )
             {
-                ((CodecControl)control).encode( bb );
+                throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
             }
+    
+            // The message Id
+            Value.encode( bb, messageId );
+    
+            // Add the protocolOp part
+            encodeProtocolOp( bb );
+    
+            // Do the same thing for Controls, if any.
+            if ( controls != null )
+            {
+                // Encode the controls
+                bb.put( ( byte ) LdapConstants.CONTROLS_TAG );
+                bb.put( TLV.getBytes( controlsLength ) );
+    
+                // Encode each control
+                for ( Control control:controls )
+                {
+                    ((CodecControl)control).encode( bb );
+                }
+            }
+    
+            return bb;
+        }
+        catch ( EncoderException ee )
+        {
+            MessageEncoderException exception = new MessageEncoderException( messageId, ee.getMessage() );
+            
+            throw exception;
         }
-
-        return bb;
     }
 
 

Added: directory/shared/branches/shared-subtree/ldap/src/main/java/org/apache/directory/shared/ldap/codec/MessageEncoderException.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-subtree/ldap/src/main/java/org/apache/directory/shared/ldap/codec/MessageEncoderException.java?rev=965668&view=auto
==============================================================================
--- directory/shared/branches/shared-subtree/ldap/src/main/java/org/apache/directory/shared/ldap/codec/MessageEncoderException.java (added)
+++ directory/shared/branches/shared-subtree/ldap/src/main/java/org/apache/directory/shared/ldap/codec/MessageEncoderException.java Mon Jul 19 22:56:03 2010
@@ -0,0 +1,55 @@
+/*
+ *  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;
+
+import org.apache.directory.shared.asn1.codec.EncoderException;
+
+/**
+ * Create an exception containing the messageId
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class MessageEncoderException extends EncoderException
+{
+    /** The message ID */
+    private int messageId;
+
+    /**
+     * Creates a new instance of MessageEncoderException.
+     *
+     * @param messageId The message ID
+     * @param message The exception message
+     */
+    public MessageEncoderException( int messageId, String message )
+    {
+        super( message );
+        this.messageId = messageId;
+    }
+
+
+    /**
+     * @return the messageId
+     */
+    public int getMessageId()
+    {
+        return messageId;
+    }
+}