directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r965671 - in /directory: apacheds/branches/apacheds-subtree/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/director...
Date Mon, 19 Jul 2010 22:59:02 GMT
Author: elecharny
Date: Mon Jul 19 22:59:01 2010
New Revision: 965671

URL: http://svn.apache.org/viewvc?rev=965671&view=rev
Log:
o Added the handling of exceptionCaucght() events in the client API
o The responseFuture now contains the cause of error if something went wrong during the request
sending
o Added a test to demonstrate DIRAPI-20, and prove that it's now fixed.
o Fixed a NPE in some tests by using non static fields

Modified:
    directory/apacheds/branches/apacheds-subtree/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
    directory/apacheds/branches/apacheds-subtree/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java
    directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
    directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/future/ResponseFuture.java
    directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolEncoder.java

Modified: directory/apacheds/branches/apacheds-subtree/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-subtree/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java?rev=965671&r1=965670&r2=965671&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-subtree/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
(original)
+++ directory/apacheds/branches/apacheds-subtree/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
Mon Jul 19 22:59:01 2010
@@ -42,12 +42,13 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.directory.shared.ldap.cursor.Cursor;
 import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.DN;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -70,21 +71,29 @@ import org.junit.runner.RunWith;
     "objectClass: top",
     "sn: user1 sn",
     "cn: user1",
-    
+
     // alias to the above entry
     "dn: cn=user1-alias,ou=users,ou=system",
     "objectClass: alias",
     "objectClass: top",
     "objectClass: extensibleObject",
     "aliasedObjectName: cn=user1,ou=users,ou=system",
-    "cn: user1-alias"
+    "cn: user1-alias",
+
+    // Another user
+    "dn: cn=elecharny,ou=users,ou=system",
+    "objectClass: person",
+    "objectClass: top",
+    "sn:: RW1tYW51ZWwgTMOpY2hhcm55",
+    "cn: elecharny"
+    
 })
 public class ClientSearchRequestTest extends AbstractLdapTestUnit
 {
-    private static LdapAsyncConnection connection;
+    private LdapAsyncConnection connection;
 
-    @BeforeClass
-    public static void setup() throws Exception
+    @Before
+    public void setup() throws Exception
     {
         connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
         DN bindDn = new DN( "uid=admin,ou=system" );
@@ -95,8 +104,8 @@ public class ClientSearchRequestTest ext
     /**
      * Close the LdapConnection
      */
-    @AfterClass
-    public static void shutdown()
+    @After
+    public void shutdown()
     {
         try
         {
@@ -155,6 +164,7 @@ public class ClientSearchRequestTest ext
             "+" );
         int count = 0;
         SearchResponse searchResponse = null;
+        
         do
         {
             searchResponse = ( SearchResponse ) searchFuture.get( 1000, TimeUnit.MILLISECONDS
);
@@ -181,6 +191,7 @@ public class ClientSearchRequestTest ext
             "+" );
         int count = 0;
         SearchResponse searchResponse = null;
+        
         do
         {
             searchResponse = ( SearchResponse ) searchFuture.get( 100000, TimeUnit.MILLISECONDS
);
@@ -193,7 +204,7 @@ public class ClientSearchRequestTest ext
         }
         while ( !( searchResponse instanceof SearchResultDone ) );
 
-        assertEquals(2, count );
+        assertEquals( 3, count );
     }
 
     
@@ -208,22 +219,32 @@ public class ClientSearchRequestTest ext
         
         int count = 0;
         Cursor<SearchResponse> cursor = connection.search( searchRequest );
+        
         while( cursor.next() )
         {
             count++;
         }
         
         // due to dereferencing of aliases we get only one entry
-        assertEquals( 1, count );
+        assertEquals( 2, count );
 
         count = 0;
         searchRequest.setDerefAliases( AliasDerefMode.NEVER_DEREF_ALIASES );
         cursor = connection.search( searchRequest );
+        
         while( cursor.next() )
         {
             count++;
         }
         
-        assertEquals( 2, count );
+        assertEquals( 3, count );
+    }
+    
+
+    @Test(expected=LdapException.class)
+    public void testSearchUTF8() throws Exception
+    {
+        connection.search( "ou=system", "(sn=Emmanuel LŽcharny)", SearchScope.ONELEVEL,
"*", "+" );
+        fail();
     }
 }

