You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/02/01 17:02:56 UTC

svn commit: r905317 - /directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java

Author: kayyagari
Date: Mon Feb  1 16:02:56 2010
New Revision: 905317

URL: http://svn.apache.org/viewvc?rev=905317&view=rev
Log:
o updated the code to use the new Control implementation
o added a null check against the received CodecControl values received from the LdapMessageCodec object
o lots of code formatting

Modified:
    directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java

Modified: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java?rev=905317&r1=905316&r2=905317&view=diff
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java (original)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java Mon Feb  1 16:02:56 2010
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.ldap.client.api;
 
+
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
@@ -81,7 +82,6 @@
 import org.apache.directory.shared.asn1.ber.IAsn1Container;
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.primitives.OID;
-import org.apache.directory.shared.ldap.codec.ControlCodec;
 import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
@@ -97,6 +97,8 @@
 import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication;
 import org.apache.directory.shared.ldap.codec.compare.CompareRequestCodec;
 import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec;
+import org.apache.directory.shared.ldap.codec.controls.CodecControl;
+import org.apache.directory.shared.ldap.codec.controls.CodecControlImpl;
 import org.apache.directory.shared.ldap.codec.del.DelRequestCodec;
 import org.apache.directory.shared.ldap.codec.del.DelResponseCodec;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec;
@@ -125,7 +127,6 @@
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.control.Control;
-import org.apache.directory.shared.ldap.message.control.ControlImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.RDN;
 import org.apache.directory.shared.ldap.util.LdapURL;
@@ -145,6 +146,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 /**
  * This class is the base for every operations sent or received to and
  * from a LDAP server.
@@ -159,49 +161,47 @@
     private static final Logger LOG = LoggerFactory.getLogger( LdapConnection.class );
 
     private static final String LDAP_RESPONSE = "LdapReponse";
-    
-    /** The timeout used for response we are waiting for */ 
+
+    /** The timeout used for response we are waiting for */
     private long timeOut = LdapConnectionConfig.DEFAULT_TIMEOUT;
-    
+
     /** configuration object for the connection */
     private LdapConnectionConfig config = new LdapConnectionConfig();
-    
+
     /** The connector open with the remote server */
     private IoConnector connector;
-    
-    /** A flag set to true when we used a local connector */ 
+
+    /** A flag set to true when we used a local connector */
     private boolean localConnector;
-    
+
     /** The Ldap codec */
-    private IoFilter ldapProtocolFilter = new ProtocolCodecFilter(
-            new LdapProtocolCodecFactory() );
+    private IoFilter ldapProtocolFilter = new ProtocolCodecFilter( new LdapProtocolCodecFactory() );
 
     /**  
      * The created session, created when we open a connection with
      * the Ldap server.
      */
     private IoSession ldapSession;
-    
+
     /** A Message ID which is incremented for each operation */
     private AtomicInteger messageId;
-    
+
     /** a map to hold the response listeners based on the operation id */
     private Map<Integer, OperationResponseListener> listenerMap = new ConcurrentHashMap<Integer, OperationResponseListener>();
-    
+
     /** a map to hold the ResponseFutures for all operations */
     private Map<Integer, ResponseFuture> futureMap = new ConcurrentHashMap<Integer, ResponseFuture>();
 
     /** a map to hold the response queues related to the operations */
     private Map<Integer, BlockingQueue> respQueueMap = new ConcurrentHashMap<Integer, BlockingQueue>();
-    
+
     /** list of controls supported by the server */
     private List<String> supportedControls;
 
     private Entry rootDSE;
 
-
     // ~~~~~~~~~~~~~~~~~ common error messages ~~~~~~~~~~~~~~~~~~~~~~~~~~
-    
+
     private static final String OPERATION_CANCELLED = "Operation would have been cancelled";
 
     private static final String TIME_OUT_ERROR = "TimeOut occured";
@@ -209,8 +209,8 @@
     private static final String NO_RESPONSE_ERROR = "The response queue has been emptied, no response was found.";
 
     private static final String COMPARE_FAILED = "Failed to perform compare operation";
-    
-    
+
+
     //--------------------------- Helper methods ---------------------------//
     /**
      * Check if the connection is valid : created and connected
@@ -222,7 +222,7 @@
         return ( ldapSession != null ) && ldapSession.isConnected();
     }
 
-    
+
     /**
      * Check that a session is valid, ie we can send requests to the
      * server
@@ -235,13 +235,14 @@
         {
             throw new InvalidConnectionException( "Cannot connect on the server, the connection is null" );
         }
-        
+
         if ( !isSessionValid() )
         {
             throw new InvalidConnectionException( "Cannot connect on the server, the connection is invalid" );
         }
     }
-    
+
+
     /**
      * Return the response stored into the current session.
      *
@@ -249,10 +250,10 @@
      */
     public LdapMessageCodec getResponse()
     {
-        return (LdapMessageCodec)ldapSession.getAttribute( LDAP_RESPONSE );
+        return ( LdapMessageCodec ) ldapSession.getAttribute( LDAP_RESPONSE );
     }
 
-    
+
     /**
      * Inject the client Controls into the message
      */
@@ -261,19 +262,18 @@
         // Add the controls
         if ( controls != null )
         {
-            for ( Control control:controls.values() )
+            for ( Control control : controls.values() )
             {
-                ControlCodec ctrl = new ControlCodec();
-                
-                ctrl.setControlType( control.getOid() );
-                ctrl.setControlValue( control.getValue() );
-                
+                CodecControlImpl ctrl = new CodecControlImpl( control.getOid() );
+
+                ctrl.setValue( control.getValue() );
+
                 message.addControl( ctrl );
             }
         }
     }
