directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r993075 - in /directory: apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/ clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/
Date Mon, 06 Sep 2010 15:42:26 GMT
Author: elecharny
Date: Mon Sep  6 15:42:25 2010
New Revision: 993075

URL: http://svn.apache.org/viewvc?rev=993075&view=rev
Log:
Added parameters checks to avoid NPE (DIRAPI-18)

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
    directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
    directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java?rev=993075&r1=993074&r2=993075&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/LdapCoreSessionConnection.java
Mon Sep  6 15:42:25 2010
@@ -93,6 +93,8 @@ import org.slf4j.LoggerFactory;
  */
 public class LdapCoreSessionConnection implements LdapConnection
 {
+    /** The logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( LdapCoreSessionConnection.class
);
 
     /** the CoreSession object */
     private CoreSession session;
@@ -103,10 +105,9 @@ public class LdapCoreSessionConnection i
     /** the session's DirectoryService */
     private DirectoryService directoryService;
 
+    /** The MessageId counter */
     private AtomicInteger messageId = new AtomicInteger( 0 );
 
-    private static final Logger LOG = LoggerFactory.getLogger( LdapCoreSessionConnection.class
);
-
 
     public LdapCoreSessionConnection()
     {
@@ -161,6 +162,20 @@ public class LdapCoreSessionConnection i
      */
     public AddResponse add( AddRequest addRequest ) throws LdapException
     {
+        if ( addRequest == null )
+        {
+            String msg = "Cannot process a null addRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
+        if ( addRequest.getEntry() == null )
+        {
+            String msg = "Cannot add a null entry";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         int newId = messageId.incrementAndGet();
 
         addRequest.setMessageId( newId );
@@ -190,6 +205,13 @@ public class LdapCoreSessionConnection i
      */
     public AddResponse add( Entry entry ) throws LdapException
     {
+        if ( entry == null )
+        {
+            String msg = "Cannot add an empty entry";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         AddRequest addRequest = new AddRequestImpl();
         addRequest.setEntry( entry );
 
@@ -202,6 +224,13 @@ public class LdapCoreSessionConnection i
      */
     public CompareResponse compare( CompareRequest compareRequest ) throws LdapException
     {
+        if ( compareRequest == null )
+        {
+            String msg = "Cannot process a null compareRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         int newId = messageId.incrementAndGet();
 
         CompareResponse resp = new CompareResponseImpl( newId );
@@ -302,6 +331,13 @@ public class LdapCoreSessionConnection i
      */
     public DeleteResponse delete( DeleteRequest deleteRequest ) throws LdapException
     {
+        if ( deleteRequest == null )
+        {
+            String msg = "Cannot process a null deleteRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         int newId = messageId.incrementAndGet();
 
         DeleteResponse resp = new DeleteResponseImpl( newId );
@@ -349,7 +385,7 @@ public class LdapCoreSessionConnection i
     /**
      * {@inheritDoc}
      */
-    public boolean doesFutureExistFor( Integer messageId )
+    public boolean doesFutureExistFor( int messageId )
     {
         return false;
     }
@@ -480,6 +516,19 @@ public class LdapCoreSessionConnection i
      */
     public ModifyResponse modify( DN dn, Modification... modifications ) throws LdapException
     {
+        if ( dn == null )
+        {
+            LOG.debug( "received a null dn for modification" );
+            throw new IllegalArgumentException( "The DN to be modified cannot be null" );
+        }
+
+        if ( ( modifications == null ) || ( modifications.length == 0 ) )
+        {
+            String msg = "Cannot process a ModifyRequest without any modification";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         int newId = messageId.incrementAndGet();
 
         ModifyResponse resp = new ModifyResponseImpl( newId );
@@ -525,6 +574,12 @@ public class LdapCoreSessionConnection i
      */
     public ModifyResponse modify( Entry entry, ModificationOperation modOp ) throws LdapException
     {
+        if ( entry == null )
+        {
+            LOG.debug( "received a null entry for modification" );
+            throw new IllegalArgumentException( "Entry to be modified cannot be null" );
+        }
+
         int newId = messageId.incrementAndGet();
         ModifyResponse resp = new ModifyResponseImpl( newId );
         resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
@@ -561,6 +616,13 @@ public class LdapCoreSessionConnection i
      */
     public ModifyResponse modify( ModifyRequest modRequest ) throws LdapException
     {
+        if ( modRequest == null )
+        {
+            String msg = "Cannot process a null modifyRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         int newId = messageId.incrementAndGet();
 
         modRequest.setMessageId( newId );
@@ -589,6 +651,13 @@ public class LdapCoreSessionConnection i
      */
     public ModifyDnResponse modifyDn( ModifyDnRequest modDnRequest ) throws LdapException
     {
+        if ( modDnRequest == null )
+        {
+            String msg = "Cannot process a null modDnRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         int newId = messageId.incrementAndGet();
 
         ModifyDnResponse resp = new ModifyDnResponseImpl( newId );
@@ -607,16 +676,16 @@ public class LdapCoreSessionConnection i
         try
         {
             DN newRdn = null;
-            if( modDnRequest.getNewRdn() != null )
+            if ( modDnRequest.getNewRdn() != null )
             {
                 newRdn = new DN( modDnRequest.getNewRdn().getName(), schemaManager );
             }
-            
+
             DN oldRdn = new DN( modDnRequest.getName().getRdn().getName(), schemaManager
);
-            
-            boolean rdnChanged = modDnRequest.getNewRdn() != null && 
-                ! newRdn.getNormName().equals( oldRdn.getNormName() );
-            
+
+            boolean rdnChanged = modDnRequest.getNewRdn() != null
+                && !newRdn.getNormName().equals( oldRdn.getNormName() );
+
             if ( rdnChanged )
             {
                 if ( modDnRequest.getNewSuperior() != null )
@@ -659,6 +728,20 @@ public class LdapCoreSessionConnection i
      */
     public ModifyDnResponse move( DN entryDn, DN newSuperiorDn ) throws LdapException
     {
+        if ( entryDn == null )
+        {
+            String msg = "Cannot process a move of a null DN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
+        if ( newSuperiorDn == null )
+        {
+            String msg = "Cannot process a move to a null DN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         ModifyDnRequest iModDnReq = new ModifyDnRequestImpl();
         iModDnReq.setName( entryDn );
         iModDnReq.setNewSuperior( newSuperiorDn );
@@ -672,6 +755,20 @@ public class LdapCoreSessionConnection i
      */
     public ModifyDnResponse move( String entryDn, String newSuperiorDn ) throws LdapException
     {
+        if ( entryDn == null )
+        {
+            String msg = "Cannot process a move of a null DN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
+        if ( newSuperiorDn == null )
+        {
+            String msg = "Cannot process a move to a null DN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         return move( new DN( entryDn ), new DN( newSuperiorDn ) );
     }
 
@@ -681,6 +778,20 @@ public class LdapCoreSessionConnection i
      */
     public ModifyDnResponse rename( DN entryDn, RDN newRdn, boolean deleteOldRdn ) throws
LdapException
     {
+        if ( entryDn == null )
+        {
+            String msg = "Cannot process a rename of a null DN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
+        if ( newRdn == null )
+        {
+            String msg = "Cannot process a rename with a null RDN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         ModifyDnRequest iModDnReq = new ModifyDnRequestImpl();
         iModDnReq.setName( entryDn );
         iModDnReq.setNewRdn( newRdn );
@@ -713,6 +824,20 @@ public class LdapCoreSessionConnection i
      */
     public ModifyDnResponse rename( String entryDn, String newRdn ) throws LdapException
     {
+        if ( entryDn == null )
+        {
+            String msg = "Cannot process a rename of a null DN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
+        if ( newRdn == null )
+        {
+            String msg = "Cannot process a rename with a null RDN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         return rename( new DN( entryDn ), new RDN( newRdn ) );
     }
 
@@ -800,6 +925,13 @@ public class LdapCoreSessionConnection i
      */
     public Cursor<Response> search( SearchRequest searchRequest ) throws LdapException
     {
+        if ( searchRequest == null )
+        {
+            String msg = "Cannot process a null searchRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         try
         {
             int newId = messageId.incrementAndGet();
@@ -827,6 +959,12 @@ public class LdapCoreSessionConnection i
     public Cursor<Response> search( DN baseDn, String filter, SearchScope scope, String...
attributes )
         throws LdapException
     {
+        if ( baseDn == null )
+        {
+            LOG.debug( "received a null dn for a search" );
+            throw new IllegalArgumentException( "The base DN cannot be null" );
+        }
+
         // generate some random operation number
         SearchRequest searchRequest = new SearchRequestImpl();
 
@@ -853,9 +991,10 @@ public class LdapCoreSessionConnection i
     /**
      * {@inheritDoc}
      */
-    public void unBind() throws Exception
+    public void unBind() throws LdapException
     {
         messageId.set( 0 );
+
         if ( session != null )
         {
             session.unbind();
@@ -879,6 +1018,13 @@ public class LdapCoreSessionConnection i
      */
     public ExtendedResponse extended( ExtendedRequest extendedRequest ) throws LdapException
     {
+        if ( extendedRequest == null )
+        {
+            String msg = "Cannot process a null extendedRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         return extended( ( String ) null );
 
     }
@@ -956,6 +1102,13 @@ public class LdapCoreSessionConnection i
      */
     public BindResponse bind( BindRequest bindRequest ) throws LdapException, IOException
     {
+        if ( bindRequest == null )
+        {
+            String msg = "Cannot process a null bindRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         int newId = messageId.incrementAndGet();
 
         BindOperationContext bindContext = new BindOperationContext( null );

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=993075&r1=993074&r2=993075&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 Sep  6 15:42:25 2010
@@ -53,10 +53,13 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 
 
+/**
+ * The root interface for all the LdapConnection implementations/
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
 public interface LdapConnection
 {
-
-    //--------------------------- Helper methods ---------------------------//
     /**
      * Check if we are connected
      *
@@ -73,12 +76,12 @@ public interface LdapConnection
     public abstract boolean isAuthenticated();
 
 
-    //-------------------------- The methods ---------------------------//
     /**
      * Connect to the remote LDAP server.
      *
      * @return <code>true</code> if the connection is established, false otherwise
-     * @throws LdapException if some error has occured
+     * @throws LdapException if some error occurred
+     * @throws IOException if an I/O exception occurred
      */
     public abstract boolean connect() throws LdapException, IOException;
 
@@ -101,6 +104,7 @@ public interface LdapConnection
      *
      * @param entry The entry to add
      * @result the add operation's response
+     * @throws LdapException if some error occurred
      */
     public abstract AddResponse add( Entry entry ) throws LdapException;
 
@@ -110,7 +114,7 @@ public interface LdapConnection
      *
      * @param addRequest the request object containing an entry and controls(if any)
      * @return the add operation's response
-     * @throws LdapException
+     * @throws LdapException if some error occurred
      */
     public abstract AddResponse add( AddRequest addRequest ) throws LdapException;
 
@@ -126,7 +130,7 @@ public interface LdapConnection
 
 
     /**
-     * An abandon request essentially with the request message ID of the operation to be
cancelled
+     * An abandon request essentially with the request message ID of the operation to be
canceled
      * and/or potentially some controls and timeout (the controls and timeout are not mandatory).
      *
      * The abandonRequest is always non-blocking, because no response is expected
@@ -140,6 +144,8 @@ public interface LdapConnection
      * Anonymous Bind on a server.
      *
      * @return The BindResponse LdapResponse
+     * @throws LdapException if some error occurred
+     * @throws IOException if an I/O exception occurred
      */
     public abstract BindResponse bind() throws LdapException, IOException;
 
@@ -151,6 +157,8 @@ public interface LdapConnection
      * valid DN
      * @param credentials The password. It can't be null
      * @return The BindResponse LdapResponse
+     * @throws LdapException if some error occurred
+     * @throws IOException if an I/O exception occurred
      */
     public abstract BindResponse bind( String name, String credentials ) throws LdapException,
IOException;
 
@@ -162,6 +170,8 @@ public interface LdapConnection
      * valid DN
      * @param credentials The password. It can't be null
      * @return The BindResponse LdapResponse
+     * @throws LdapException if some error occurred
+     * @throws IOException if an I/O exception occurred
      */
     public abstract BindResponse bind( DN name, String credentials ) throws LdapException,
IOException;
 
@@ -172,6 +182,8 @@ public interface LdapConnection
      * @param bindRequest The BindRequest POJO containing all the needed
      * parameters
      * @return A LdapResponse containing the result
+     * @throws LdapException if some error occurred
+     * @throws IOException if an I/O exception occurred
      */
     public abstract BindResponse bind( BindRequest bindRequest ) throws LdapException, IOException;
 
@@ -192,6 +204,7 @@ public interface LdapConnection
      * @param filterString The filter to use for this search. It can't be empty
      * @param scope The sarch scope : OBJECT, ONELEVEL or SUBTREE
      * @return A cursor on the result.
+     * @throws LdapException if some error occurred
      */
     public abstract Cursor<Response> search( DN baseDn, String filter, SearchScope
scope, String... attributes )
         throws LdapException;
@@ -211,8 +224,9 @@ public interface LdapConnection
      * @param baseDn The base for the search. It must be a valid
      * DN, and can't be emtpy
      * @param filterString The filter to use for this search. It can't be empty
-     * @param scope The sarch scope : OBJECT, ONELEVEL or SUBTREE
+     * @param scope The search scope : OBJECT, ONELEVEL or SUBTREE
      * @return A cursor on the result.
+     * @throws LdapException if some error occurred
      */
     public abstract Cursor<Response> search( String baseDn, String filter, SearchScope
scope, String... attributes )
         throws LdapException;
@@ -222,8 +236,8 @@ public interface LdapConnection
      * Performs search in a synchronous mode.
      *
      * @param searchRequest The search configuration
-     * @return A {@link Cursor} containing Entries and Referencs
-     * @throws LdapException @TODO
+     * @return A {@link Cursor} containing Entries and References
+     * @throws LdapException if some error occurred
      */
     public abstract Cursor<Response> search( SearchRequest searchRequest ) throws LdapException;
 
@@ -233,8 +247,9 @@ public interface LdapConnection
     //---------------------------------------------------------------------//
     /**
      * UnBind from a server. this is a request which expect no response.
+     * @throws LdapException if some error occurred
      */
-    public abstract void unBind() throws Exception;
+    public abstract void unBind() throws LdapException;
 
 
     /**
@@ -296,6 +311,7 @@ public interface LdapConnection
     /**
      * renames the given entryDn with new Rdn and deletes the old RDN.
      * @see #rename(String, String, boolean)
+     * @throws LdapException if some error occurred
      */
     public abstract ModifyDnResponse rename( String entryDn, String newRdn ) throws LdapException;
 
@@ -303,12 +319,14 @@ public interface LdapConnection
     /**
      * renames the given entryDn with new RDN and deletes the old RDN.
      * @see #rename(DN, RDN, boolean)
+     * @throws LdapException if some error occurred
      */
     public abstract ModifyDnResponse rename( DN entryDn, RDN newRdn ) throws LdapException;
 
 
     /**
      * @see #rename(DN, RDN, boolean)
+     * @throws LdapException if some error occurred
      */
     public abstract ModifyDnResponse rename( String entryDn, String newRdn, boolean deleteOldRdn
) throws LdapException;
 
@@ -322,7 +340,7 @@ public interface LdapConnection
      * @param newRdn new Rdn for the target DN
      * @param deleteOldRdn flag to indicate whether to delete the old Rdn
      * @return modifyDn operations response
-     * @throws LdapException
+     * @throws LdapException if some error occurred
      */
     public abstract ModifyDnResponse rename( DN entryDn, RDN newRdn, boolean deleteOldRdn
) throws LdapException;
 
@@ -339,7 +357,7 @@ public interface LdapConnection
      * @param entryDn the DN of the target entry
      * @param newSuperiorDn DN of the new parent/superior
      * @return modifyDn operations response
-     * @throws LdapException
+     * @throws LdapException if some error occurred
      */
     public abstract ModifyDnResponse move( DN entryDn, DN newSuperiorDn ) throws LdapException;
 
@@ -348,6 +366,7 @@ public interface LdapConnection
      * Moves and renames the given entryDn.The old RDN will be deleted
      *
      * @see #moveAndRename(DN, DN, boolean)
+     * @throws LdapException if some error occurred
      */
     public abstract ModifyDnResponse moveAndRename( DN entryDn, DN newDn ) throws LdapException;
 
@@ -356,6 +375,7 @@ public interface LdapConnection
      * Moves and renames the given entryDn.The old RDN will be deleted
      *
      * @see #moveAndRename(DN, DN, boolean)
+     * @throws LdapException if some error occurred
      */
     public abstract ModifyDnResponse moveAndRename( String entryDn, String newDn ) throws
LdapException;
 
@@ -366,6 +386,7 @@ public interface LdapConnection
      * @param entryDn The original entry DN
      * @param newDn The new Entry DN
      * @param deleteOldRdn Tells if the old RDN must be removed
+     * @throws LdapException if some error occurred
      */
     public abstract ModifyDnResponse moveAndRename( DN entryDn, DN newDn, boolean deleteOldRdn
) throws LdapException;
 
@@ -376,6 +397,7 @@ public interface LdapConnection
      * @param entryDn The original entry DN
      * @param newDn The new Entry DN
      * @param deleteOldRdn Tells if the old RDN must be removed
+     * @throws LdapException if some error occurred
      */
     public abstract ModifyDnResponse moveAndRename( String entryDn, String newDn, boolean
deleteOldRdn )
         throws LdapException;
@@ -387,7 +409,7 @@ public interface LdapConnection
      *
      * @param modDnRequest the request
      * @return modifyDn operations response, null if non-null listener is provided
-     * @throws LdapException
+     * @throws LdapException if some error occurred
      */
     public abstract ModifyDnResponse modifyDn( ModifyDnRequest modDnRequest ) throws LdapException;
 
@@ -441,7 +463,7 @@ public interface LdapConnection
      * @param attributeName the attribute's name
      * @param value a byte[] value with which the target entry's attribute value to be compared
with
      * @return compare operation's response
-     * @throws LdapException
+     * @throws LdapException if some error occurred
      */
     public abstract CompareResponse compare( String dn, String attributeName, byte[] value
) throws LdapException;
 
@@ -454,7 +476,7 @@ public interface LdapConnection
      * @param attributeName the attribute's name
      * @param value a Value<?> value with which the target entry's attribute value
to be compared with
      * @return compare operation's response
-     * @throws LdapException
+     * @throws LdapException if some error occurred
      */
     public abstract CompareResponse compare( String dn, String attributeName, Value<?>
value ) throws LdapException;
 
@@ -467,7 +489,7 @@ public interface LdapConnection
      * @param attributeName the attribute's name
      * @param value a String value with which the target entry's attribute value to be compared
with
      * @return compare operation's response
-     * @throws LdapException
+     * @throws LdapException if some error occurred
      */
     public abstract CompareResponse compare( DN dn, String attributeName, String value )
throws LdapException;
 
@@ -480,7 +502,7 @@ public interface LdapConnection
      * @param attributeName the attribute's name
      * @param value a byte[] value with which the target entry's attribute value to be compared
with
      * @return compare operation's response
-     * @throws LdapException
+     * @throws LdapException if some error occurred
      */
     public abstract CompareResponse compare( DN dn, String attributeName, byte[] value )
throws LdapException;
 
@@ -493,7 +515,7 @@ public interface LdapConnection
      * @param attributeName the attribute's name
      * @param value a Value<?> value with which the target entry's attribute value
to be compared with
      * @return compare operation's response
-     * @throws LdapException
+     * @throws LdapException if some error occurred
      */
     public abstract CompareResponse compare( DN dn, String attributeName, Value<?>
value ) throws LdapException;
 
@@ -503,25 +525,28 @@ public interface LdapConnection
      *
      * @param compareRequest the CompareRequest which contains the target DN, attribute name
and value
      * @return compare operation's response
-     * @throws LdapException
+     * @throws LdapException if some error occurred
      */
     public abstract CompareResponse compare( CompareRequest compareRequest ) throws LdapException;
 
 
     /**
      * @see #extended(OID, byte[])
+     * @throws LdapException if some error occurred
      */
     public abstract ExtendedResponse extended( String oid ) throws LdapException;
 
 
     /**
      * @see #extended(OID, byte[])
+     * @throws LdapException if some error occurred
      */
     public abstract ExtendedResponse extended( String oid, byte[] value ) throws LdapException;
 
 
     /**
      * @see #extended(OID, byte[])
+     * @throws LdapException if some error occurred
      */
     public abstract ExtendedResponse extended( OID oid ) throws LdapException;
 
@@ -532,7 +557,7 @@ public interface LdapConnection
      * @param oid the object identifier of the extended operation
      * @param value value to be used by the extended operation, can be a null value
      * @return extended operation's response
-     * @throws LdapException
+     * @throws LdapException if some error occurred
      */
     public abstract ExtendedResponse extended( OID oid, byte[] value ) throws LdapException;
 
@@ -549,12 +574,14 @@ public interface LdapConnection
 
     /**
      * @see #lookup(DN, String...)
+     * @throws LdapException if some error occurred
      */
     public abstract Entry lookup( DN dn ) throws LdapException;
 
 
     /**
      * @see #lookup(String, String...)
+     * @throws LdapException if some error occurred
      */
     public abstract Entry lookup( String dn ) throws LdapException;
 
@@ -572,6 +599,7 @@ public interface LdapConnection
 
     /**
      * @see #lookup(DN, String...)
+     * @throws LdapException if some error occurred
      */
     public abstract Entry lookup( String dn, String... attributes ) throws LdapException;
 
@@ -581,6 +609,7 @@ public interface LdapConnection
      *
      * @param controlOID the OID of the control
      * @return true if the control is supported, false otherwise
+     * @throws LdapException if some error occurred
      */
     public abstract boolean isControlSupported( String controlOID ) throws LdapException;
 
@@ -589,7 +618,7 @@ public interface LdapConnection
      * get the Controls supported by server.
      *
      * @return a list of control OIDs supported by server
-     * @throws LdapException
+     * @throws LdapException if some error occurred
      */
     public abstract List<String> getSupportedControls() throws LdapException;
 
@@ -602,6 +631,9 @@ public interface LdapConnection
     public abstract void loadSchema() throws LdapException;
 
 
+    /**
+     * @return The SchemaManager associated with this LdapConection if any
+     */
     public abstract SchemaManager getSchemaManager();
 
 
@@ -611,6 +643,6 @@ public interface LdapConnection
      * @param messageId ID of the request
      * @return true if there is a non-null future exists, false otherwise
      */
-    public abstract boolean doesFutureExistFor( Integer messageId );
+    public abstract boolean doesFutureExistFor( int messageId );
 
 }
\ No newline at end of file

Modified: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=993075&r1=993074&r2=993075&view=diff
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
(original)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
Mon Sep  6 15:42:25 2010
@@ -66,7 +66,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
-import org.apache.directory.shared.ldap.exception.LdapReferralException;
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.message.AbandonRequest;
 import org.apache.directory.shared.ldap.message.AbandonRequestImpl;
@@ -147,8 +146,6 @@ public class LdapNetworkConnection exten
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( LdapNetworkConnection.class
);
 
-    private static final String LDAP_RESPONSE = "LdapReponse";
-
     /** The timeout used for response we are waiting for */
     private long timeout = LdapConnectionConfig.DEFAULT_TIMEOUT;
 
@@ -348,13 +345,24 @@ public class LdapNetworkConnection exten
      * Create a new instance of a LdapConnection on a given
      * server, using the default port (389).
      *
-     * @param server The server we want to be connected to
+     * @param server The server we want to be connected to. If null or empty,
+     * we will default to LocalHost.
      */
     public LdapNetworkConnection( String server )
     {
         config.setUseSsl( false );
         config.setLdapPort( config.getDefaultLdapPort() );
-        config.setLdapHost( server );
+
+        // Default to localhost if null
+        if ( StringTools.isEmpty( server ) )
+        {
+            config.setLdapHost( "localhost" );
+        }
+        else
+        {
+            config.setLdapHost( server );
+        }
+
         messageId = new AtomicInteger( 0 );
     }
 
@@ -364,14 +372,25 @@ public class LdapNetworkConnection exten
      * server, using the default port (389) if the SSL flag
      * is off, or 636 otherwise.
      *
-     * @param server The server we want to be connected to
+     * @param server The server we want to be connected to. If null or empty,
+     * we will default to LocalHost.
      * @param useSsl A flag to tell if it's a SSL connection or not.
      */
     public LdapNetworkConnection( String server, boolean useSsl )
     {
         config.setUseSsl( useSsl );
         config.setLdapPort( useSsl ? config.getDefaultLdapsPort() : config.getDefaultLdapPort()
);
-        config.setLdapHost( server );
+
+        // Default to localhost if null
+        if ( StringTools.isEmpty( server ) )
+        {
+            config.setLdapHost( "localhost" );
+        }
+        else
+        {
+            config.setLdapHost( server );
+        }
+
         messageId = new AtomicInteger( 0 );
     }
 
@@ -394,7 +413,8 @@ public class LdapNetworkConnection exten
      * server, and a give port. We set the SSL flag accordingly
      * to the last parameter.
      *
-     * @param server The server we want to be connected to
+     * @param server The server we want to be connected to. If null or empty,
+     * we will default to LocalHost.
      * @param port The port the server is listening to
      * @param useSsl A flag to tell if it's a SSL connection or not.
      */
@@ -402,7 +422,17 @@ public class LdapNetworkConnection exten
     {
         config.setUseSsl( useSsl );
         config.setLdapPort( port );
-        config.setLdapHost( server );
+
+        // Default to localhost if null
+        if ( StringTools.isEmpty( server ) )
+        {
+            config.setLdapHost( "localhost" );
+        }
+        else
+        {
+            config.setLdapHost( server );
+        }
+
         messageId = new AtomicInteger();
     }
 
@@ -537,7 +567,7 @@ public class LdapNetworkConnection exten
     {
         if ( entry == null )
         {
-            String msg = "Cannot add empty entry";
+            String msg = "Cannot add an empty entry";
             LOG.debug( msg );
             throw new IllegalArgumentException( msg );
         }
@@ -573,6 +603,20 @@ public class LdapNetworkConnection exten
      */
     public AddResponse add( AddRequest addRequest ) throws LdapException
     {
+        if ( addRequest == null )
+        {
+            String msg = "Cannot process a null addRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
+        if ( addRequest.getEntry() == null )
+        {
+            String msg = "Cannot add a null entry";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         AddFuture addFuture = addAsync( addRequest );
 
         // Get the result from the future
@@ -637,6 +681,20 @@ public class LdapNetworkConnection exten
      */
     public AddFuture addAsync( AddRequest addRequest ) throws LdapException
     {
+        if ( addRequest == null )
+        {
+            String msg = "Cannot process a null addRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
+        if ( addRequest.getEntry() == null )
+        {
+            String msg = "Cannot add a null entry";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         checkSession();
 
         int newId = messageId.incrementAndGet();
@@ -669,6 +727,13 @@ public class LdapNetworkConnection exten
      */
     public void abandon( int messageId )
     {
+        if ( messageId < 0 )
+        {
+            String msg = "Cannot abandon a negative message ID";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         AbandonRequest abandonRequest = new AbandonRequestImpl();
         abandonRequest.setAbandoned( messageId );
 
@@ -681,6 +746,13 @@ public class LdapNetworkConnection exten
      */
     public void abandon( AbandonRequest abandonRequest )
     {
+        if ( abandonRequest == null )
+        {
+            String msg = "Cannot process a null abandonRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         abandonInternal( abandonRequest );
     }
 
@@ -813,6 +885,13 @@ public class LdapNetworkConnection exten
      */
     public BindResponse bind( BindRequest bindRequest ) throws LdapException, IOException
     {
+        if ( bindRequest == null )
+        {
+            String msg = "Cannot process a null bindRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         BindFuture bindFuture = bindAsync( bindRequest );
 
         // Get the result from the future
@@ -979,8 +1058,7 @@ public class LdapNetworkConnection exten
     /**
      * Create a Simple BindRequest with controls ready to be sent.
      */
-    private BindRequest createBindRequest( String name, byte[] credentials, Control[] controls
)
-        throws LdapException
+    private BindRequest createBindRequest( String name, byte[] credentials, Control[] controls
) throws LdapException
     {
         return createBindRequest( name, credentials, null, controls );
     }
@@ -989,8 +1067,7 @@ public class LdapNetworkConnection exten
     /**
      * Create a Simple BindRequest with controls ready to be sent.
      */
-    private BindRequest createBindRequest( DN name, byte[] credentials, Control[] controls
)
-        throws LdapException
+    private BindRequest createBindRequest( DN name, byte[] credentials, Control[] controls
) throws LdapException
     {
         return createBindRequest( name, credentials, null, controls );
     }
@@ -999,8 +1076,7 @@ public class LdapNetworkConnection exten
     /**
      * Create a SASL BindRequest ready to be sent.
      */
-    private BindRequest createBindRequest( String name, byte[] credentials, String mechanism
)
-        throws LdapException
+    private BindRequest createBindRequest( String name, byte[] credentials, String mechanism
) throws LdapException
     {
         return createBindRequest( name, credentials, mechanism, ( Control[] ) null );
     }
@@ -1018,8 +1094,8 @@ public class LdapNetworkConnection exten
     /**
      * Create a complete BindRequest ready to be sent.
      */
-    private BindRequest createBindRequest( String name, byte[] credentials, String saslMechanism,
-        Control... controls ) throws LdapException
+    private BindRequest createBindRequest( String name, byte[] credentials, String saslMechanism,
Control... controls )
+        throws LdapException
     {
         // Set the name
         try
@@ -1042,8 +1118,8 @@ public class LdapNetworkConnection exten
     /**
      * Create a complete BindRequest ready to be sent.
      */
-    private BindRequest createBindRequest( DN name, byte[] credentials, String saslMechanism,
-        Control... controls ) throws LdapException
+    private BindRequest createBindRequest( DN name, byte[] credentials, String saslMechanism,
Control... controls )
+        throws LdapException
     {
         // clear the mappings if any (in case of a second call to bind() without calling
unBind())
         //clearMaps();
@@ -1087,6 +1163,13 @@ public class LdapNetworkConnection exten
      */
     public BindFuture bindAsync( BindRequest bindRequest ) throws LdapException, IOException
     {
+        if ( bindRequest == null )
+        {
+            String msg = "Cannot process a null bindRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         // First switch to anonymous state
         authenticated.set( false );
 
@@ -1196,6 +1279,13 @@ public class LdapNetworkConnection exten
      */
     public SearchFuture searchAsync( SearchRequest searchRequest ) throws LdapException
     {
+        if ( searchRequest == null )
+        {
+            String msg = "Cannot process a null searchRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         // If the session has not been establish, or is closed, we get out immediately
         checkSession();
 
@@ -1237,6 +1327,13 @@ public class LdapNetworkConnection exten
      */
     public Cursor<Response> search( SearchRequest searchRequest ) throws LdapException
     {
+        if ( searchRequest == null )
+        {
+            String msg = "Cannot process a null searchRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         SearchFuture searchFuture = searchAsync( searchRequest );
 
         long timeout = getTimeout( searchRequest.getTimeLimit() );
@@ -1251,7 +1348,7 @@ public class LdapNetworkConnection exten
     /**
      * {@inheritDoc}
      */
-    public void unBind() throws Exception
+    public void unBind() throws LdapException
     {
         // If the session has not been establish, or is closed, we get out immediately
         checkSession();
@@ -1751,6 +1848,13 @@ public class LdapNetworkConnection exten
             throw new IllegalArgumentException( "The DN to be modified cannot be null" );
         }
 
+        if ( ( modifications == null ) || ( modifications.length == 0 ) )
+        {
+            String msg = "Cannot process a ModifyRequest without any modification";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         ModifyRequest modReq = new ModifyRequestImpl();
         modReq.setName( dn );
 
@@ -1777,6 +1881,13 @@ public class LdapNetworkConnection exten
      */
     public ModifyResponse modify( ModifyRequest modRequest ) throws LdapException
     {
+        if ( modRequest == null )
+        {
+            String msg = "Cannot process a null modifyRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         ModifyFuture modifyFuture = modifyAsync( modRequest );
 
         // Get the result from the future
@@ -1841,6 +1952,13 @@ public class LdapNetworkConnection exten
      */
     public ModifyFuture modifyAsync( ModifyRequest modRequest ) throws LdapException
     {
+        if ( modRequest == null )
+        {
+            String msg = "Cannot process a null modifyRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         checkSession();
 
         int newId = messageId.incrementAndGet();
@@ -1889,6 +2007,20 @@ public class LdapNetworkConnection exten
      */
     public ModifyDnResponse rename( String entryDn, String newRdn, boolean deleteOldRdn )
throws LdapException
     {
+        if ( entryDn == null )
+        {
+            String msg = "Cannot process a rename of a null DN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
+        if ( newRdn == null )
+        {
+            String msg = "Cannot process a rename with a null RDN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         try
         {
             return rename( new DN( entryDn ), new RDN( newRdn ), deleteOldRdn );
@@ -1906,6 +2038,20 @@ public class LdapNetworkConnection exten
      */
     public ModifyDnResponse rename( DN entryDn, RDN newRdn, boolean deleteOldRdn ) throws
LdapException
     {
+        if ( entryDn == null )
+        {
+            String msg = "Cannot process a rename of a null DN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
+        if ( newRdn == null )
+        {
+            String msg = "Cannot process a rename with a null RDN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();
         modDnRequest.setName( entryDn );
         modDnRequest.setNewRdn( newRdn );
@@ -1920,6 +2066,20 @@ public class LdapNetworkConnection exten
      */
     public ModifyDnResponse move( String entryDn, String newSuperiorDn ) throws LdapException
     {
+        if ( entryDn == null )
+        {
+            String msg = "Cannot process a move of a null DN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
+        if ( newSuperiorDn == null )
+        {
+            String msg = "Cannot process a move to a null DN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         try
         {
             return move( new DN( entryDn ), new DN( newSuperiorDn ) );
@@ -1937,6 +2097,20 @@ public class LdapNetworkConnection exten
      */
     public ModifyDnResponse move( DN entryDn, DN newSuperiorDn ) throws LdapException
     {
+        if ( entryDn == null )
+        {
+            String msg = "Cannot process a move of a null DN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
+        if ( newSuperiorDn == null )
+        {
+            String msg = "Cannot process a move to a null DN";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();
         modDnRequest.setName( entryDn );
         modDnRequest.setNewSuperior( newSuperiorDn );
@@ -2029,6 +2203,13 @@ public class LdapNetworkConnection exten
      */
     public ModifyDnResponse modifyDn( ModifyDnRequest modDnRequest ) throws LdapException
     {
+        if ( modDnRequest == null )
+        {
+            String msg = "Cannot process a null modDnRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         ModifyDnFuture modifyDnFuture = modifyDnAsync( modDnRequest );
 
         // Get the result from the future
@@ -2093,6 +2274,13 @@ public class LdapNetworkConnection exten
      */
     public ModifyDnFuture modifyDnAsync( ModifyDnRequest modDnRequest ) throws LdapException
     {
+        if ( modDnRequest == null )
+        {
+            String msg = "Cannot process a null modDnRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         checkSession();
 
         int newId = messageId.incrementAndGet();
@@ -2305,6 +2493,13 @@ public class LdapNetworkConnection exten
      */
     public DeleteResponse delete( DeleteRequest deleteRequest ) throws LdapException
     {
+        if ( deleteRequest == null )
+        {
+            String msg = "Cannot process a null deleteRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         DeleteFuture deleteFuture = deleteAsync( deleteRequest );
 
         // Get the result from the future
@@ -2367,19 +2562,26 @@ public class LdapNetworkConnection exten
     /**
      * {@inheritDoc}
      */
-    public DeleteFuture deleteAsync( DeleteRequest delRequest ) throws LdapException
+    public DeleteFuture deleteAsync( DeleteRequest deleteRequest ) throws LdapException
     {
+        if ( deleteRequest == null )
+        {
+            String msg = "Cannot process a null deleteRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         checkSession();
 
         int newId = messageId.incrementAndGet();
 
-        delRequest.setMessageId( newId );
+        deleteRequest.setMessageId( newId );
 
         DeleteFuture deleteFuture = new DeleteFuture( this, newId );
         addToFutureMap( newId, deleteFuture );
 
         // Send the request to the server
-        WriteFuture writeFuture = ldapSession.write( delRequest );
+        WriteFuture writeFuture = ldapSession.write( deleteRequest );
 
         // Wait for the message to be sent to the server
         if ( !writeFuture.awaitUninterruptibly( getTimeout( 0 ) ) )
@@ -2477,6 +2679,13 @@ public class LdapNetworkConnection exten
      */
     public CompareResponse compare( CompareRequest compareRequest ) throws LdapException
     {
+        if ( compareRequest == null )
+        {
+            String msg = "Cannot process a null compareRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         CompareFuture compareFuture = compareAsync( compareRequest );
 
         // Get the result from the future
@@ -2541,6 +2750,13 @@ public class LdapNetworkConnection exten
      */
     public CompareFuture compareAsync( CompareRequest compareRequest ) throws LdapException
     {
+        if ( compareRequest == null )
+        {
+            String msg = "Cannot process a null compareRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         checkSession();
 
         int newId = messageId.incrementAndGet();
@@ -2621,6 +2837,13 @@ public class LdapNetworkConnection exten
      */
     public ExtendedResponse extended( ExtendedRequest extendedRequest ) throws LdapException
     {
+        if ( extendedRequest == null )
+        {
+            String msg = "Cannot process a null extendedRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         ExtendedFuture extendedFuture = extendedAsync( extendedRequest );
 
         // Get the result from the future
@@ -2686,6 +2909,13 @@ public class LdapNetworkConnection exten
      */
     public ExtendedFuture extendedAsync( ExtendedRequest extendedRequest ) throws LdapException
     {
+        if ( extendedRequest == null )
+        {
+            String msg = "Cannot process a null extendedRequest";
+            LOG.debug( msg );
+            throw new IllegalArgumentException( msg );
+        }
+
         checkSession();
 
         int newId = messageId.incrementAndGet();
@@ -3007,7 +3237,7 @@ public class LdapNetworkConnection exten
     /**
      * {@inheritDoc}
      */
-    public boolean doesFutureExistFor( Integer messageId )
+    public boolean doesFutureExistFor( int messageId )
     {
         ResponseFuture<?> responseFuture = futureMap.get( messageId );
         return responseFuture != null;



Mime
View raw message