directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1097144 - in /directory/studio/trunk/plugins/connection.core/src/main: java/org/apache/directory/studio/connection/core/ java/org/apache/directory/studio/connection/core/io/api/ resources/org/apache/directory/studio/connection/core/
Date Wed, 27 Apr 2011 15:26:28 GMT
Author: pamarcelot
Date: Wed Apr 27 15:26:27 2011
New Revision: 1097144

URL: http://svn.apache.org/viewvc?rev=1097144&view=rev
Log:
Improved error reporting for the LDAP API connection wrapper by appending the generic result
code description in the case where no message is returned by the server.

Added:
    directory/studio/trunk/plugins/connection.core/src/main/resources/org/apache/directory/studio/connection/core/ResultCodeDescriptions.properties
Modified:
    directory/studio/trunk/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Utils.java
    directory/studio/trunk/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java

Modified: directory/studio/trunk/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Utils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Utils.java?rev=1097144&r1=1097143&r2=1097144&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Utils.java
(original)
+++ directory/studio/trunk/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/Utils.java
Wed Apr 27 15:26:27 2011
@@ -59,6 +59,21 @@ public class Utils
         }
     }
 
+    public static ResourceBundle resultCodeDescriptions = null;
+    // Load RessourceBundle with OID descriptions
+    static
+    {
+        try
+        {
+            resultCodeDescriptions = ResourceBundle
+                .getBundle( "org.apache.directory.studio.connection.core.ResultCodeDescriptions"
);
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+    }
+
 
     /**
      * Gets the textual OID description for the given numeric OID.
@@ -73,8 +88,31 @@ public class Utils
         {
             try
             {
-                String description = oidDescriptions.getString( oid );
-                return description;
+                return oidDescriptions.getString( oid );
+            }
+            catch ( MissingResourceException ignored )
+            {
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Gets the textual result code description for the given numeric result code.
+     * 
+     * @param code the result code
+     * 
+     * @return the OID description, null if the numeric OID is unknown
+     */
+    public static String getResultCodeDescription( int code )
+    {
+        if ( resultCodeDescriptions != null )
+        {
+            try
+            {
+                return resultCodeDescriptions.getString( "" + code );
             }
             catch ( MissingResourceException ignored )
             {
@@ -146,7 +184,7 @@ public class Utils
             return null;
         }
 
-        byte[] b = Strings.getBytesUtf8(s);
+        byte[] b = Strings.getBytesUtf8( s );
         StringBuffer sb = new StringBuffer();
         for ( int i = 0; i < b.length; i++ )
         {

Modified: directory/studio/trunk/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java?rev=1097144&r1=1097143&r2=1097144&view=diff
==============================================================================
--- directory/studio/trunk/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
(original)
+++ directory/studio/trunk/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
Wed Apr 27 15:26:27 2011
@@ -40,6 +40,7 @@ import javax.security.auth.login.AppConf
 import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
 import javax.security.auth.login.Configuration;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.directory.ldap.client.api.CramMd5Request;
 import org.apache.directory.ldap.client.api.DigestMd5Request;
 import org.apache.directory.ldap.client.api.GssApiRequest;
@@ -86,6 +87,7 @@ import org.apache.directory.studio.conne
 import org.apache.directory.studio.connection.core.ICredentials;
 import org.apache.directory.studio.connection.core.IJndiLogger;
 import org.apache.directory.studio.connection.core.Messages;
+import org.apache.directory.studio.connection.core.Utils;
 import org.apache.directory.studio.connection.core.io.ConnectionWrapper;
 import org.apache.directory.studio.connection.core.io.StudioNamingEnumeration;
 import org.apache.directory.studio.connection.core.io.StudioTrustManager;
@@ -1230,8 +1232,18 @@ public class DirectoryApiConnectionWrapp
                 // Different from SUCCESS, we throw a generic exception
                 else if ( !ResultCodeEnum.SUCCESS.equals( ldapResult.getResultCode() ) )
                 {
+                    int code = ldapResult.getResultCode().getResultCode();
+                    String message = ldapResult.getDiagnosticMessage();
+
+                    // Checking if we got a message from the LDAP result
+                    if ( StringUtils.isEmpty( message ) )
+                    {
+                        // Assigning the generic result code description
+                        message = Utils.getResultCodeDescription( code );
+                    }
+
                     throw new Exception( NLS.bind( "[LDAP: error code {0} - {1}]", new String[]
-                        { ldapResult.getResultCode().getResultCode() + "", ldapResult.getDiagnosticMessage()
} ) );
+                        { code + "", message } ) );
                 }
             }
         }

Added: directory/studio/trunk/plugins/connection.core/src/main/resources/org/apache/directory/studio/connection/core/ResultCodeDescriptions.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/connection.core/src/main/resources/org/apache/directory/studio/connection/core/ResultCodeDescriptions.properties?rev=1097144&view=auto
==============================================================================
--- directory/studio/trunk/plugins/connection.core/src/main/resources/org/apache/directory/studio/connection/core/ResultCodeDescriptions.properties
(added)
+++ directory/studio/trunk/plugins/connection.core/src/main/resources/org/apache/directory/studio/connection/core/ResultCodeDescriptions.properties
Wed Apr 27 15:26:27 2011
@@ -0,0 +1,46 @@
+0=Success
+1=Operations Error
+2=Protocol Error
+3=Time Limit Exceeded
+4=Size Limit Exceeded
+5=Compare False
+6=Compare True
+7=Auth Method Not Supported
+8=Strong Auth Required
+9=Partial Results
+10=Referral
+11=Admin Limit Exceeded
+12=Unavailable Critical Extension
+13=Confidentiality Required
+14=SASL Bind In Progress
+16=No Such Attribute
+17=Undefined Attribute Type
+18=Inappropriate Matching
+19=Constraint Violation
+20=Attribute Or Value Exists
+21=Invalid Attribute Syntax
+32=No Such Object
+33=Alias Problem
+34=Invalid DN Syntax
+36=Alias Dereferencing Problem
+48=Inappropriate Authentication
+49=Invalid Credentials
+50=Insufficient Access Rights
+51=Busy
+52=Unavailable
+53=UnwillingToPerform
+54=Loop Detect
+64=Naming Violation
+65=Object Class Violation
+66=Not Allowed On Non Leaf
+67=Not Allowed On RDN
+68=Entry Already Exists
+69=Object Class Mods Prohibited
+71=Affects Multiple DSAs
+80=Other
+118=Canceled
+119=No Such Operation
+120=Too Late
+121=Cannot Cancel
+4096=eSync Refresh Required
+122=Unknown
\ No newline at end of file



Mime
View raw message