-    
-    
+
+
     /**
      * Get the smallest timeout from the client timeout and the connection
      * timeout.
@@ -290,18 +290,18 @@
         }
         else
         {
-            return timeOut < clientTimeOut ? timeOut : clientTimeOut; 
+            return timeOut < clientTimeOut ? timeOut : clientTimeOut;
         }
     }
-    
-    
+
+
     /**
      * Convert a BindResponseCodec to a BindResponse message
      */
     private BindResponse convert( BindResponseCodec bindResponseCodec )
     {
         BindResponse bindResponse = new BindResponse();
-        
+
         bindResponse.setMessageId( bindResponseCodec.getMessageId() );
         bindResponse.setServerSaslCreds( bindResponseCodec.getServerSaslCreds() );
         bindResponse.setLdapResult( convert( bindResponseCodec.getLdapResult() ) );
@@ -316,7 +316,7 @@
     private IntermediateResponse convert( IntermediateResponseCodec intermediateResponseCodec )
     {
         IntermediateResponse intermediateResponse = new IntermediateResponse();
-        
+
         intermediateResponse.setMessageId( intermediateResponseCodec.getMessageId() );
         intermediateResponse.setResponseName( intermediateResponseCodec.getResponseName() );
         intermediateResponse.setResponseValue( intermediateResponseCodec.getResponseValue() );
@@ -331,21 +331,21 @@
     private LdapResult convert( LdapResultCodec ldapResultCodec )
     {
         LdapResult ldapResult = new LdapResult();
-        
+
         ldapResult.setErrorMessage( ldapResultCodec.getErrorMessage() );
         ldapResult.setMatchedDn( ldapResultCodec.getMatchedDN() );
-        
+
         // Loop on the referrals
         Referral referral = new Referral();
-        
-        if (ldapResultCodec.getReferrals() != null )
+
+        if ( ldapResultCodec.getReferrals() != null )
         {
-            for ( LdapURL url:ldapResultCodec.getReferrals() )
+            for ( LdapURL url : ldapResultCodec.getReferrals() )
             {
                 referral.addLdapUrls( url );
             }
         }
-        
+
         ldapResult.setReferral( referral );
         ldapResult.setResultCode( ldapResultCodec.getResultCode() );
 
@@ -359,7 +359,7 @@
     private SearchResultEntry convert( SearchResultEntryCodec searchEntryResultCodec )
     {
         SearchResultEntry searchResultEntry = new SearchResultEntry();
-        
+
         searchResultEntry.setMessageId( searchEntryResultCodec.getMessageId() );
         searchResultEntry.setEntry( searchEntryResultCodec.getEntry() );
         addControls( searchEntryResultCodec, searchResultEntry );
@@ -374,7 +374,7 @@
     private SearchResultDone convert( SearchResultDoneCodec searchResultDoneCodec )
     {
         SearchResultDone searchResultDone = new SearchResultDone();
-        
+
         searchResultDone.setMessageId( searchResultDoneCodec.getMessageId() );
         searchResultDone.setLdapResult( convert( searchResultDoneCodec.getLdapResult() ) );
         addControls( searchResultDoneCodec, searchResultDone );
@@ -389,23 +389,23 @@
     private SearchResultReference convert( SearchResultReferenceCodec searchEntryReferenceCodec )
     {
         SearchResultReference searchResultReference = new SearchResultReference();
-        
+
         searchResultReference.setMessageId( searchEntryReferenceCodec.getMessageId() );
 
         // Loop on the referrals
         Referral referral = new Referral();
-        
-        if (searchEntryReferenceCodec.getSearchResultReferences() != null )
+
+        if ( searchEntryReferenceCodec.getSearchResultReferences() != null )
         {
-            for ( LdapURL url:searchEntryReferenceCodec.getSearchResultReferences() )
+            for ( LdapURL url : searchEntryReferenceCodec.getSearchResultReferences() )
             {
                 referral.addLdapUrls( url );
             }
         }
-        
+
         searchResultReference.setReferral( referral );
         addControls( searchEntryReferenceCodec, searchResultReference );
-        
+
         return searchResultReference;
     }
 
@@ -422,8 +422,8 @@
         config.setLdapHost( config.getDefaultLdapHost() );
         messageId = new AtomicInteger();
     }
-    
-    
+
+
     /**
      * 
      * Creates a new instance of LdapConnection with the given connection configuration.
@@ -435,8 +435,8 @@
         this.config = config;
         messageId = new AtomicInteger();
     }
-    
-    
+
+
     /**
      * Create a new instance of a LdapConnection on localhost,
      * port 389 if the SSL flag is off, or 636 otherwise.
@@ -450,8 +450,8 @@
         config.setLdapHost( config.getDefaultLdapHost() );
         messageId = new AtomicInteger();
     }
-    
-    
+
+
     /**
      * Create a new instance of a LdapConnection on a given
      * server, using the default port (389).
@@ -465,8 +465,8 @@
         config.setLdapHost( server );
         messageId = new AtomicInteger();
     }
-    
-    
+
+
     /**
      * Create a new instance of a LdapConnection on a given
      * server, using the default port (389) if the SSL flag 
@@ -482,8 +482,8 @@
         config.setLdapHost( server );
         messageId = new AtomicInteger();
     }
-    
-    
+
+
     /**
      * Create a new instance of a LdapConnection on a 
      * given server and a given port. We don't use ssl.
@@ -495,8 +495,8 @@
     {
         this( server, port, false );
     }
-    
-    
+
+
     /**
      * Create a new instance of a LdapConnection on a given
      * server, and a give port. We set the SSL flag accordingly
@@ -514,7 +514,7 @@
         messageId = new AtomicInteger();
     }
 
-    
+
     //-------------------------- The methods ---------------------------//
     /**
      * Connect to the remote LDAP server.
@@ -524,23 +524,23 @@
      */
     public boolean connect() throws LdapException, IOException
     {
-        if ( ( ldapSession != null ) && ldapSession.isConnected() ) 
+        if ( ( ldapSession != null ) && ldapSession.isConnected() )
         {
             // No need to connect if we already have a connected session
             return true;
         }
 
         // Create the connector if needed
-        if ( connector == null ) 
+        if ( connector == null )
         {
             connector = new NioSocketConnector();
             localConnector = true;
-            
+
             // Add the codec to the chain
             connector.getFilterChain().addLast( "ldapCodec", ldapProtocolFilter );
-    
+
             // If we use SSL, we have to add the SslFilter to the chain
-            if ( config.isUseSsl() ) 
+            if ( config.isUseSsl() )
             {
                 try
                 {
@@ -548,39 +548,37 @@
                     sslContext.init( config.getKeyManagers(), config.getTrustManagers(), config.getSecureRandom() );
 
                     SslFilter sslFilter = new SslFilter( sslContext );
-                    sslFilter.setUseClientMode(true);
+                    sslFilter.setUseClientMode( true );
                     connector.getFilterChain().addFirst( "sslFilter", sslFilter );
                 }
-                catch( Exception e )
+                catch ( Exception e )
                 {
                     String msg = "Failed to initialize the SSL context";
                     LOG.error( msg, e );
                     throw new LdapException( msg, e );
                 }
             }
-            
+
             // Add an executor so that this connection can be used
             // for handling more than one request (mainly because
             // we may have to handle some abandon request)
-            connector.getFilterChain().addLast( "executor", 
-                new ExecutorFilter( 
-                    new UnorderedThreadPoolExecutor( 10 ),
-                    IoEventType.MESSAGE_RECEIVED ) );
-    
+            connector.getFilterChain().addLast( "executor",
+                new ExecutorFilter( new UnorderedThreadPoolExecutor( 10 ), IoEventType.MESSAGE_RECEIVED ) );
+
             // Inject the protocolHandler
             connector.setHandler( this );
         }
-        
+
         // Build the connection address
-        SocketAddress address = new InetSocketAddress( config.getLdapHost() , config.getLdapPort() );
-        
+        SocketAddress address = new InetSocketAddress( config.getLdapHost(), config.getLdapPort() );
+
         // And create the connection future
         ConnectFuture connectionFuture = connector.connect( address );
-        
+
         // Wait until it's established
         connectionFuture.awaitUninterruptibly();
-        
-        if ( !connectionFuture.isConnected() ) 
+
+        if ( !connectionFuture.isConnected() )
         {
             // disposing connector if not connected
             try
@@ -591,50 +589,50 @@
             {
                 // Nothing to do
             }
-            
+
             return false;
         }
-        
+
         // Get back the session
         ldapSession = connectionFuture.getSession();
-        
+
         // And inject the current Ldap container into the session
         IAsn1Container ldapMessageContainer = new LdapMessageContainer();
-        
+
         // Store the container into the session 
         ldapSession.setAttribute( "LDAP-Container", ldapMessageContainer );
-        
+
         // And return
         return true;
     }
-    
-    
+
+
     /**
      * Disconnect from the remote LDAP server
      *
      * @return <code>true</code> if the connection is closed, false otherwise
      * @throws IOException if some I/O error occurs
      */
-    public boolean close() throws IOException 
+    public boolean close() throws IOException
     {
         // Close the session
         if ( ( ldapSession != null ) && ldapSession.isConnected() )
         {
             ldapSession.close( true );
         }
-        
+
         // And close the connector if it has been created locally
-        if ( localConnector ) 
+        if ( localConnector )
         {
             // Release the connector
             connector.dispose();
             connector = null;
         }
-        
+
         return true;
     }
-    
-    
+
+
     //------------------------ The LDAP operations ------------------------//
     // Add operations                                                      //
     //---------------------------------------------------------------------//
@@ -647,17 +645,17 @@
      */
     public AddResponse add( Entry entry ) throws LdapException
     {
-        if ( entry == null ) 
+        if ( entry == null )
         {
             String msg = "Cannot add empty entry";
             LOG.debug( msg );
             throw new NullPointerException( msg );
         }
-        
+
         return add( new AddRequest( entry ), null );
     }
-    
-    
+
+
     /**
      * Add an entry present in the AddRequest to the server.
      * @param addRequest the request object containing an entry and controls(if any)
@@ -668,7 +666,8 @@
     {
         return add( addRequest, null );
     }
-    
+
+
     /**
      * Add an entry present in the AddRequest to the server.
      * @param addRequest the request object containing an entry and controls(if any)
@@ -681,7 +680,7 @@
         checkSession();
 
         AddRequestCodec addReqCodec = new AddRequestCodec();
-        
+
         int newId = messageId.incrementAndGet();
         LdapMessageCodec message = new LdapMessageCodec();
         message.setMessageId( newId );
@@ -690,38 +689,38 @@
         addReqCodec.setEntry( addRequest.getEntry() );
         addReqCodec.setEntryDn( addRequest.getEntry().getDn() );
         setControls( addRequest.getControls(), addReqCodec );
-        
+
         message.setProtocolOP( addReqCodec );
-        
+
         BlockingQueue<AddResponse> addResponseQueue = new LinkedBlockingQueue<AddResponse>();
         respQueueMap.put( newId, addResponseQueue );
-        
+
         ResponseFuture addFuture = new ResponseFuture( addResponseQueue );
         futureMap.put( newId, addFuture );
 
         // Send the request to the server
         ldapSession.write( message );
-        
+
         AddResponse response = null;
-        if( listener == null )
+        if ( listener == null )
         {
             try
             {
                 long timeout = getTimeout( addRequest.getTimeout() );
                 response = ( AddResponse ) addFuture.get( timeout, TimeUnit.MILLISECONDS );
-                
+
                 if ( response == null )
                 {
                     LOG.error( "Add failed : timeout occured" );
                     throw new LdapException( TIME_OUT_ERROR );
                 }
             }
-            catch( InterruptedException ie )
+            catch ( InterruptedException ie )
             {
                 LOG.error( OPERATION_CANCELLED, ie );
                 throw new LdapException( OPERATION_CANCELLED, ie );
             }
-            catch( Exception e )
+            catch ( Exception e )
             {
                 LOG.error( NO_RESPONSE_ERROR );
                 removeFromMaps( newId );
@@ -730,27 +729,27 @@
         }
         else
         {
-            listenerMap.put( newId, listener );            
+            listenerMap.put( newId, listener );
         }
 
         return response;
     }
 
-    
+
     /**
      * converts the AddResponseCodec to AddResponse.
      */
     private AddResponse convert( AddResponseCodec addRespCodec )
     {
         AddResponse addResponse = new AddResponse();
-        
+
         addResponse.setMessageId( addRespCodec.getMessageId() );
         addResponse.setLdapResult( convert( addRespCodec.getLdapResult() ) );
-        
+
         return addResponse;
     }
 
-    
+
     //------------------------ The LDAP operations ------------------------//
 
     /**
@@ -764,11 +763,11 @@
     {
         AbandonRequest abandonRequest = new AbandonRequest();
         abandonRequest.setAbandonedMessageId( messageId );
-        
+
         abandonInternal( abandonRequest );
     }
 
-    
+
     /**
      * An abandon request essentially with the request message ID of the operation to be cancelled
      * and/or potentially some controls and timeout (the controls and timeout are not mandatory).
@@ -781,8 +780,8 @@
     {
         abandonInternal( abandonRequest );
     }
-    
-    
+
+
     /**
      * Internal AbandonRequest handling
      */
@@ -799,16 +798,16 @@
 
         // Create the inner abandonRequest
         AbandonRequestCodec request = new AbandonRequestCodec();
-        
+
         // Inject the data into the request
         request.setAbandonedMessageId( abandonRequest.getAbandonedMessageId() );
-        
+
         // Inject the request into the message
         message.setProtocolOP( request );
-        
+
         // Inject the controls
         setControls( abandonRequest.getControls(), message );
-        
+
         LOG.debug( "-----------------------------------------------------------------" );
         LOG.debug( "Sending request \n{}", message );
 
@@ -824,13 +823,14 @@
 
         // if the listener is not null, this is a async operation and no need to
         // send cancel signal on future, sending so will leave a dangling poision object in the corresponding queue
-        if( listener != null )
+        if ( listener != null )
         {
             LOG.debug( "removed the listener associated with the abandoned operation with id {}", abandonId );
         }
-        else // this is a sync operation send cancel signal to the corresponding ResponseFuture
+        else
+        // this is a sync operation send cancel signal to the corresponding ResponseFuture
         {
-            if( rf != null )
+            if ( rf != null )
             {
                 LOG.debug( "sending cancel signal to future" );
                 rf.cancel( true );
@@ -838,12 +838,15 @@
             else
             {
                 // this shouldn't happen
-                LOG.error( "There is no future asscoiated with operation message ID {}, perhaps the operation would have been completed", abandonId );
+                LOG
+                    .error(
+                        "There is no future asscoiated with operation message ID {}, perhaps the operation would have been completed",
+                        abandonId );
             }
         }
     }
-    
-    
+
+
     /**
      * Anonymous Bind on a server. 
      *
@@ -855,8 +858,8 @@
 
         return bind( StringTools.EMPTY, StringTools.EMPTY_BYTES );
     }
-    
-    
+
+
     /**
      * An Unauthenticated Authentication Bind on a server. (cf RFC 4513,
      * par 5.1.2)
@@ -872,7 +875,7 @@
         return bind( name, StringTools.EMPTY_BYTES );
     }
 
-    
+
     /**
      * An Unauthenticated Authentication Bind on a server. (cf RFC 4513,
      * par 5.1.2)
@@ -896,7 +899,7 @@
         }
     }
 
-    
+
     /**
      * Simple Bind on a server.
      *
@@ -935,7 +938,7 @@
         }
     }
 
-    
+
     /**
      * Simple Bind on a server.
      *
@@ -943,14 +946,14 @@
      * @param credentials The password.
      * @return The BindResponse LdapResponse 
      */
-    public BindResponse bind( LdapDN name, byte[] credentials )  throws LdapException, IOException
+    public BindResponse bind( LdapDN name, byte[] credentials ) throws LdapException, IOException
     {
         LOG.debug( "Bind request : {}", name );
 
         return bind( name.getName(), credentials );
     }
 
-    
+
     /**
      * Simple Bind on a server.
      *
@@ -959,7 +962,7 @@
      * @param credentials The password.
      * @return The BindResponse LdapResponse 
      */
-    public BindResponse bind( String name, byte[] credentials )  throws LdapException, IOException
+    public BindResponse bind( String name, byte[] credentials ) throws LdapException, IOException
     {
         LOG.debug( "Bind request : {}", name );
 
@@ -967,7 +970,7 @@
         BindRequest bindRequest = new BindRequest();
         bindRequest.setName( name );
         bindRequest.setCredentials( credentials );
-        
+
         BindResponse response = bind( bindRequest );
 
         if ( LOG.isDebugEnabled() )
@@ -981,11 +984,11 @@
                 LOG.debug( " Bind failure {}", response );
             }
         }
-        
+
         return response;
     }
-    
-    
+
+
     /**
      * Bind to the server using a BindRequest object.
      *
@@ -996,29 +999,29 @@
     public BindResponse bind( BindRequest bindRequest ) throws LdapException, IOException
     {
         BindFuture bindFuture = bind( bindRequest, null );
-        
+
         // Get the result from the future
         try
         {
             // Read the response, waiting for it if not available immediately
             long timeout = getTimeout( bindRequest.getTimeout() );
-            
+
             // Get the response, blocking
-            BindResponse bindResponse = (BindResponse)bindFuture.get( timeout, TimeUnit.MILLISECONDS );
+            BindResponse bindResponse = ( BindResponse ) bindFuture.get( timeout, TimeUnit.MILLISECONDS );
 
             // Everything is fine, return the response
             LOG.debug( "Bind successful : {}", bindResponse );
-            
+
             return bindResponse;
         }
         catch ( TimeoutException te )
         {
             // Send an abandon request
-            if( !bindFuture.isCancelled() )
+            if ( !bindFuture.isCancelled() )
             {
                 abandon( bindRequest.getMessageId() );
             }
-            
+
             // We didn't received anything : this is an error
             LOG.error( "Bind failed : timeout occured" );
             throw new LdapException( TIME_OUT_ERROR );
@@ -1029,18 +1032,18 @@
             LOG.error( NO_RESPONSE_ERROR, ie );
             LdapException ldapException = new LdapException( NO_RESPONSE_ERROR );
             ldapException.initCause( ie );
-            
+
             // Send an abandon request
-            if( !bindFuture.isCancelled() )
+            if ( !bindFuture.isCancelled() )
             {
                 abandon( bindRequest.getMessageId() );
             }
-            
+
             throw ldapException;
         }
     }
-    
-    
+
+
     /**
      * Create a LdapMessage ready to be sent.
      */
@@ -1053,18 +1056,18 @@
         // As it's a Bind request, reset the MessageId 
         // value to zero.
         messageId.set( 0 );
-        
+
         // the bind request should always start with message id 1 (One)
         int newId = messageId.incrementAndGet();
         bindRequest.setMessageId( newId );
         bindMessage.setMessageId( newId );
-        
+
         // Create a new codec BindRequest object
-        BindRequestCodec request =  new BindRequestCodec();
-        
+        BindRequestCodec request = new BindRequestCodec();
+
         // Set the version
         request.setVersion( LdapConnectionConfig.LDAP_V3 );
-        
+
         // Set the name
         try
         {
@@ -1080,36 +1083,37 @@
 
             throw ldapException;
         }
-        
+
         // Set the credentials
         LdapAuthentication authentication = null;
-        
+
         if ( bindRequest.isSimple() )
         {
             // Simple bind
             authentication = new SimpleAuthentication();
-            ((SimpleAuthentication)authentication).setSimple( bindRequest.getCredentials() );
+            ( ( SimpleAuthentication ) authentication ).setSimple( bindRequest.getCredentials() );
         }
         else
         {
             // SASL bind
             authentication = new SaslCredentials();
-            ((SaslCredentials)authentication).setCredentials( bindRequest.getCredentials() );
-            ((SaslCredentials)authentication).setMechanism( bindRequest.getSaslMechanism() );
+            ( ( SaslCredentials ) authentication ).setCredentials( bindRequest.getCredentials() );
+            ( ( SaslCredentials ) authentication ).setMechanism( bindRequest.getSaslMechanism() );
         }
-        
+
         // The authentication
         request.setAuthentication( authentication );
-        
+
         // Stores the BindRequest into the message
         bindMessage.setProtocolOP( request );
-        
+
         // Add the controls
         setControls( bindRequest.getControls(), bindMessage );
-        
+
         return bindMessage;
     }
 
+
     /**
      * Do a non-blocking bind
      *
@@ -1117,11 +1121,11 @@
      * @param listener The listener 
      * @return BindFuture A future
      */
-    public BindFuture bind( BindRequest bindRequest, BindListener bindListener ) throws LdapException, IOException 
+    public BindFuture bind( BindRequest bindRequest, BindListener bindListener ) throws LdapException, IOException
     {
         // First try to connect, if we aren't already connected.
         connect();
-        
+
         // If the session has not been establish, or is closed, we get out immediately
         checkSession();
 
@@ -1129,7 +1133,7 @@
         LdapMessageCodec bindMessage = createBindMessage( bindRequest );
 
         int newId = bindMessage.getMessageId();
-        
+
         if ( bindListener != null )
         {
             // This is an asynchronous bind
@@ -1141,7 +1145,7 @@
 
         BlockingQueue<BindResponse> bindResponseQueue = new LinkedBlockingQueue<BindResponse>();
         respQueueMap.put( newId, bindResponseQueue );
-        
+
         // Create a future for this Bind opeation
         BindFuture bindFuture = new BindFuture( bindResponseQueue );
 
@@ -1156,14 +1160,14 @@
 
         // Send the request to the server
         WriteFuture writeFuture = ldapSession.write( bindMessage );
-        
+
         // Wait for the message to be sent to the server
         writeFuture.awaitUninterruptibly( timeOut );
-        
+
         return bindFuture;
     }
-    
-    
+
+
     /**
      * Do a search, on the base object, using the given filter. The
      * SearchRequest parameters default to :
@@ -1181,12 +1185,12 @@
      * @param scope The sarch scope : OBJECT, ONELEVEL or SUBTREE 
      * @return A cursor on the result. 
      */
-    public Cursor<SearchResponse> search( String baseDn, String filter, SearchScope scope, 
-        String... attributes ) throws LdapException
+    public Cursor<SearchResponse> search( String baseDn, String filter, SearchScope scope, String... attributes )
+        throws LdapException
     {
         // Create a new SearchRequest object
         SearchRequest searchRequest = new SearchRequest();
-        
+
         searchRequest.setBaseDn( baseDn );
         searchRequest.setFilter( filter );
         searchRequest.setScope( scope );
@@ -1196,8 +1200,8 @@
         // Process the request in blocking mode
         return searchInternal( searchRequest, null );
     }
-    
-    
+
+
     /**
      * Do a search, on the base object, using the given filter. The
      * SearchRequest parameters default to :
@@ -1220,8 +1224,8 @@
     {
         searchInternal( searchRequest, listener );
     }
-    
-    
+
+
     /**
      * performs search in a synchronous mode (as if a null search listener is passed) 
      * @see #search(SearchRequest, SearchListener)
@@ -1231,25 +1235,25 @@
         return searchInternal( searchRequest, null );
     }
 
-    
+
     private Cursor<SearchResponse> searchInternal( SearchRequest searchRequest, SearchListener searchListener )
         throws LdapException
     {
         // If the session has not been establish, or is closed, we get out immediately
         checkSession();
-    
+
         // Create the new message and update the messageId
         LdapMessageCodec searchMessage = new LdapMessageCodec();
-        
+
         // Creates the messageID and stores it into the 
         // initial message and the transmitted message.
         int newId = messageId.incrementAndGet();
         searchRequest.setMessageId( newId );
         searchMessage.setMessageId( newId );
-        
+
         // Create a new codec SearchRequest object
-        SearchRequestCodec request =  new SearchRequestCodec();
-        
+        SearchRequestCodec request = new SearchRequestCodec();
+
         // Set the name
         try
         {
@@ -1265,29 +1269,29 @@
 
             throw ldapException;
         }
-        
+
         // Set the scope
         request.setScope( searchRequest.getScope() );
-        
+
         // Set the typesOnly flag
         request.setDerefAliases( searchRequest.getDerefAliases().getValue() );
-        
+
         // Set the timeLimit
         request.setTimeLimit( searchRequest.getTimeLimit() );
-        
+
         // Set the sizeLimit
         request.setSizeLimit( searchRequest.getSizeLimit() );
-        
+
         // Set the typesOnly flag
         request.setTypesOnly( searchRequest.getTypesOnly() );
-    
+
         // Set the filter
         Filter filter = null;
-        
+
         try
         {
             ExprNode filterNode = FilterParser.parse( searchRequest.getFilter() );
-            
+
             filter = LdapTransformer.transformFilter( filterNode );
         }
         catch ( ParseException pe )
@@ -1299,39 +1303,38 @@
 
             throw ldapException;
         }
-        
+
         request.setFilter( filter );
-        
+
         // Set the attributes
         Set<String> attributes = searchRequest.getAttributes();
-        
+
         if ( attributes != null )
         {
-            for ( String attribute:attributes )
+            for ( String attribute : attributes )
             {
                 request.addAttribute( attribute );
             }
         }
-        
+
         // Stores the SearchRequest into the message
         searchMessage.setProtocolOP( request );
-        
+
         // Add the controls
         setControls( searchRequest.getControls(), searchMessage );
-    
+
         LOG.debug( "-----------------------------------------------------------------" );
         LOG.debug( "Sending request \n{}", searchMessage );
-    
+
         BlockingQueue<SearchResponse> searchResponseQueue = new LinkedBlockingQueue<SearchResponse>();
         respQueueMap.put( newId, searchResponseQueue );
-        
+
         ResponseFuture searchFuture = new ResponseFuture( searchResponseQueue );
         futureMap.put( newId, searchFuture );
 
         // Send the request to the server
         ldapSession.write( searchMessage );
-    
-        
+
         if ( searchListener == null )
         {
             // Read the response, waiting for it if not available immediately
@@ -1342,7 +1345,7 @@
                 List<SearchResponse> searchResponses = new ArrayList<SearchResponse>();
 
                 // We may have more than one response, so loop on the queue
-                do 
+                do
                 {
                     response = ( SearchResponse ) searchFuture.get( timeout, TimeUnit.MILLISECONDS );
 
@@ -1351,7 +1354,7 @@
                     {
                         // Send an abandon request
                         abandon( searchMessage.getSearchRequest().getMessageId() );
-                        
+
                         // We didn't received anything : this is an error
                         LOG.error( "Search failed : timeout occured" );
 
@@ -1372,10 +1375,10 @@
                 while ( !( response instanceof SearchResultDone ) );
 
                 LOG.debug( "Search successful, {} elements found", searchResponses.size() );
-                
+
                 return new ListCursor<SearchResponse>( searchResponses );
             }
-            catch( InterruptedException ie )
+            catch ( InterruptedException ie )
             {
                 LOG.error( OPERATION_CANCELLED, ie );
                 throw new LdapException( OPERATION_CANCELLED, ie );
@@ -1385,13 +1388,13 @@
                 LOG.error( NO_RESPONSE_ERROR, e );
                 LdapException ldapException = new LdapException( NO_RESPONSE_ERROR );
                 ldapException.initCause( e );
-                
+
                 // Send an abandon request
-                if( !searchFuture.isCancelled() )
+                if ( !searchFuture.isCancelled() )
                 {
                     abandon( searchMessage.getSearchRequest().getMessageId() );
                 }
-                
+
                 throw ldapException;
             }
         }
@@ -1404,7 +1407,7 @@
         }
     }
 
-    
+
     //------------------------ The LDAP operations ------------------------//
     // Unbind operations                                                   //
     //---------------------------------------------------------------------//
@@ -1415,10 +1418,10 @@
     {
         // If the session has not been establish, or is closed, we get out immediately
         checkSession();
-        
+
         // Create the UnbindRequest
         UnBindRequestCodec unbindRequest = new UnBindRequestCodec();
-        
+
         // Encode the request
         LdapMessageCodec unbindMessage = new LdapMessageCodec();
 
@@ -1429,23 +1432,23 @@
         unbindMessage.setMessageId( newId );
 
         unbindMessage.setProtocolOP( unbindRequest );
-        
+
         LOG.debug( "-----------------------------------------------------------------" );
         LOG.debug( "Sending Unbind request \n{}", unbindMessage );
-        
+
         // Send the request to the server
         WriteFuture unbindFuture = ldapSession.write( unbindMessage );
-        
+
         unbindFuture.awaitUninterruptibly();
-        
+
         //  We now have to close the connection
         //close();
 
         // And get out
         LOG.debug( "Unbind successful" );
     }
-    
-    
+
+
     /**
      * Set the connector to use.
      *
@@ -1467,54 +1470,55 @@
     {
         this.timeOut = timeOut;
     }
-    
-    
+
+
     /**
      * Handle the incoming LDAP messages. This is where we feed the cursor for search 
      * requests, or call the listener. 
      */
-    public void messageReceived( IoSession session, Object message) throws Exception 
+    public void messageReceived( IoSession session, Object message ) throws Exception
     {
         // Feed the response and store it into the session
-        LdapMessageCodec response = (LdapMessageCodec)message;
+        LdapMessageCodec response = ( LdapMessageCodec ) message;
 
         LOG.debug( "-------> {} Message received <-------", response.getMessageTypeName() );
-        
+
         // this check is necessary to prevent adding an abandoned operation's
         // result(s) to corresponding queue
         ResponseFuture rf = futureMap.get( response.getMessageId() );
-        
-        if( rf == null )
+
+        if ( rf == null )
         {
-            LOG.error( "There is no future associated with the messageId {}, ignoring the message", response.getMessageId()  );
+            LOG.error( "There is no future associated with the messageId {}, ignoring the message", response
+                .getMessageId() );
             return;
         }
-        
+
         SearchListener searchListener = null;
         int messageId = response.getMessageId();
 
         switch ( response.getMessageType() )
         {
-            case LdapConstants.ADD_RESPONSE :
+            case LdapConstants.ADD_RESPONSE:
                 // Store the response into the responseQueue
                 AddResponseCodec addRespCodec = response.getAddResponse();
                 addRespCodec.addControl( response.getCurrentControl() );
                 addRespCodec.setMessageId( messageId );
-                
+
                 futureMap.remove( addRespCodec.getMessageId() );
                 AddListener addListener = ( AddListener ) listenerMap.remove( addRespCodec.getMessageId() );
                 AddResponse addResp = convert( addRespCodec );
-                if( addListener != null )
+                if ( addListener != null )
                 {
                     addListener.entryAdded( this, addResp );
                 }
                 else
                 {
-                    addToRespQueueAndRemoveQueueRef( messageId, addResp ); 
+                    addToRespQueueAndRemoveQueueRef( messageId, addResp );
                 }
                 break;
-                
-            case LdapConstants.BIND_RESPONSE: 
+
+            case LdapConstants.BIND_RESPONSE:
                 // Store the response into the responseQueue
                 BindResponseCodec bindResponseCodec = response.getBindResponse();
                 bindResponseCodec.setMessageId( messageId );
@@ -1522,10 +1526,10 @@
                 BindResponse bindResponse = convert( bindResponseCodec );
 
                 futureMap.remove( bindResponseCodec.getMessageId() );
-                
+
                 // remove the listener from the listener map
                 BindListener bindListener = ( BindListener ) listenerMap.remove( bindResponseCodec.getMessageId() );
-                
+
                 if ( bindListener != null )
                 {
                     bindListener.bindCompleted( this, bindResponse );
@@ -1535,57 +1539,57 @@
                     // Store the response into the responseQueue
                     addToRespQueueAndRemoveQueueRef( messageId, bindResponse );
                 }
-                
+
                 break;
-                
-            case LdapConstants.COMPARE_RESPONSE :
+
+            case LdapConstants.COMPARE_RESPONSE:
                 // Store the response into the responseQueue
                 CompareResponseCodec compResCodec = response.getCompareResponse();
                 compResCodec.setMessageId( messageId );
                 compResCodec.addControl( response.getCurrentControl() );
                 CompareResponse compRes = convert( compResCodec );
-                
+
                 futureMap.remove( compRes.getMessageId() );
-                
+
                 CompareListener listener = ( CompareListener ) listenerMap.remove( compRes.getMessageId() );
-                if( listener != null )
+                if ( listener != null )
                 {
                     listener.attributeCompared( this, compRes );
                 }
                 else
                 {
-                    addToRespQueueAndRemoveQueueRef( messageId, compRes ); 
+                    addToRespQueueAndRemoveQueueRef( messageId, compRes );
                 }
-                
+
                 break;
-                
-            case LdapConstants.DEL_RESPONSE :
+
+            case LdapConstants.DEL_RESPONSE:
                 // Store the response into the responseQueue
                 DelResponseCodec delRespCodec = response.getDelResponse();
                 delRespCodec.setMessageId( messageId );
                 delRespCodec.addControl( response.getCurrentControl() );
                 DeleteResponse delResp = convert( delRespCodec );
-                
+
                 futureMap.remove( delResp.getMessageId() );
                 DeleteListener delListener = ( DeleteListener ) listenerMap.remove( delResp.getMessageId() );
-                if( delListener != null )
+                if ( delListener != null )
                 {
                     delListener.entryDeleted( this, delResp );
                 }
                 else
                 {
-                    addToRespQueueAndRemoveQueueRef( messageId, delResp ); 
+                    addToRespQueueAndRemoveQueueRef( messageId, delResp );
                 }
                 break;
-                
-            case LdapConstants.EXTENDED_RESPONSE :
+
+            case LdapConstants.EXTENDED_RESPONSE:
                 ExtendedResponseCodec extResCodec = response.getExtendedResponse();
                 extResCodec.setMessageId( messageId );
                 extResCodec.addControl( response.getCurrentControl() );
-                
+
                 ExtendedResponse extResponse = convert( extResCodec );
                 ExtendedListener extListener = ( ExtendedListener ) listenerMap.remove( extResCodec.getMessageId() );
-                
+
                 if ( extListener != null )
                 {
                     extListener.extendedOperationCompleted( this, extResponse );
@@ -1593,21 +1597,21 @@
                 else
                 {
                     // Store the response into the responseQueue
-                    addToRespQueueAndRemoveQueueRef( messageId, extResponse ); 
+                    addToRespQueueAndRemoveQueueRef( messageId, extResponse );
                 }
-                
+
                 break;
-                
-                //FIXME the way we handle the intermediate responses is broken
+
+            //FIXME the way we handle the intermediate responses is broken
             case LdapConstants.INTERMEDIATE_RESPONSE:
                 // Store the response into the responseQueue
-                IntermediateResponseCodec intermediateResponseCodec = 
-                    response.getIntermediateResponse();
+                IntermediateResponseCodec intermediateResponseCodec = response.getIntermediateResponse();
                 intermediateResponseCodec.setMessageId( messageId );
                 intermediateResponseCodec.addControl( response.getCurrentControl() );
-                
-                IntermediateResponse intrmResp = convert( intermediateResponseCodec );                
-                IntermediateResponseListener intrmListener = ( IntermediateResponseListener ) listenerMap.get( intermediateResponseCodec.getMessageId() ); 
+
+                IntermediateResponse intrmResp = convert( intermediateResponseCodec );
+                IntermediateResponseListener intrmListener = ( IntermediateResponseListener ) listenerMap
+                    .get( intermediateResponseCodec.getMessageId() );
                 if ( intrmListener != null )
                 {
                     intrmListener.responseReceived( this, intrmResp );
@@ -1617,10 +1621,10 @@
                     // Store the response into the responseQueue
                     addToRespQueueAndRemoveQueueRef( messageId, intrmResp );
                 }
-                
+
                 break;
-     
-            case LdapConstants.MODIFY_RESPONSE :
+
+            case LdapConstants.MODIFY_RESPONSE:
                 ModifyResponseCodec modRespCodec = response.getModifyResponse();
                 modRespCodec.setMessageId( messageId );
                 modRespCodec.addControl( response.getCurrentControl() );
@@ -1628,27 +1632,27 @@
 
                 futureMap.remove( modResp.getMessageId() );
                 ModifyListener modListener = ( ModifyListener ) listenerMap.remove( modResp.getMessageId() );
-                
-                if( modListener != null )
+
+                if ( modListener != null )
                 {
                     modListener.modifyCompleted( this, modResp );
                 }
                 else
                 {
-                    addToRespQueueAndRemoveQueueRef( messageId, modResp ); 
+                    addToRespQueueAndRemoveQueueRef( messageId, modResp );
                 }
                 break;
-                
-            case LdapConstants.MODIFYDN_RESPONSE :
-                
+
+            case LdapConstants.MODIFYDN_RESPONSE:
+
                 ModifyDNResponseCodec modDnCodec = response.getModifyDNResponse();
                 modDnCodec.addControl( response.getCurrentControl() );
                 modDnCodec.setMessageId( messageId );
                 ModifyDnResponse modDnResp = convert( modDnCodec );
-                
+
                 futureMap.remove( modDnCodec.getMessageId() );
                 ModifyDnListener modDnListener = ( ModifyDnListener ) listenerMap.remove( modDnCodec.getMessageId() );
-                if( modDnListener != null )
+                if ( modDnListener != null )
                 {
                     modDnListener.modifyDnCompleted( this, modDnResp );
                 }
@@ -1658,15 +1662,14 @@
                     addToRespQueueAndRemoveQueueRef( messageId, modDnResp );
                 }
                 break;
-                
+
             case LdapConstants.SEARCH_RESULT_DONE:
                 // Store the response into the responseQueue
-                SearchResultDoneCodec searchResultDoneCodec = 
-                    response.getSearchResultDone();
+                SearchResultDoneCodec searchResultDoneCodec = response.getSearchResultDone();
                 searchResultDoneCodec.setMessageId( messageId );
                 searchResultDoneCodec.addControl( response.getCurrentControl() );
                 SearchResultDone srchDone = convert( searchResultDoneCodec );
-                
+
                 futureMap.remove( searchResultDoneCodec.getMessageId() );
                 // search listener has to be removed from listener map only here
                 searchListener = ( SearchListener ) listenerMap.remove( searchResultDoneCodec.getMessageId() );
@@ -1678,19 +1681,18 @@
                 {
                     addToRespQueueAndRemoveQueueRef( messageId, srchDone );
                 }
-                
+
                 break;
-            
+
             case LdapConstants.SEARCH_RESULT_ENTRY:
                 // Store the response into the responseQueue
-                SearchResultEntryCodec searchResultEntryCodec = 
-                    response.getSearchResultEntry();
+                SearchResultEntryCodec searchResultEntryCodec = response.getSearchResultEntry();
                 searchResultEntryCodec.setMessageId( messageId );
                 searchResultEntryCodec.addControl( response.getCurrentControl() );
-                
+
                 SearchResultEntry srchEntry = convert( searchResultEntryCodec );
                 searchListener = ( SearchListener ) listenerMap.get( searchResultEntryCodec.getMessageId() );
-                
+
                 if ( searchListener != null )
                 {
                     searchListener.entryFound( this, srchEntry );
@@ -1700,13 +1702,12 @@
                     // shouldn't call addToRespQueueAndRemoveQueueRef
                     respQueueMap.get( messageId ).add( srchEntry );
                 }
-                
+
                 break;
-                       
+
             case LdapConstants.SEARCH_RESULT_REFERENCE:
                 // Store the response into the responseQueue
-                SearchResultReferenceCodec searchResultReferenceCodec = 
-                    response.getSearchResultReference();
+                SearchResultReferenceCodec searchResultReferenceCodec = response.getSearchResultReference();
                 searchResultReferenceCodec.setMessageId( messageId );
                 searchResultReferenceCodec.addControl( response.getCurrentControl() );
 
@@ -1723,12 +1724,14 @@
                 }
 
                 break;
-                       
-             default: LOG.error( "~~~~~~~~~~~~~~~~~~~~~ Unknown message type {} ~~~~~~~~~~~~~~~~~~~~~", response.getMessageTypeName() );
+
+            default:
+                LOG.error( "~~~~~~~~~~~~~~~~~~~~~ Unknown message type {} ~~~~~~~~~~~~~~~~~~~~~", response
+                    .getMessageTypeName() );
         }
     }
-    
-    
+
+
     /**
      * 
      * modifies all the attributes present in the entry by applying the same operation.
@@ -1740,24 +1743,24 @@
      */
     public ModifyResponse modify( Entry entry, ModificationOperation modOp ) throws LdapException
     {
-        if( entry == null )
+        if ( entry == null )
         {
             LOG.debug( "received a null entry for modification" );
             throw new NullPointerException( "Entry to be modified cannot be null" );
         }
-        
+
         ModifyRequest modReq = new ModifyRequest( entry.getDn() );
-        
+
         Iterator<EntryAttribute> itr = entry.iterator();
-        while( itr.hasNext() )
+        while ( itr.hasNext() )
         {
             modReq.addModification( itr.next(), modOp );
         }
-        
+
         return modify( modReq, null );
     }
-    
-    
+
+
     /**
      * 
      * performs modify operation based on the modifications present in the ModifyRequest.
@@ -1767,16 +1770,16 @@
      * @return the modify operation's response, null if non-null listener is provided
      * @throws LdapException in case of modify operation failure or timeout happens
      */
-    public ModifyResponse modify( ModifyRequest modRequest, ModifyListener listener )  throws LdapException
+    public ModifyResponse modify( ModifyRequest modRequest, ModifyListener listener ) throws LdapException
     {
         checkSession();
-    
+
         LdapMessageCodec modifyMessage = new LdapMessageCodec();
-        
+
         int newId = messageId.incrementAndGet();
         modRequest.setMessageId( newId );
         modifyMessage.setMessageId( newId );
-        
+
         ModifyRequestCodec modReqCodec = new ModifyRequestCodec();
         modReqCodec.setModifications( modRequest.getMods() );
         modReqCodec.setObject( modRequest.getDn() );
@@ -1786,20 +1789,20 @@
 
         BlockingQueue<ModifyResponse> modifyResponseQueue = new LinkedBlockingQueue<ModifyResponse>();
         respQueueMap.put( newId, modifyResponseQueue );
-        
+
         ResponseFuture modifyFuture = new ResponseFuture( modifyResponseQueue );
         futureMap.put( newId, modifyFuture );
-        
+
         ldapSession.write( modifyMessage );
-        
+
         ModifyResponse response = null;
-        if( listener == null )
+        if ( listener == null )
         {
             try
             {
                 long timeout = getTimeout( modRequest.getTimeout() );
                 response = ( ModifyResponse ) modifyFuture.get( timeout, TimeUnit.MILLISECONDS );
-                
+
                 if ( response == null )
                 {
                     LOG.error( "Modify failed : timeout occured" );
@@ -1807,12 +1810,12 @@
                     throw new LdapException( TIME_OUT_ERROR );
                 }
             }
-            catch( InterruptedException ie )
+            catch ( InterruptedException ie )
             {
                 LOG.error( OPERATION_CANCELLED, ie );
                 throw new LdapException( OPERATION_CANCELLED, ie );
             }
-            catch( Exception e )
+            catch ( Exception e )
             {
                 LOG.error( NO_RESPONSE_ERROR );
                 removeFromMaps( newId );
@@ -1824,18 +1827,18 @@
         {
             listenerMap.put( newId, listener );
         }
-        
+
         return response;
     }
-    
-    
+
+
     /**
      * converts the ModifyResponseCodec to ModifyResponse.
      */
     private ModifyResponse convert( ModifyResponseCodec modRespCodec )
     {
         ModifyResponse modResponse = new ModifyResponse();
-        
+
         modResponse.setMessageId( modRespCodec.getMessageId() );
         modResponse.setLdapResult( convert( modRespCodec.getLdapResult() ) );
 
@@ -1852,7 +1855,7 @@
         return rename( entryDn, newRdn, true );
     }
 
-    
+
     /**
      * renames the given entryDn with new RDN and deletes the old RDN.
      * @see #rename(LdapDN, RDN, boolean)
@@ -1861,8 +1864,8 @@
     {
         return rename( entryDn, newRdn, true );
     }
-    
-    
+
+
     /**
      * @see #rename(LdapDN, RDN, boolean)
      */
@@ -1872,14 +1875,14 @@
         {
             return rename( new LdapDN( entryDn ), new RDN( newRdn ), deleteOldRdn );
         }
-        catch( InvalidNameException e )
+        catch ( InvalidNameException e )
         {
             LOG.error( e.getMessage(), e );
             throw new LdapException( e.getMessage(), e );
         }
     }
-    
-    
+
+
     /**
      * 
      * renames the given entryDn with new RDN and deletes the old Rdn if 
@@ -1897,10 +1900,10 @@
         modDnRequest.setEntryDn( entryDn );
         modDnRequest.setNewRdn( newRdn );
         modDnRequest.setDeleteOldRdn( deleteOldRdn );
-        
+
         return modifyDn( modDnRequest, null );
     }
-    
+
 
     /**
      * @see #move(LdapDN, LdapDN) 
@@ -1911,13 +1914,13 @@
         {
             return move( new LdapDN( entryDn ), new LdapDN( newSuperiorDn ) );
         }
-        catch( InvalidNameException e )
+        catch ( InvalidNameException e )
         {
             LOG.error( e.getMessage(), e );
             throw new LdapException( e.getMessage(), e );
         }
     }
-    
+
 
     /**
      * moves the given entry DN under the new superior DN
@@ -1932,14 +1935,14 @@
         ModifyDnRequest modDnRequest = new ModifyDnRequest();
         modDnRequest.setEntryDn( entryDn );
         modDnRequest.setNewSuperior( newSuperiorDn );
-        
+
         //TODO not setting the below value is resulting in error
         modDnRequest.setNewRdn( entryDn.getRdn() );
-        
+
         return modifyDn( modDnRequest, null );
     }
 
-    
+
     /**
      * 
      * performs the modifyDn operation based on the given ModifyDnRequest.
@@ -1952,9 +1955,9 @@
     public ModifyDnResponse modifyDn( ModifyDnRequest modDnRequest, ModifyDnListener listener ) throws LdapException
     {
         checkSession();
-    
+
         LdapMessageCodec modifyDnMessage = new LdapMessageCodec();
-        
+
         int newId = messageId.incrementAndGet();
         modDnRequest.setMessageId( newId );
         modifyDnMessage.setMessageId( newId );
@@ -1964,26 +1967,26 @@
         modDnCodec.setNewRDN( modDnRequest.getNewRdn() );
         modDnCodec.setDeleteOldRDN( modDnRequest.isDeleteOldRdn() );
         modDnCodec.setNewSuperior( modDnRequest.getNewSuperior() );
-        
+
         modifyDnMessage.setProtocolOP( modDnCodec );
         setControls( modDnRequest.getControls(), modifyDnMessage );
-        
+
         BlockingQueue<ModifyDnResponse> modifyDNResponseQueue = new LinkedBlockingQueue<ModifyDnResponse>();
         respQueueMap.put( newId, modifyDNResponseQueue );
-        
+
         ResponseFuture modifyDNFuture = new ResponseFuture( modifyDNResponseQueue );
         futureMap.put( newId, modifyDNFuture );
-        
+
         ldapSession.write( modifyDnMessage );
-        
-        if( listener == null )
+
+        if ( listener == null )
         {
             ModifyDnResponse response = null;
             try
             {
                 long timeout = getTimeout( modDnRequest.getTimeout() );
                 response = ( ModifyDnResponse ) modifyDNFuture.get( timeout, TimeUnit.MILLISECONDS );
-                
+
                 if ( response == null )
                 {
                     LOG.error( "Modifying DN failed : timeout occured" );
@@ -1991,12 +1994,12 @@
                     throw new LdapException( TIME_OUT_ERROR );
                 }
             }
-            catch( InterruptedException ie )
+            catch ( InterruptedException ie )
             {
                 LOG.error( OPERATION_CANCELLED, ie );
                 throw new LdapException( OPERATION_CANCELLED, ie );
             }
-            catch( Exception e )
+            catch ( Exception e )
             {
                 LOG.error( NO_RESPONSE_ERROR );
                 removeFromMaps( newId );
@@ -2005,7 +2008,7 @@
                 ldapException.initCause( e );
                 throw ldapException;
             }
-            
+
             return response;
         }
         else
@@ -2014,18 +2017,18 @@
             return null;
         }
     }
-    
-    
+
+
     /**
      * converts the ModifyDnResponseCodec to ModifyResponse.
      */
     private ModifyDnResponse convert( ModifyDNResponseCodec modDnRespCodec )
     {
         ModifyDnResponse modDnResponse = new ModifyDnResponse();
-        
+
         modDnResponse.setMessageId( modDnRespCodec.getMessageId() );
         modDnResponse.setLdapResult( convert( modDnRespCodec.getLdapResult() ) );
-        
+
         return modDnResponse;
     }
 
@@ -2044,14 +2047,14 @@
 
             return delete( deleteRequest, null );
         }
-        catch( InvalidNameException e )
+        catch ( InvalidNameException e )
         {
             LOG.error( e.getMessage(), e );
             throw new LdapException( e.getMessage(), e );
         }
     }
 
