From 03fe0954e42abf00746b8efa4c79ee74cf514427 Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Thu, 27 May 2010 15:10:50 +0000
Subject: [PATCH] Fix an issue with connection timeouts in CLI. The timeout is now configurable on CLI with the --connectTimeout option (expressed in milliseconds), the default is 30 000 milliseconds. This solves Issue 4196.

---
 opends/src/server/org/opends/server/tools/LDAPPasswordModify.java |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java b/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java
index da82045..700c971 100644
--- a/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java
+++ b/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java
@@ -22,9 +22,10 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2009 Sun Microsystems, Inc.
+ *      Copyright 2006-2010 Sun Microsystems, Inc.
  */
 package org.opends.server.tools;
+import org.opends.admin.ads.util.ConnectionUtils;
 import org.opends.messages.Message;
 
 
@@ -186,6 +187,7 @@
     StringArgument    sslKeyStorePIN;
     StringArgument    sslTrustStore;
     StringArgument    sslTrustStorePIN;
+    IntegerArgument   connectTimeout;
     StringArgument    propertiesFileArgument;
     BooleanArgument   noPropertiesFileArgument;
 
@@ -405,6 +407,16 @@
       controlStr.setPropertyName("control");
       argParser.addArgument(controlStr);
 
+      int defaultTimeout = ConnectionUtils.getDefaultLDAPTimeout();
+      connectTimeout = new IntegerArgument(OPTION_LONG_CONNECT_TIMEOUT,
+          null, OPTION_LONG_CONNECT_TIMEOUT,
+          false, false, true, INFO_TIMEOUT_PLACEHOLDER.get(),
+          defaultTimeout, null,
+          true, 0, false, Integer.MAX_VALUE,
+          INFO_DESCRIPTION_CONNECTION_TIMEOUT.get());
+      connectTimeout.setPropertyName(OPTION_LONG_CONNECT_TIMEOUT);
+      argParser.addArgument(connectTimeout);
+
 
       showUsage = new BooleanArgument("help", OPTION_SHORT_HELP,
                                       OPTION_LONG_HELP,
@@ -665,7 +677,8 @@
 
     try
     {
-      connection.connectToHost(dn, pw, nextMessageID);
+      int timeout = connectTimeout.getIntValue();
+      connection.connectToHost(dn, pw, nextMessageID, timeout);
     }
     catch (LDAPConnectionException lce)
     {
@@ -673,6 +686,13 @@
       err.println(wrapText(message, MAX_LINE_WIDTH));
       return lce.getResultCode();
     }
+    catch (ArgumentException e)
+    {
+      // This should not occur because the arguments are already parsed.
+      // It is a bug
+      e.printStackTrace();
+      throw new IllegalStateException("Unexpected error: "+e, e);
+    }
 
     LDAPReader reader = connection.getLDAPReader();
     LDAPWriter writer = connection.getLDAPWriter();

--
Gitblit v1.10.0