directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r760567 - in /directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api: ./ exception/ messages/
Date Tue, 31 Mar 2009 18:55:01 GMT
Author: elecharny
Date: Tue Mar 31 18:55:00 2009
New Revision: 760567

URL: http://svn.apache.org/viewvc?rev=760567&view=rev
Log:
o Added a new generic LdapException
o Wrapped all the exception to produce LdapException
o Finished the BindRequest implementation
o Commented the other operation atm

Added:
    directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/exception/LdapException.java
Modified:
    directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java
    directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/exception/InvalidConnectionException.java
    directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/BindRequestImpl.java
    directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/Message.java

Modified: directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java?rev=760567&r1=760566&r2=760567&view=diff
==============================================================================
--- directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java
(original)
+++ directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/LdapConnection.java
Tue Mar 31 18:55:00 2009
@@ -22,23 +22,46 @@
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
+import java.util.Map;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 
+import javax.naming.InvalidNameException;
+import javax.naming.ldap.Control;
 import javax.net.ssl.SSLContext;
 
 import org.apache.directory.shared.asn1.ber.IAsn1Container;
+import org.apache.directory.shared.ldap.client.api.exception.InvalidConnectionException;
+import org.apache.directory.shared.ldap.client.api.exception.LdapException;
+import org.apache.directory.shared.ldap.client.api.listeners.BindListener;
+import org.apache.directory.shared.ldap.client.api.listeners.SearchListener;
+import org.apache.directory.shared.ldap.client.api.messages.BindRequest;
+import org.apache.directory.shared.ldap.client.api.messages.BindRequestImpl;
 import org.apache.directory.shared.ldap.client.api.protocol.LdapProtocolCodecFactory;
+import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.apache.directory.shared.ldap.codec.LdapMessage;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.LdapResponse;
-import org.apache.directory.shared.ldap.codec.bind.BindRequest;
+import org.apache.directory.shared.ldap.codec.bind.LdapAuthentication;
+import org.apache.directory.shared.ldap.codec.bind.SaslCredentials;
 import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication;
+import org.apache.directory.shared.ldap.codec.search.Filter;
+import org.apache.directory.shared.ldap.codec.search.SearchRequest;
+import org.apache.directory.shared.ldap.codec.search.SearchResultDone;
+import org.apache.directory.shared.ldap.codec.search.SearchResultEntry;
+import org.apache.directory.shared.ldap.codec.search.SearchResultReference;
 import org.apache.directory.shared.ldap.codec.unbind.UnBindRequest;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.cursor.ListCursor;
 import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.filter.FilterParser;
+import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.apache.directory.shared.ldap.message.AddResponse;
+import org.apache.directory.shared.ldap.message.BindResponse;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -112,14 +135,40 @@
     /** A Message ID which is incremented for each operation */
     private int messageId;
     
-    /** A queue used to store the incoming responses */
-    private BlockingQueue<LdapMessage> responseQueue;
+    /** A queue used to store the incoming add responses */
+    private BlockingQueue<LdapMessage> addResponseQueue;
+    
+    /** A queue used to store the incoming bind responses */
+    private BlockingQueue<LdapMessage> bindResponseQueue;
+    
+    /** A queue used to store the incoming compare responses */
+    private BlockingQueue<LdapMessage> compareResponseQueue;
+    
+    /** A queue used to store the incoming delete responses */
+    private BlockingQueue<LdapMessage> deleteResponseQueue;
+    
+    /** A queue used to store the incoming extended responses */
+    private BlockingQueue<LdapMessage> extendedResponseQueue;
+    
+    /** A queue used to store the incoming modify responses */
+    private BlockingQueue<LdapMessage> modifyResponseQueue;
+    
+    /** A queue used to store the incoming modifyDN responses */
+    private BlockingQueue<LdapMessage> modifyDNResponseQueue;
+    
+    /** A queue used to store the incoming search responses */
+    private BlockingQueue<LdapMessage> searchResponseQueue;
+    
+    /** A queue used to store the incoming intermediate responses */
+    private BlockingQueue<LdapMessage> intermediateResponseQueue;
+    
     
     /** An operation mutex to guarantee the operation order */
     private Semaphore operationMutex;
     