-    
+
     /**
      * deletes the entry with the given DN
      *  
@@ -2061,8 +2064,8 @@
     public DeleteResponse delete( LdapDN dn ) throws LdapException
     {
         DeleteRequest deleteRequest = new DeleteRequest( dn );
-        
-        return delete( deleteRequest, null ); 
+
+        return delete( deleteRequest, null );
     }
 
 
@@ -2076,12 +2079,12 @@
     public DeleteResponse deleteTree( LdapDN dn ) throws LdapException
     {
         String treeDeleteOid = "1.2.840.113556.1.4.805";
-        
-        if ( isControlSupported( treeDeleteOid ) ) 
+
+        if ( isControlSupported( treeDeleteOid ) )
         {
             DeleteRequest delRequest = new DeleteRequest( dn );
-            delRequest.add( new ControlImpl( treeDeleteOid ) );
-            return delete( delRequest, null ); 
+            delRequest.add( new CodecControlImpl( treeDeleteOid ) );
+            return delete( delRequest, null );
         }
         else
         {
@@ -2089,7 +2092,7 @@
         }
     }
 
-    
+
     /**
      * deletes the entry with the given DN, and all its children
      *  
@@ -2103,25 +2106,25 @@
         {
             String treeDeleteOid = "1.2.840.113556.1.4.805";
             LdapDN ldapDn = new LdapDN( dn );
-            
-            if ( isControlSupported( treeDeleteOid ) ) 
+
+            if ( isControlSupported( treeDeleteOid ) )
             {
                 DeleteRequest delRequest = new DeleteRequest( ldapDn );
-                delRequest.add( new ControlImpl( treeDeleteOid ) );
-                return delete( delRequest, null ); 
+                delRequest.add( new CodecControlImpl( treeDeleteOid ) );
+                return delete( delRequest, null );
             }
             else
             {
                 return deleteRecursive( ldapDn, null, null );
             }
         }
-        catch( InvalidNameException e )
+        catch ( InvalidNameException e )
         {
             LOG.error( e.getMessage(), e );
             throw new LdapException( e.getMessage(), e );
         }
     }
-    
+
 
     /**
      * removes all child entries present under the given DN and finally the DN itself
@@ -2154,12 +2157,13 @@
      * @param listener  the delete operation response listener 
      * @throws LdapException If the DN is not valid or if the deletion failed
      */