Modified: directory/apacheds/branches/apacheds-subtree/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-subtree/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java?rev=965671&r1=965670&r2=965671&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-subtree/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java
(original)
+++ directory/apacheds/branches/apacheds-subtree/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java
Mon Jul 19 22:59:01 2010
@@ -41,7 +41,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.name.DN;
 import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 

Modified: directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=965671&r1=965670&r2=965671&view=diff
==============================================================================
--- directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
(original)
+++ directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
Mon Jul 19 22:59:01 2010
@@ -86,6 +86,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.LdapResultCodec;
 import org.apache.directory.shared.ldap.codec.LdapTransformer;
+import org.apache.directory.shared.ldap.codec.MessageEncoderException;
 import org.apache.directory.shared.ldap.codec.abandon.AbandonRequestCodec;
 import org.apache.directory.shared.ldap.codec.add.AddRequestCodec;
 import org.apache.directory.shared.ldap.codec.add.AddResponseCodec;
@@ -149,6 +150,7 @@ import org.apache.mina.core.service.IoCo
 import org.apache.mina.core.service.IoHandlerAdapter;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.filter.codec.ProtocolEncoderException;
 import org.apache.mina.filter.ssl.SslFilter;
 import org.apache.mina.transport.socket.nio.NioSocketConnector;
 import org.slf4j.Logger;
@@ -1383,6 +1385,13 @@ public class LdapNetworkConnection exten
 
             throw new LdapException( TIME_OUT_ERROR );
         }
+
+        // Chekc that the future hasn't be canceled
+        if ( searchFuture.isCancelled() )
+        {
+            // Thow an exception here
+            throw new LdapException( searchFuture.getCause() );
+        }
         
         // Ok, done return the future
         return searchFuture;
@@ -1477,6 +1486,27 @@ public class LdapNetworkConnection exten
 
 
     /**
+     * Handle the exception we got.
+     */
+    public void exceptionCaught( IoSession session, Throwable cause ) throws Exception 
+    {
+        if ( cause instanceof ProtocolEncoderException )
+        {
+            Throwable realCause = ((ProtocolEncoderException)cause).getCause();
+            
+            if ( realCause instanceof MessageEncoderException )
+            {
+                int messageId = ((MessageEncoderException)realCause).getMessageId();
+                
+                ResponseFuture<?> response = futureMap.get( messageId );
+                response.cancel( true );
+                response.setCause( realCause );
+            }
+        }
+    }
+    
+    
+    /**
      * Handle the incoming LDAP messages. This is where we feed the cursor for search 
      * requests, or call the listener. 
      */

Modified: directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/future/ResponseFuture.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/future/ResponseFuture.java?rev=965671&r1=965670&r2=965671&view=diff
==============================================================================
--- directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/future/ResponseFuture.java
(original)
+++ directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/future/ResponseFuture.java
Mon Jul 19 22:59:01 2010
@@ -43,6 +43,9 @@ public class ResponseFuture<R> implement
     
     /** flag to determine if this future is cancelled */
     protected boolean cancelled = false;
+    
+    /** If the request has been cancelled because of an exception  it will be stored here
*/
+    protected Throwable cause;
 
     /** The messageID for this future */
     protected int messageId;
@@ -144,6 +147,24 @@ public class ResponseFuture<R> implement
     {
         throw new UnsupportedOperationException( "Operation not supported" );
     }
+
+
+    /**
+     * @return the cause
+     */
+    public Throwable getCause()
+    {
+        return cause;
+    }
+
+
+    /**
+     * @param cause the cause to set
+     */
+    public void setCause( Throwable cause )
+    {
+        this.cause = cause;
+    }
     
     
     public String toString()

Modified: directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolEncoder.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolEncoder.java?rev=965671&r1=965670&r2=965671&view=diff
==============================================================================
--- directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolEncoder.java
(original)
+++ directory/clients/ldap/branches/ldap-client-subtree/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolEncoder.java
Mon Jul 19 22:59:01 2010
@@ -47,6 +47,7 @@ public class LdapProtocolEncoder impleme
         if ( request instanceof LdapMessageCodec )
         {
             LdapMessageCodec ldapRequest = (LdapMessageCodec)request;
+            
             ByteBuffer bb = ldapRequest.encode();
             bb.flip();
             



Mime
View raw message