From commits-return-26619-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Mon Jul 19 22:57:00 2010 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 54134 invoked from network); 19 Jul 2010 22:57:00 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 19 Jul 2010 22:57:00 -0000 Received: (qmail 33901 invoked by uid 500); 19 Jul 2010 22:57:00 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 33846 invoked by uid 500); 19 Jul 2010 22:56:59 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 33838 invoked by uid 99); 19 Jul 2010 22:56:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Jul 2010 22:56:59 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Jul 2010 22:56:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9C1FE23889ED; Mon, 19 Jul 2010 22:56:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r965668 - in /directory/shared/branches/shared-subtree/ldap/src/main/java/org/apache/directory/shared/ldap/codec: LdapMessageCodec.java MessageEncoderException.java Date: Mon, 19 Jul 2010 22:56:03 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100719225603.9C1FE23889ED@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 Apache Directory Project + * @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; + } +}