-    private DeleteResponse deleteRecursive( LdapDN dn, Map<LdapDN, Cursor<SearchResponse>> cursorMap, DeleteListener listener ) throws LdapException
+    private DeleteResponse deleteRecursive( LdapDN dn, Map<LdapDN, Cursor<SearchResponse>> cursorMap,
+        DeleteListener listener ) throws LdapException
     {
         LOG.debug( "searching for {}", dn.getName() );
         DeleteResponse delResponse = null;
         Cursor<SearchResponse> cursor = null;
-        
+
         try
         {
             if ( cursorMap == null )
@@ -2167,16 +2171,16 @@
                 cursorMap = new HashMap<LdapDN, Cursor<SearchResponse>>();
             }
 
-            cursor = cursorMap.get( dn ); 
-            
-            if( cursor == null )
+            cursor = cursorMap.get( dn );
+
+            if ( cursor == null )
             {
-                cursor = search( dn.getName(), "(objectClass=*)", SearchScope.ONELEVEL, (String[])null ); 
+                cursor = search( dn.getName(), "(objectClass=*)", SearchScope.ONELEVEL, ( String[] ) null );
                 LOG.debug( "putting curosr for {}", dn.getName() );
                 cursorMap.put( dn, cursor );
             }
-            
-            if( ! cursor.next() ) // if this is a leaf entry's DN
+
+            if ( !cursor.next() ) // if this is a leaf entry's DN
             {
                 LOG.debug( "deleting {}", dn.getName() );
                 cursorMap.remove( dn );
@@ -2188,32 +2192,32 @@
                 do
                 {
                     SearchResponse searchResp = cursor.get();
-                    
-                    if( searchResp instanceof SearchResultEntry )
+
+                    if ( searchResp instanceof SearchResultEntry )
                     {
                         SearchResultEntry searchResult = ( SearchResultEntry ) searchResp;
                         deleteRecursive( searchResult.getEntry().getDn(), cursorMap, listener );
                     }
                 }
-                while( cursor.next() );
-                
+                while ( cursor.next() );
+
                 cursorMap.remove( dn );
                 cursor.close();
                 LOG.debug( "deleting {}", dn.getName() );
                 delResponse = delete( new DeleteRequest( dn ), listener );
             }
         }