-    /** The search listener used to get results back */
-    private SearchListener listener;
+    /** The listeners used to get results back */
+    private SearchListener searchListener;
+    private BindListener bindListener;
 
     //--------------------------- Helper methods ---------------------------//
     /**
@@ -139,11 +188,11 @@
      *
      * @throws Exception If the session is not valid
      */
-    private void checkSession() throws Exception
+    private void checkSession() throws InvalidConnectionException
     {
         if ( !isSessionValid() )
         {
-            throw new Exception( "Cannot connect on the server, the connection is invalid"
);
+            throw new InvalidConnectionException( "Cannot connect on the server, the connection
is invalid" );
         }
     }
     
@@ -157,6 +206,28 @@
         return (LdapMessage)ldapSession.getAttribute( LDAP_RESPONSE );
     }
     
+    
+    /**
+     * Handle the lock mechanism on session
+     */
+    private void lock() throws LdapException
+    {
+        try
+        {
+            operationMutex.acquire();
+        }
+        catch ( InterruptedException ie )
+        {
+            String message = "Cannot acquire the session lock";
+            LOG.error(  message );
+            LdapException ldapException = 
+                new LdapException( message );
+            ldapException.initCause( ie );
+            
+            throw ldapException;
+        }
+    }
+    
 
     //------------------------- The constructors --------------------------//
     /**
@@ -318,8 +389,16 @@
         // Store the container into the session 
         ldapSession.setAttribute( "LDAP-Container", ldapMessageContainer );
         
-        // Create the responses queue
-        responseQueue = new LinkedBlockingQueue<LdapMessage>();
+        // Create the responses queues
+        addResponseQueue = new LinkedBlockingQueue<LdapMessage>();
+        bindResponseQueue = new LinkedBlockingQueue<LdapMessage>();
+        compareResponseQueue = new LinkedBlockingQueue<LdapMessage>();
+        deleteResponseQueue = new LinkedBlockingQueue<LdapMessage>();
+        extendedResponseQueue = new LinkedBlockingQueue<LdapMessage>();
+        modifyResponseQueue = new LinkedBlockingQueue<LdapMessage>();
+        modifyDNResponseQueue = new LinkedBlockingQueue<LdapMessage>();
+        searchResponseQueue = new LinkedBlockingQueue<LdapMessage>();
+        intermediateResponseQueue = new LinkedBlockingQueue<LdapMessage>();
         
         // And return
         return true;
@@ -340,6 +419,17 @@
             ldapSession.close( true );
         }
         
+        // clean the queues
+        addResponseQueue.clear();
+        bindResponseQueue.clear();
+        compareResponseQueue.clear();
+        deleteResponseQueue.clear();
+        extendedResponseQueue.clear();
+        modifyResponseQueue.clear();
+        modifyDNResponseQueue.clear();
+        searchResponseQueue.clear();
+        intermediateResponseQueue.clear();
+        
         // And close the connector if it has been created locally
         if ( localConnector ) 
         {
@@ -350,31 +440,95 @@
         return true;
     }
     
-    
     //------------------------ The LDAP operations ------------------------//
-    // Bind operations                                                     //
+    // Add operations                                                      //
     //---------------------------------------------------------------------//
     /**
-     * Anonymous Bind on a server. 
+     * Add an entry to the server. This is a blocking add : the user has 
+     * to wait for the response until the AddResponse is returned.
+     * 
+     * @param entry The entry to add
+     * @result AddResponse The resulting response 
      *
-     * @return The BindResponse LdapResponse 
-     */
-    public LdapResponse bind() throws Exception
+    public AddResponse add( Entry entry )
     {
-        LOG.debug( " Unauthenticated Authentication bind" );
-        
-        LdapResponse response = bind( (String)null, (byte[])null );
-        
-        if (response.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
+        if ( entry == null ) 
         {
-            LOG.debug( " Unauthenticated Authentication bind successfull" );
+            LOG.debug( "Cannot add empty entry" );
+            return null;
         }
-        else
+        
+        
+    }
+    
+    
+    public void add( AddRequest addRequest ) throws InvalidConnectionException
+    {
+        // If the session has not been establish, or is closed, we get out immediately
+        checkSession();
+
+        // Guarantee that for this session, we don't have more than one operation
+        // running at the same time
+        lock();
+        
+        // Create the AddRequest
+        LdapDN dn = new LdapDN( name );
+        
+        InternalAddRequest addRequest = new InternalBindRequest();
+        bindRequest.setName( dn );
+        bindRequest.setVersion( LDAP_V3 );
+        
+        // Create the Simple authentication
+        SimpleAuthentication simpleAuth = new SimpleAuthentication();
+        simpleAuth.setSimple( credentials );
+
+        bindRequest.setAuthentication( simpleAuth );
+        
+        // Encode the request
+        LdapMessage message = new LdapMessage();
+        message.setMessageId( messageId++ );
+        message.setProtocolOP( bindRequest );
+        
+        LOG.debug( "-----------------------------------------------------------------" );
+        LOG.debug( "Sending request \n{}", message );
+
+        // Send the request to the server
+        ldapSession.write( message );
+
+        // Read the response, waiting for it if not available immediately
+        LdapMessage response = bindResponseQueue.poll( timeOut, TimeUnit.MILLISECONDS );
+    
+        // Check that we didn't get out because of a timeout
+        if ( response == null )
         {
-            LOG.debug( " Unauthenticated Authentication bind failure {}", response );
+            // We didn't received anything : this is an error
+            LOG.error( "Bind failed : timeout occured" );
+            operationMutex.release();
+            throw new Exception( "TimeOut occured" );
         }
         
-        return response;
+        operationMutex.release();
+        
+        // Everything is fine, return the response
+        LdapResponse resp = response.getBindResponse();
+        
+        LOG.debug( "Bind successful : {}", resp );
+        
+        return resp;
+    }
+    */
+    
+    //------------------------ The LDAP operations ------------------------//
+    // Bind operations                                                     //
+    //---------------------------------------------------------------------//
+    /**
+     * Anonymous Bind on a server. 
+     *
+     * @return The BindResponse LdapResponse 
+     */
+    public LdapResponse bind()  throws LdapException
+    {
+        return bind( (String)null, (byte[])null );
     }
     
     
@@ -385,7 +539,7 @@
      * @param name The name we use to authenticate the user. It must be a 
      * valid DN
      * @return The BindResponse LdapResponse 
-     */
+     *
     public LdapResponse bind( String name ) throws Exception
     {
         LOG.debug( "Anonymous bind" );
@@ -413,7 +567,7 @@
      * @param credentials The password. It can't be null 
      * @return The BindResponse LdapResponse 
      */
-    public LdapResponse bind( String name, String credentials ) throws Exception
+    public LdapResponse bind( String name, String credentials ) throws LdapException
     {
         return bind( name, StringTools.getBytesUtf8( credentials ) );
     }
@@ -427,32 +581,122 @@
      * @param credentials The password.
      * @return The BindResponse LdapResponse 
      */
-    public LdapResponse bind( String name, byte[] credentials ) throws Exception
+    public LdapResponse bind( String name, byte[] credentials )  throws LdapException
+    {
+        LOG.debug( "Bind request : {}", name );
+
+        // Create the BindRequest
+        BindRequest bindRequest = new BindRequestImpl();
+        bindRequest.setName( name );
+        bindRequest.setCredentials( credentials );
+        
+        LdapResponse response = bind( bindRequest );
+
+        if ( response.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
+        {
+            LOG.debug( " Bind successfull" );
+        }
+        else
+        {
+            LOG.debug( " Bind failure {}", response );
+        }
+
+        return response;
+    }
+    
+    
+    /**
+     * Bind to the server using a BindRequest object.
+     *
+     * @param bindRequest The BindRequest POJO containing all the needed
+     * parameters 
+     * @return A LdapResponse containing the result
+     */
+    public LdapResponse bind( BindRequest bindRequest ) throws LdapException
+    {
+        return bind( bindRequest, null );
+    }
+        
+
+    /**
+     * Do the bind blocking or non-blocking, depending on the listener value.
+     *
+     * @param bindRequest The BindRequest to send
+     * @param listener The listener (Can be null) 
+     */
+    public LdapResponse bind( BindRequest bindRequest, BindListener bindListener ) throws
LdapException 
     {
         // If the session has not been establish, or is closed, we get out immediately
         checkSession();
 
         // Guarantee that for this session, we don't have more than one operation
         // running at the same time
-        operationMutex.acquire();
+        lock();
         
-        // Create the BindRequest
-        LdapDN dn = new LdapDN( name );
+        // Encode the request
+        LdapMessage message = new LdapMessage();
+        message.setMessageId( messageId++ );
         
-        BindRequest bindRequest = new BindRequest();
-        bindRequest.setName( dn );
-        bindRequest.setVersion( LDAP_V3 );
+        // Create a new codec BindRequest object
+        org.apache.directory.shared.ldap.codec.bind.BindRequest request = 
+            new org.apache.directory.shared.ldap.codec.bind.BindRequest();
         
-        // Create the Simple authentication
-        SimpleAuthentication simpleAuth = new SimpleAuthentication();
-        simpleAuth.setSimple( credentials );
-
-        bindRequest.setAuthentication( simpleAuth );
+        // Set the name
+        try
+        {
+            LdapDN dn = new LdapDN( bindRequest.getName() );
+            request.setName( dn );
+        }
+        catch ( InvalidNameException ine )
+        {
+            LOG.error( "The given dn '{}' is not valid", bindRequest.getName() );
+            LdapException ldapException = new LdapException();
+            ldapException.initCause( ine );
+            throw ldapException;
+        }
         
-        // Encode the request
-        LdapMessage message = new LdapMessage();
+        // Set the credentials
+        LdapAuthentication authentication = null;
+        
+        if ( bindRequest.isSimple() )
+        {
+            // Simple bind
+            authentication = new SimpleAuthentication();
+            ((SimpleAuthentication)authentication).setSimple( bindRequest.getCredentials()
);
+        }
+        else
+        {
+            // SASL bind
+            authentication = new SaslCredentials();
+            ((SaslCredentials)authentication).setCredentials( bindRequest.getCredentials()
);
+            ((SaslCredentials)authentication).setMechanism( bindRequest.getSaslMechanism()
);
+        }
+        
+        // The authentication
+        request.setAuthentication( authentication );
+        
+        // Stores the BindRequest into the message
+        message.setProtocolOP( request );
+        
+        // Add the controls
+        Map<String, Control> controls = bindRequest.getControls();
+        
+        if ( controls != null )
+        {
+            for ( Control control:controls.values() )
+            {
+                org.apache.directory.shared.ldap.codec.Control ctrl = 
+                    new org.apache.directory.shared.ldap.codec.Control();
+                
+                ctrl.setControlType( control.getID() );
+                ctrl.setControlValue( control.getEncodedValue() );
+                
+                message.addControl( ctrl );
+            }
+        }
+
+        // Set the message ID now
         message.setMessageId( messageId++ );
-        message.setProtocolOP( bindRequest );
         
         LOG.debug( "-----------------------------------------------------------------" );
         LOG.debug( "Sending request \n{}", message );
@@ -460,28 +704,49 @@
         // Send the request to the server
         ldapSession.write( message );
 
-        // Read the response, waiting for it if not available immediately
-        LdapMessage response = responseQueue.poll( timeOut, TimeUnit.MILLISECONDS );
-    
-        // Check that we didn't get out because of a timeout
-        if ( response == null )
+        if ( bindListener == null )
         {
-            // We didn't received anything : this is an error
-            LOG.error( "Bind failed : timeout occured" );
-            operationMutex.release();
-            throw new Exception( "TimeOut occured" );
+            // Read the response, waiting for it if not available immediately
+            try
+            {
+                LdapMessage response = bindResponseQueue.poll( bindRequest.getTimeout(),
TimeUnit.MILLISECONDS );
+            
+                // Check that we didn't get out because of a timeout
+                if ( response == null )
+                {
+                    // TODO Send an abandon request here
+                    //abandon( message.getBindRequest().getMessageId() );
+                    
+                    // We didn't received anything : this is an error
+                    LOG.error( "Bind failed : timeout occured" );
+                    operationMutex.release();
+                    throw new LdapException( "TimeOut occured" );
+                }
+                
+                operationMutex.release();
+                
+                // Everything is fine, return the response
+                LdapResponse resp = response.getBindResponse();
+                
+                LOG.debug( "Bind successful : {}", resp );
+                
+                return resp;
+            }
+            catch ( InterruptedException ie )
+            {
+                LOG.error( "The response queue has been emptied, no response will be find."
);
+                LdapException ldapException = new LdapException();
+                ldapException.initCause( ie );
+                //abandon( message.getBindRequest().getMessageId() );
+                throw ldapException;
+            }
+        }
+        else
+        {
+            // The listener will be called on a MessageReceived event
+            return null;
         }
-        
-        operationMutex.release();
-        
-        // Everything is fine, return the response
-        LdapResponse resp = response.getBindResponse();
-        
-        LOG.debug( "Bind successful : {}", resp );
-        
-        return resp;
     }
-
     
     //------------------------ The LDAP operations ------------------------//
     // Search operations                                                   //
@@ -499,12 +764,64 @@
      * 
      * @param baseObject The base for the search. It must be a valid
      * DN, and can't be emtpy
-     * @param filter The filter to use for this search. It can't be empty
+     * @param filterString The filter to use for this search. It can't be empty
      * @return A cursor on the result. 
-     */
-    public Cursor<Entry> search( String baseObject, String filter ) throws Exception
+     *
+    public Cursor<Entry> search( String baseObject, String filterString ) throws Exception
     {
-        return null;
+        // If the session has not been establish, or is closed, we get out immediately
+        checkSession();
+        
+        LdapDN baseDN = null;
+        Filter filter = null;
+        
+        // Check that the baseObject is not null or empty, 
+        // and is a valid DN
+        if ( StringTools.isEmpty( baseObject ) )
+        {
+            throw new Exception( "Cannot search on RootDSE when the scope is not BASE" );
+        }
+        
+        try
+        {
+            baseDN = new LdapDN( baseObject );
+        }
+        catch ( InvalidNameException ine )
+        {
+            throw new Exception( "The baseObject is not a valid DN" );
+        }
+        
+        // Check that the filter is valid
+        try
+        {
+            ExprNode filterNode = FilterParser.parse( filterString );
+            
+            filter = TwixTransformer.transformFilter( filterNode );
+        }
+        catch ( ParseException pe )
+        {
+            throw new Exception( "The filter is invalid" );
+        }
+        
+        // Create the searchRequest
+        SearchRequest searchRequest = new SearchRequest();
+        searchRequest.setBaseObject( baseDN );
+        searchRequest.setFilter( filter );
+        
+        // Fill the default values
+        searchRequest.setSizeLimit( 0 );
+        searchRequest.setTimeLimit( 0 );
+        searchRequest.setDerefAliases( LdapConstants.DEREF_ALWAYS );
+        searchRequest.setScope( SearchScope.ONELEVEL );
+        searchRequest.setTypesOnly( false );
+        searchRequest.addAttribute( SchemaConstants.ALL_USER_ATTRIBUTES );
+
+        // Send the search request
+        search( searchRequest );
+        
+        // We now have to create the cursor around the response, and return it.
+        Cursor<LdapResponse> searchCursor = new ListCursor<LdapResponse>();
+        
     }
     
     
@@ -531,6 +848,94 @@
         
     }
     
+    
+    /**
+     * {@inheritDoc}
+     */
+    private void search( SearchRequest searchRequest ) throws Exception
+    {
+        // First check the session
+        checkSession();
+        
+        // Guarantee that for this session, we don't have more than one operation
+        // running at the same time
+        lock();
+        
+        // Encode the request
+        LdapMessage message = new LdapMessage();
+        message.setMessageId( messageId++ );
+        message.setProtocolOP( searchRequest );
+        message.addControl( searchRequest.getCurrentControl() );
+        
+        LOG.debug( "-----------------------------------------------------------------" );
+        LOG.debug( "Sending request \n{}", message );
+    
+        // Loop and get all the responses
+        // Send the request to the server
+        ldapSession.write( message );
+
+        operationMutex.release();
+//        int i = 0;
+//        
+//        List<SearchResultEntry> searchResults = new ArrayList<SearchResultEntry>();
+        
+        // Now wait for the responses
+        // Loop until we got all the responses
+        
+/*        do
+        {
+            // If we get out before the timeout, check that the response 
+            // is there, and get it
+            LdapMessage response = responseQueue.poll( timeOut, TimeUnit.MILLISECONDS );
+            
+            if ( response == null )
+            {
+                // No response, get out
+                operationMutex.release();
+                
+                // We didn't received anything : this is an error
+                throw new Exception( "TimeOut occured" );
+            }
+            
+            i++;
+
+            // Print the response
+//            System.out.println( "Result[" + i + "]" + response );
+            
+            if( response.getMessageType() == LdapConstants.INTERMEDIATE_RESPONSE )
+            {
+                consumer.handleSyncInfo( response.getIntermediateResponse().getResponseValue()
);
+            }
+            
+            if ( response.getMessageType() == LdapConstants.SEARCH_RESULT_DONE )
+            {
+                SearchResultDone resDone = response.getSearchResultDone();
+                resDone.addControl( response.getCurrentControl() );
+                
+                operationMutex.release();
+                consumer.handleSearchDone( resDone );
+                
+                return;
+            }
+       
+            if( response.getMessageType() == LdapConstants.SEARCH_RESULT_ENTRY )
+            {
+                SearchResultEntry sre = response.getSearchResultEntry();
+                sre.addControl( response.getCurrentControl() );
+                consumer.handleSearchResult( sre );
+            }
+            
+            if( response.getMessageType() == LdapConstants.SEARCH_RESULT_REFERENCE )
+            {
+                SearchResultReference searchRef = response.getSearchResultReference();
+                searchRef.addControl( response.getCurrentControl() );
+                
+                consumer.handleSearchReference( searchRef );
+            }
+        }
+        while ( true );
+*/    }
+    
     //------------------------ The LDAP operations ------------------------//
     // Unbind operations                                                   //
     //---------------------------------------------------------------------//
@@ -544,7 +949,7 @@
         
         // Guarantee that for this session, we don't have more than one operation
         // running at the same time
-        operationMutex.acquire();
+        lock();
         
         // Create the UnBindRequest
         UnBindRequest unBindRequest = new UnBindRequest();
@@ -563,8 +968,8 @@
         // We don't have to wait for a response. Reset the messageId counter to 0
         messageId = 0;
         
-        // We also have to reset the response queue
-        responseQueue.clear();
+        // We also have to reset the response queues
+        bindResponseQueue.clear();
         
         operationMutex.release();
         LOG.debug( "Unbind successful" );
@@ -577,9 +982,9 @@
      *
      * @param listener an instance of SearchListener implementation.
      */
-    public void addListener( SearchListener listener )
+    public void addListener( SearchListener searchListener )
     {
-        this.listener = listener;
+        this.searchListener = searchListener;
     }
     
     
@@ -606,4 +1011,115 @@
     }
     
     
+    /**
+     * 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 
+    {
+        // Feed the response and store it into the session
+        LdapMessage response = (LdapMessage)message;
+
+        LOG.debug( "-------> {} Message received <-------", response.getMessageTypeName()
);
+        
+        switch ( response.getMessageType() )
+        {
+            case LdapConstants.ADD_RESPONSE :
+                // Store the response into the responseQueue
+                addResponseQueue.add( response ); 
+                break;
+                
+            case LdapConstants.BIND_RESPONSE: 
+                if ( bindListener != null )
+                {
+                    bindListener.bindCompleted( this, response.getBindResponse() );
+                }
+                else
+                {
+                    // Store the response into the responseQueue
+                    bindResponseQueue.add( response.getBindResponse() );
+                }
+                
+                break;
+                
+            case LdapConstants.COMPARE_RESPONSE :
+                // Store the response into the responseQueue
+                compareResponseQueue.add( response ); 
+                break;
+                
+            case LdapConstants.DEL_RESPONSE :
+                // Store the response into the responseQueue
+                deleteResponseQueue.add( response ); 
+                break;
+                
+            case LdapConstants.EXTENDED_RESPONSE :
+                // Store the response into the responseQueue
+                extendedResponseQueue.add( response ); 
+                break;
+                
+            case LdapConstants.INTERMEDIATE_RESPONSE:
+                //consumer.handleSyncInfo( response.getIntermediateResponse().getResponseValue()
);
+                break;
+     
+            case LdapConstants.MODIFY_RESPONSE :
+                // Store the response into the responseQueue
+                modifyResponseQueue.add( response ); 
+                break;
+                
+            case LdapConstants.MODIFYDN_RESPONSE :
+                // Store the response into the responseQueue
+                modifyDNResponseQueue.add( response ); 
+                break;
+                
+            case LdapConstants.SEARCH_RESULT_DONE:
+                // Store the response into the responseQueue
+                SearchResultDone resDone = response.getSearchResultDone();
+                resDone.addControl( response.getCurrentControl() );
+                
+                if ( searchListener != null )
+                {
+                    searchListener.searchDone( this, response.getLdapResponse() );
+                }
+                else
+                {
+                    searchResponseQueue.add( resDone );
+                }
+                
+                break;
+            
+            case LdapConstants.SEARCH_RESULT_ENTRY:
+                // Store the response into the responseQueue
+                SearchResultEntry searchResultEntry = response.getSearchResultEntry();
+                searchResultEntry.addControl( response.getCurrentControl() );
+                
+                if ( searchListener != null )
+                {
+                    searchListener.entryFound( this, searchResultEntry );
+                }
+                else
+                {
+                    searchResponseQueue.add( searchResultEntry );
+                }
+                
+                break;
+                       
+            case LdapConstants.SEARCH_RESULT_REFERENCE:
+                // Store the response into the responseQueue
+                SearchResultReference searchRef = response.getSearchResultReference();
+                searchRef.addControl( response.getCurrentControl() );
+
+                if ( searchListener != null )
+                {
+                    searchListener.referralFound( this, searchRef );
+                }
+                else
+                {
+                    searchResponseQueue.add( searchRef );
+                }
+
+                break;
+                       
+             default: LOG.error( "~~~~~~~~~~~~~~~~~~~~~ Unknown message type {} ~~~~~~~~~~~~~~~~~~~~~",
response.getMessageTypeName() );
+        }
+    }
 }

Modified: directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/exception/InvalidConnectionException.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/exception/InvalidConnectionException.java?rev=760567&r1=760566&r2=760567&view=diff
==============================================================================
--- directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/exception/InvalidConnectionException.java
(original)
+++ directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/exception/InvalidConnectionException.java
Tue Mar 31 18:55:00 2009
@@ -25,7 +25,7 @@
  * on a closed connection
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class InvalidConnectionException extends Exception
+public class InvalidConnectionException extends LdapException
 {
     static final long serialVersionUID = 1L;
 

Added: directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/exception/LdapException.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/exception/LdapException.java?rev=760567&view=auto
==============================================================================
--- directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/exception/LdapException.java
(added)
+++ directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/exception/LdapException.java
Tue Mar 31 18:55:00 2009
@@ -0,0 +1,43 @@
+/*
+ *  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.client.api.exception;
+
+
+/**
+ * A InvalidConnectionException is thrown if one tries to apply an operation
+ * on a closed connection
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapException extends Exception
+{
+    static final long serialVersionUID = 1L;
+
+
+    public LdapException()
+    {
+        super();
+    }
+
+
+    public LdapException(String explanation)
+    {
+        super( explanation );
+    }
+}

Modified: directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/BindRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/BindRequestImpl.java?rev=760567&r1=760566&r2=760567&view=diff
==============================================================================
--- directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/BindRequestImpl.java
(original)
+++ directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/BindRequestImpl.java
Tue Mar 31 18:55:00 2009
@@ -56,7 +56,7 @@
     private Map<String, Control> controls;
     
     /** The client request timeout */
-    private int timeout = 0;
+    private long timeout = 0;
 
 
     /**
@@ -209,7 +209,7 @@
     /**
      * {@inheritDoc}
      */
-    public int getTimeout()
+    public long getTimeout()
     {
         return timeout;
     }
@@ -239,7 +239,7 @@
     /**
      * {@inheritDoc}
      */
-    public void setTimeout( int timeout )
+    public void setTimeout( long timeout )
     {
         this.timeout = timeout;
     }

Modified: directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/Message.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/Message.java?rev=760567&r1=760566&r2=760567&view=diff
==============================================================================
--- directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/Message.java
(original)
+++ directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/Message.java
Tue Mar 31 18:55:00 2009
@@ -40,16 +40,16 @@
      *
      * @return The timeout
      */
-    int getTimeout();
+    long getTimeout();
     
     
     /**
      * Set a request client timeout. When this timeout is reached, the request 
      * will be canceled. If <= 0, then we wait for the response forever.  
      *
-     * @param timeout The new timeout.
+     * @param timeout The new timeout, expressed in milliseconds
      */
-    void setTimeout( int timeout );
+    void setTimeout( long timeout );
     
     
     /**



Mime
View raw message