From 82043dfb2454c7c81e144e55951efb8ad75ddc91 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.

---
 opendj-sdk/opends/src/server/org/opends/server/tools/LDAPModify.java |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPModify.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPModify.java
index 9501bd8..11aa3fb 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPModify.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPModify.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;
 
 import java.io.FileInputStream;
@@ -72,6 +73,7 @@
 import static org.opends.server.util.ServerConstants.*;
 import static org.opends.server.util.StaticUtils.*;
 import static org.opends.server.tools.ToolConstants.*;
+
 import org.opends.server.controls.*;
 import org.opends.server.plugins.ChangeNumberControlPlugin;
 
@@ -608,6 +610,7 @@
     FileBasedArgument bindPasswordFile       = null;
     FileBasedArgument keyStorePasswordFile   = null;
     FileBasedArgument trustStorePasswordFile = null;
+    IntegerArgument   connectTimeout         = null;
     IntegerArgument   port                   = null;
     IntegerArgument   version                = null;
     StringArgument    assertionFilter        = null;
@@ -865,6 +868,16 @@
       version.setPropertyName(OPTION_LONG_PROTOCOL_VERSION);
       argParser.addArgument(version);
 
+      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);
+
       encodingStr = new StringArgument("encoding", 'i', "encoding",
                                       false, false,
                                       true, INFO_ENCODING_PLACEHOLDER.get(),
@@ -1192,7 +1205,9 @@
       AtomicInteger nextMessageID = new AtomicInteger(1);
       connection = new LDAPConnection(hostNameValue, portNumber,
                                       connectionOptions, out, err);
-      connection.connectToHost(bindDNValue, bindPasswordValue, nextMessageID);
+      int timeout = connectTimeout.getIntValue();
+      connection.connectToHost(bindDNValue, bindPasswordValue, nextMessageID,
+          timeout);
 
       ldapModify = new LDAPModify(fileNameValue, nextMessageID, out, err);
       ldapModify.readAndExecute(connection, fileNameValue, modifyOptions);

--
Gitblit v1.10.0