-        catch( Exception e )
+        catch ( Exception e )
         {
             String msg = "Failed to delete child entries under the DN " + dn.getName();
             LOG.error( msg, e );
             throw new LdapException( msg, e );
         }
-        
+
         return delResponse;
     }
-    
-    
+
+
     /**
      * Performs a synchronous delete operation based on the delete request object.
      *  
@@ -2221,7 +2225,7 @@
      * @return delete operation's response, null if a non-null listener value is provided
      * @throws LdapException If the DN is not valid or if the deletion failed
      */
-    public DeleteResponse delete( DeleteRequest delRequest )  throws LdapException
+    public DeleteResponse delete( DeleteRequest delRequest ) throws LdapException
     {
         // Just call the delete method with a null listener
         return delete( delRequest, null );
@@ -2236,12 +2240,12 @@
      * @return delete operation's response, null if a non-null listener value is provided
      * @throws LdapException If the DN is not valid or if the deletion failed
      */
-    public DeleteResponse delete( DeleteRequest delRequest, DeleteListener listener )  throws LdapException
+    public DeleteResponse delete( DeleteRequest delRequest, DeleteListener listener ) throws LdapException
     {
         checkSession();
-    
+
         LdapMessageCodec deleteMessage = new LdapMessageCodec();
-        
+
         int newId = messageId.incrementAndGet();
         delRequest.setMessageId( newId );
         deleteMessage.setMessageId( newId );
@@ -2251,24 +2255,24 @@
 
         deleteMessage.setProtocolOP( delCodec );
         setControls( delRequest.getControls(), deleteMessage );
-        
+
         BlockingQueue<DeleteResponse> deleteResponseQueue = new LinkedBlockingQueue<DeleteResponse>();
         respQueueMap.put( newId, deleteResponseQueue );
-        
+
         ResponseFuture deleteFuture = new ResponseFuture( deleteResponseQueue );
         futureMap.put( newId, deleteFuture );
 
         ldapSession.write( deleteMessage );
-        
+
         DeleteResponse response = null;
-        
-        if( listener == null )
+
+        if ( listener == null )
         {
             try
             {
                 long timeout = getTimeout( delRequest.getTimeout() );
                 response = ( DeleteResponse ) deleteFuture.get( timeout, TimeUnit.MILLISECONDS );
-                
+
                 if ( response == null )
                 {
                     LOG.error( "Delete DN failed : timeout occured" );
@@ -2276,12 +2280,12 @@
                     throw new LdapException( TIME_OUT_ERROR );
                 }
             }
-            catch( InterruptedException ie )
+            catch ( InterruptedException ie )
             {
                 LOG.error( OPERATION_CANCELLED, ie );
                 throw new LdapException( OPERATION_CANCELLED, ie );
             }
-            catch( Exception e )
+            catch ( Exception e )
             {
                 LOG.error( NO_RESPONSE_ERROR );
                 removeFromMaps( newId );
@@ -2318,10 +2322,10 @@
             compareRequest.setEntryDn( new LdapDN( dn ) );
             compareRequest.setAttrName( attributeName );
             compareRequest.setValue( value );
-            
+
             return compare( compareRequest, null );
         }
-        catch( Exception e )
+        catch ( Exception e )
         {
             LOG.error( COMPARE_FAILED, e );
             throw new LdapException( COMPARE_FAILED, e );
@@ -2347,10 +2351,10 @@
             compareRequest.setEntryDn( new LdapDN( dn ) );
             compareRequest.setAttrName( attributeName );
             compareRequest.setValue( value );
-            
+
             return compare( compareRequest, null );
         }
-        catch( Exception e )
+        catch ( Exception e )
         {
             LOG.error( COMPARE_FAILED, e );
             throw new LdapException( COMPARE_FAILED, e );
@@ -2376,17 +2380,17 @@
             compareRequest.setEntryDn( new LdapDN( dn ) );
             compareRequest.setAttrName( attributeName );
             compareRequest.setValue( value );
-            
+
             return compare( compareRequest, null );
         }
-        catch( Exception e )
+        catch ( Exception e )
         {
             LOG.error( COMPARE_FAILED, e );
             throw new LdapException( COMPARE_FAILED, e );
         }
     }
 
-    
+
     /**
      * Compares a whether a given attribute's value matches that of the 
      * existing value of the attribute present in the entry with the given DN
@@ -2403,11 +2407,11 @@
         compareRequest.setEntryDn( dn );
         compareRequest.setAttrName( attributeName );
         compareRequest.setValue( value );
-        
+
         return compare( compareRequest, null );
     }
 
-    
+
     /**
      * Compares a whether a given attribute's value matches that of the 
      * existing value of the attribute present in the entry with the given DN
@@ -2424,7 +2428,7 @@
         compareRequest.setEntryDn( dn );
         compareRequest.setAttrName( attributeName );
         compareRequest.setValue( value );
-        
+
         return compare( compareRequest, null );
     }
 
@@ -2445,11 +2449,11 @@
         compareRequest.setEntryDn( dn );
         compareRequest.setAttrName( attributeName );
         compareRequest.setValue( value.get() );
-        
+
         return compare( compareRequest, null );
     }
-    
-    
+
+
     /**
      * compares an entry's attribute's value with that of the given value
      *   
@@ -2461,8 +2465,8 @@
     {
         return compare( compareRequest, null );
     }
-    
-    
+
+
     /**
      * compares an entry's attribute's value with that of the given value
      *   
@@ -2476,7 +2480,7 @@
         checkSession();
 
         CompareRequestCodec compareReqCodec = new CompareRequestCodec();
-        
+
         int newId = messageId.incrementAndGet();
         LdapMessageCodec message = new LdapMessageCodec();
         message.setMessageId( newId );
@@ -2486,26 +2490,26 @@
         compareReqCodec.setAttributeDesc( compareRequest.getAttrName() );
         compareReqCodec.setAssertionValue( compareRequest.getValue() );
         setControls( compareRequest.getControls(), compareReqCodec );
-        
+
         message.setProtocolOP( compareReqCodec );
-        
+
         BlockingQueue<CompareResponse> compareResponseQueue = new LinkedBlockingQueue<CompareResponse>();
         respQueueMap.put( newId, compareResponseQueue );
-        
+
         ResponseFuture compareFuture = new ResponseFuture( compareResponseQueue );
         futureMap.put( newId, compareFuture );
 
         // Send the request to the server
         ldapSession.write( message );
-        
+
         CompareResponse response = null;
-        if( listener == null )
+        if ( listener == null )
         {
             try
             {
                 long timeout = getTimeout( compareRequest.getTimeout() );
                 response = ( CompareResponse ) compareFuture.get( timeout, TimeUnit.MILLISECONDS );
-                
+
                 if ( response == null )
                 {
                     LOG.error( "Compare failed : timeout occured" );
@@ -2513,12 +2517,12 @@
                     throw new LdapException( TIME_OUT_ERROR );
                 }
             }
-            catch( InterruptedException ie )
+            catch ( InterruptedException ie )
             {
                 LOG.error( OPERATION_CANCELLED, ie );
                 throw new LdapException( OPERATION_CANCELLED, ie );
             }
-            catch( Exception e )
+            catch ( Exception e )
             {
                 LOG.error( NO_RESPONSE_ERROR );
                 removeFromMaps( newId );
@@ -2528,41 +2532,41 @@
         }
         else
         {
-            listenerMap.put( newId, listener );            
+            listenerMap.put( newId, listener );
         }
 
         return response;
     }
-    
-    
+
+
     /**
      * converts the CompareResponseCodec to CompareResponse.
      */
     private CompareResponse convert( CompareResponseCodec compareRespCodec )
     {
         CompareResponse compareResponse = new CompareResponse();
-        
+
         compareResponse.setMessageId( compareRespCodec.getMessageId() );
         compareResponse.setLdapResult( convert( compareRespCodec.getLdapResult() ) );
-        
+
         return compareResponse;
     }
 
-    
+
     /**
      * converts the DeleteResponseCodec to DeleteResponse object.
      */
     private DeleteResponse convert( DelResponseCodec delRespCodec )
     {
         DeleteResponse response = new DeleteResponse();
-        
+
         response.setMessageId( delRespCodec.getMessageId() );
         response.setLdapResult( convert( delRespCodec.getLdapResult() ) );
-        
+
         return response;
     }
-    
-    
+
+
     /**
      * @see #extended(OID, byte[])
      */
@@ -2571,7 +2575,7 @@
         return extended( oid, null );
     }
 
-    
+
     /**
      * @see #extended(OID, byte[])
      */
@@ -2581,15 +2585,15 @@
         {
             return extended( new OID( oid ), value );
         }
-        catch( DecoderException e )
+        catch ( DecoderException e )
         {
             String msg = "Failed to decode the OID " + oid;
             LOG.error( msg );
             throw new LdapException( msg, e );
         }
     }
