From 390948050c34e7ed6668059ccdb4af27b4204fd9 Mon Sep 17 00:00:00 2001
From: lutoff <lutoff@localhost>
Date: Fri, 14 Sep 2007 09:09:16 +0000
Subject: [PATCH] Fix for issue #2256 (limit the number of prompt in status CLI) status cli will now exit after 3 connection failure.

---
 opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
index b5e810a..3450f60 100644
--- a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
+++ b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
@@ -85,6 +85,9 @@
   /** Suffix for log files. */
   static public final String LOG_FILE_SUFFIX = ".log";
 
+  /** Maximum number of connection attempts. */
+  private final int MAX_CONNECTION_RETRY =3;
+
   /**
    * The enumeration containing the different return codes that the command-line
    * can have.
@@ -112,7 +115,11 @@
     /**
      * User cancelled (for instance not accepting the certificate proposed).
      */
-    USER_CANCELLED(3);
+    USER_CANCELLED(3),
+    /**
+     * Too many connection failure.
+     */
+   ERROR_TOO_MANY_CONNECTION_FAILURE(4);
 
     private int returnCode;
     private ErrorReturnCode(int returnCode)
@@ -350,8 +357,10 @@
             }
 
             InitialLdapContext ctx = null;
-            while (!connected && !cancelled)
+            int remainingRetry = MAX_CONNECTION_RETRY;
+            while (!connected && !cancelled && (remainingRetry > 0))
             {
+             remainingRetry--;
               if (prompted)
               {
                 printLineBreak();
@@ -446,6 +455,14 @@
             {
               return ErrorReturnCode.USER_CANCELLED.getReturnCode();
             }
+            else
+            if (remainingRetry <= 0)
+            {
+              printErrorMessage(
+                  ERR_STATUS_CLI_TOO_MANY_CONNECTION_ATTEMPT.get());
+              return ErrorReturnCode.ERROR_TOO_MANY_CONNECTION_FAILURE
+                  .getReturnCode();
+            }
           }
           else
           {

--
Gitblit v1.10.0