-    
-    
+
+
     /**
      * @see #extended(OID, byte[])
      */
@@ -2597,7 +2601,7 @@
     {
         return extended( oid, null );
     }
-    
+
 
     /**
      * sends a extended operation request to the server with the given OID and value
@@ -2611,11 +2615,11 @@
     {
         ExtendedRequest extRequest = new ExtendedRequest( oid );
         extRequest.setValue( value );
-        
+
         return extended( extRequest );
     }
 
-    
+
     /**
      * @see #extended(ExtendedRequest, ExtendedListener) 
      */
@@ -2623,8 +2627,8 @@
     {
         return extended( extendedRequest, null );
     }
-    
-    
+
+
     /**
      * requests the server to perform an extended operation based on the given request.
      * 
@@ -2636,9 +2640,9 @@
     public ExtendedResponse extended( ExtendedRequest extendedRequest, ExtendedListener listener ) throws LdapException
     {
         checkSession();
-        
+
         ExtendedRequestCodec extReqCodec = new ExtendedRequestCodec();
-        
+
         int newId = messageId.incrementAndGet();
         LdapMessageCodec message = new LdapMessageCodec();
         message.setMessageId( newId );
@@ -2647,26 +2651,26 @@
         extReqCodec.setRequestName( extendedRequest.getOid() );
         extReqCodec.setRequestValue( extendedRequest.getValue() );
         setControls( extendedRequest.getControls(), extReqCodec );
-        
+
         message.setProtocolOP( extReqCodec );
-        
+
         BlockingQueue<ExtendedResponse> extendedResponseQueue = new LinkedBlockingQueue<ExtendedResponse>();
         respQueueMap.put( newId, extendedResponseQueue );
-        
+
         ResponseFuture extendedFuture = new ResponseFuture( extendedResponseQueue );
         futureMap.put( newId, extendedFuture );
 
         // Send the request to the server
         ldapSession.write( message );
-        
+
         ExtendedResponse response = null;
-        if( listener == null )
+        if ( listener == null )
         {
             try
             {
                 long timeout = getTimeout( extendedRequest.getTimeout() );
                 response = ( ExtendedResponse ) extendedFuture.get( timeout, TimeUnit.MILLISECONDS );
-                
+
                 if ( response == null )
                 {
                     LOG.error( "Extended operation failed : timeout occured" );
@@ -2674,12 +2678,12 @@
                     throw new LdapException( TIME_OUT_ERROR );
                 }
             }
-            catch( InterruptedException ie )
+            catch ( InterruptedException ie )
             {
                 LOG.error( OPERATION_CANCELLED, ie );
                 throw new LdapException( OPERATION_CANCELLED, ie );
             }
-            catch( Exception e )
+            catch ( Exception e )
             {
                 LOG.error( NO_RESPONSE_ERROR );
                 removeFromMaps( newId );
@@ -2689,43 +2693,43 @@
         }
         else
         {
-            listenerMap.put( newId, listener );            
+            listenerMap.put( newId, listener );
         }
 
         return response;
     }
 
-    
+
     /**
      * converts the ExtendedResponseCodec to ExtendedResponse.
      */
     private ExtendedResponse convert( ExtendedResponseCodec extRespCodec )
     {
         ExtendedResponse extResponse = new ExtendedResponse();
-        
+
         OID oid = null;
         try
         {
-            if( extRespCodec.getResponseName() != null )
+            if ( extRespCodec.getResponseName() != null )
             {
                 oid = new OID( extRespCodec.getResponseName() );
             }
         }
-        catch( DecoderException e )
+        catch ( DecoderException e )
         {
             // can happen in case of a PROTOCOL_ERROR result, ignore 
             //LOG.error( "invalid response name {}", extRespCodec.getResponseName() );
         }
-        
+
         extResponse.setOid( oid );
         extResponse.setValue( extRespCodec.getResponse() );
         extResponse.setMessageId( extRespCodec.getMessageId() );
         extResponse.setLdapResult( convert( extRespCodec.getLdapResult() ) );
-        
+
         return extResponse;
     }
 
-    
+
     /**
      * checks if a control with the given OID is supported
      * 
@@ -2736,8 +2740,8 @@
     {
         return getSupportedControls().contains( controlOID );
     }
-    
-    
+
+
     /**
      * get the Controls supported by server.
      *
@@ -2746,12 +2750,12 @@
      */
     public List<String> getSupportedControls() throws LdapException
     {
-        if( supportedControls != null )
+        if ( supportedControls != null )
         {
             return supportedControls;
         }
-        
-        if( rootDSE == null )
+
+        if ( rootDSE == null )
         {
             fetchRootDSE();
         }
@@ -2760,15 +2764,15 @@
 
         EntryAttribute attr = rootDSE.get( SchemaConstants.SUPPORTED_CONTROL_AT );
         Iterator<Value<?>> itr = attr.getAll();
-        
-        while( itr.hasNext() )
+
+        while ( itr.hasNext() )
         {
             supportedControls.add( ( String ) itr.next().get() );
         }
 
         return supportedControls;
     }
-    
+
 
     /**
      * fetches the rootDSE from the server
@@ -2782,10 +2786,10 @@
             cursor = search( "", "(objectClass=*)", SearchScope.OBJECT, "*", "+" );
             cursor.next();
             SearchResultEntry searchRes = ( SearchResultEntry ) cursor.get();
-            
+
             rootDSE = searchRes.getEntry();
         }
-        catch( Exception e )
+        catch ( Exception e )
         {
             String msg = "Failed to fetch the RootDSE";
             LOG.error( msg );
@@ -2793,13 +2797,13 @@
         }
         finally
         {
-            if( cursor != null )
+            if ( cursor != null )
             {
                 try
                 {
                     cursor.close();
                 }
-                catch( Exception e )
+                catch ( Exception e )
                 {
                     LOG.error( "Failed to close open cursor", e );
                 }
@@ -2818,24 +2822,29 @@
         return config;
     }
 
-    
+
     private void addControls( LdapMessageCodec codec, AbstractMessage message )
     {
-        List<ControlCodec> ccList = codec.getControls();
-        if( ccList != null )
+        List<CodecControl> ccList = codec.getControls();
+        if ( ccList != null )
         {
-            for( ControlCodec cc : ccList )
+            for ( CodecControl cc : ccList )
             {
-                // FIXME this is causing the exceptions
-//                Control control = new ControlImpl( cc.getControlType() );
-//                control.setValue( cc.getEncodedValue() );
-//                control.setCritical( cc.getCriticality() );
-//                
-//                message.add( control );
+                // FIXME why the cc is coming as null!?
+                if ( cc == null )
+                {
+                    continue;
+                }
+
+                Control control = new CodecControlImpl( cc.getOid() );
+                control.setValue( cc.getValue() );
+                control.setCritical( cc.isCritical() );
+
+                message.add( control );
             }
         }
     }
-    
+
 
     /**
      * removes the Objects associated with the given message ID
@@ -2848,8 +2857,8 @@
         futureMap.remove( msgId );
         respQueueMap.remove( msgId );
     }
-    
-    
+
+
     /**
      * removes the blocking queue present in the
      * respQueueMap and adds the given message to the blocking queue