mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

ludovicp
27.10.2010 03fe0954e42abf00746b8efa4c79ee74cf514427
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.
1 files deleted
42 files modified
1310 ■■■■ changed files
opends/src/ads/org/opends/admin/ads/TopologyCache.java 25 ●●●● patch | view | raw | blame | history
opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java 15 ●●●●● patch | view | raw | blame | history
opends/src/ads/org/opends/admin/ads/util/ServerLoader.java 13 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ControlPanel.java 1 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ControlPanelArgumentParser.java 54 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java 26 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java 27 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteEntryTask.java 4 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java 2 ●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java 8 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java 33 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java 15 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java 5 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/uninstaller/ui/LoginDialog.java 15 ●●●● patch | view | raw | blame | history
opends/src/messages/messages/tools.properties 3 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/Application.java 5 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/UserData.java 22 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java 56 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java 3 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/ui/DirectoryManagerAuthenticationDialog.java 504 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java 21 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java 9 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/util/ServerController.java 4 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/util/Utils.java 18 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java 17 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java 22 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/InstallDS.java 13 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java 33 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPCompare.java 20 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPConnection.java 30 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPDelete.java 18 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPModify.java 19 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPPasswordModify.java 24 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPSearch.java 19 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/ToolConstants.java 8 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java 82 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/status/StatusCli.java 1 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/tasks/TaskTool.java 41 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/args/ArgumentParser.java 5 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java 40 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/cli/ConsoleApplication.java 11 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java 15 ●●●●● patch | view | raw | blame | history
opends/src/ads/org/opends/admin/ads/TopologyCache.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 */
package org.opends.admin.ads;
@@ -69,6 +69,7 @@
{
  private ADSContext adsContext;
  private ApplicationTrustManager trustManager;
  private int timeout;
  private String dn;
  private String pwd;
  private Set<ServerDescriptor> servers = new HashSet<ServerDescriptor>();
@@ -90,12 +91,16 @@
   * @param trustManager the ApplicationTrustManager that must be used to trust
   * certificates when we create connections to the registered servers to read
   * their configuration.
   * @param timeout the timeout to establish the connection in milliseconds.
   * Use {@code 0} to express no timeout.
   */
  public TopologyCache(ADSContext adsContext,
      ApplicationTrustManager trustManager)
      ApplicationTrustManager trustManager,
      int timeout)
  {
    this.adsContext = adsContext;
    this.trustManager = trustManager;
    this.timeout = timeout;
    dn = ConnectionUtils.getBindDN(adsContext.getDirContext());
    pwd = ConnectionUtils.getBindPassword(adsContext.getDirContext());
  }
@@ -207,6 +212,16 @@
  }
  /**
   * Returns the timeout to establish the connection in milliseconds.
   * @return the timeout to establish the connection in milliseconds. Returns
   * {@code 0} to express no timeout.
   */
  public int getConnectTimeout()
  {
    return timeout;
  }
  /**
   * Reads the replication monitoring.
   * @throws NamingException if an error occurs reading the replication
   * monitoring.
@@ -373,6 +388,7 @@
  {
    return new ServerLoader(serverProperties, dn, pwd,
        trustManager == null ? null : trustManager.createCopy(),
            timeout,
            getPreferredConnections(), getFilter());
  }
@@ -464,11 +480,12 @@
      ServerLoader loader =
        getServerLoader(replicationServer.getAdsProperties());
      ctx = loader.createContext();
      NamingEnumeration monitorEntries = ctx.search(jndiName, filter, ctls);
      NamingEnumeration<SearchResult> monitorEntries =
        ctx.search(jndiName, filter, ctls);
      while(monitorEntries.hasMore())
      {
        SearchResult sr = (SearchResult)monitorEntries.next();
        SearchResult sr = monitorEntries.next();
        String dn = ConnectionUtils.getFirstValue(sr, "domain-name");
        int replicaId = -1;
opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java
@@ -236,7 +236,8 @@
   * Clones the provided InitialLdapContext and returns a connection using
   * the same parameters.
   * @param ctx hte connection to be cloned.
   * @param timeout the timeout to establish the connection.
   * @param timeout the timeout to establish the connection in milliseconds.
   * Use {@code 0} to express no timeout.
   * @param trustManager the trust manager to be used to connect.
   * @param keyManager the key manager to be used to connect.
   * @return the new InitialLdapContext connected to the server.
@@ -575,11 +576,13 @@
   * @param ldapUrl the ldap URL of the server.
   * @param dn the dn to be used.
   * @param pwd the password to be used.
   * @param timeout the timeout to establish the connection in milliseconds.
   * Use {@code 0} to express no timeout.
   * @return <CODE>true</CODE> if we can connect and read the configuration and
   * <CODE>false</CODE> otherwise.
   */
  public static boolean canConnectAsAdministrativeUser(String ldapUrl,
      String dn, String pwd)
      String dn, String pwd, int timeout)
  {
    boolean canConnectAsAdministrativeUser = false;
    try
@@ -587,12 +590,12 @@
      InitialLdapContext ctx;
      if (ldapUrl.toLowerCase().startsWith("ldap:"))
      {
        ctx = createLdapContext(ldapUrl, dn, pwd, getDefaultLDAPTimeout(),
        ctx = createLdapContext(ldapUrl, dn, pwd, timeout,
            null);
      }
      else
      {
        ctx = createLdapsContext(ldapUrl, dn, pwd, getDefaultLDAPTimeout(),
        ctx = createLdapsContext(ldapUrl, dn, pwd, timeout,
            null, null, null);
      }
@@ -646,8 +649,8 @@
   * @param t the Thread to be used to create the InitialLdapContext.
   * @param pair an Object[] array that contains the InitialLdapContext and the
   * Throwable if any occurred.
   * @param timeout the timeout.  If we do not get to create the connection
   * before the timeout a CommunicationException will be thrown.
   * @param timeout the timeout in milliseconds.  If we do not get to create the
   * connection before the timeout a CommunicationException will be thrown.
   * @return the created InitialLdapContext
   * @throws NamingException if something goes wrong during the creation.
   */
opends/src/ads/org/opends/admin/ads/util/ServerLoader.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 */
package org.opends.admin.ads.util;
@@ -60,6 +60,7 @@
  private TopologyCacheException lastException;
  private ServerDescriptor serverDescriptor;
  private ApplicationTrustManager trustManager;
  private int timeout;
  private String dn;
  private String pwd;
  private LinkedHashSet<PreferredConnection> preferredLDAPURLs;
@@ -76,6 +77,8 @@
   * @param pwd the password that we must use to bind to the server.
   * @param trustManager the ApplicationTrustManager to be used when we try
   * to connect to the server.
   * @param timeout the timeout to establish the connection in milliseconds.
   * Use {@code 0} to express no timeout.
   * @param preferredLDAPURLs the list of preferred LDAP URLs that we want
   * to use to connect to the server.  They will be used only if they correspond
   * to the URLs that we found in the the server properties.
@@ -84,6 +87,7 @@
   */
  public ServerLoader(Map<ServerProperty,Object> serverProperties,
      String dn, String pwd, ApplicationTrustManager trustManager,
      int timeout,
      LinkedHashSet<PreferredConnection> preferredLDAPURLs,
      TopologyCacheFilter filter)
  {
@@ -91,6 +95,7 @@
    this.dn = dn;
    this.pwd = pwd;
    this.trustManager = trustManager;
    this.timeout = timeout;
    this.preferredLDAPURLs =
      new LinkedHashSet<PreferredConnection>(preferredLDAPURLs);
    this.filter = filter;
@@ -276,17 +281,17 @@
        {
        case LDAPS:
          ctx = ConnectionUtils.createLdapsContext(lastLdapUrl, dn, pwd,
              ConnectionUtils.getDefaultLDAPTimeout(), null, trustManager,
              timeout, null, trustManager,
              null);
          break;
        case START_TLS:
          ctx = ConnectionUtils.createStartTLSContext(lastLdapUrl, dn, pwd,
              ConnectionUtils.getDefaultLDAPTimeout(), null, trustManager,
              timeout, null, trustManager,
              null, null);
          break;
        default:
          ctx = ConnectionUtils.createLdapContext(lastLdapUrl, dn, pwd,
              ConnectionUtils.getDefaultLDAPTimeout(), null);
              timeout, null);
        }
      }
    }
opends/src/guitools/org/opends/guitools/controlpanel/ControlPanel.java
@@ -126,6 +126,7 @@
    {
      info.setTrustManager(new BlindApplicationTrustManager());
    }
    info.setConnectTimeout(argParser.getConnectTimeout());
  }
  /**
opends/src/guitools/org/opends/guitools/controlpanel/ControlPanelArgumentParser.java
@@ -22,29 +22,17 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2009 Sun Microsystems, Inc.
 *      Copyright 2009-2010 Sun Microsystems, Inc.
 */
package org.opends.guitools.controlpanel;
import static org.opends.messages.ToolMessages.*;
import static org.opends.server.tools.ToolConstants.OPTION_LONG_BINDDN;
import static org.opends.server.tools.ToolConstants.OPTION_LONG_BINDPWD;
import static org.opends.server.tools.ToolConstants.OPTION_LONG_BINDPWD_FILE;
import static org.opends.server.tools.ToolConstants.OPTION_LONG_HELP;
import static org.opends.server.tools.ToolConstants.OPTION_LONG_HOST;
import static org.opends.server.tools.ToolConstants.OPTION_LONG_PORT;
import static org.opends.server.tools.ToolConstants.OPTION_LONG_TRUSTALL;
import static org.opends.server.tools.ToolConstants.OPTION_SHORT_BINDDN;
import static org.opends.server.tools.ToolConstants.OPTION_SHORT_BINDPWD;
import static org.opends.server.tools.ToolConstants.OPTION_SHORT_BINDPWD_FILE;
import static org.opends.server.tools.ToolConstants.OPTION_SHORT_HELP;
import static org.opends.server.tools.ToolConstants.OPTION_SHORT_HOST;
import static org.opends.server.tools.ToolConstants.OPTION_SHORT_PORT;
import static org.opends.server.tools.ToolConstants.OPTION_SHORT_TRUSTALL;
import static org.opends.server.tools.ToolConstants.*;
import java.util.LinkedHashSet;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.messages.Message;
import org.opends.quicksetup.Constants;
import org.opends.quicksetup.UserData;
@@ -92,6 +80,11 @@
   */
  private BooleanArgument trustAllArg = null;
  /**
   * Argument to specify the connect timeout.
   */
  private IntegerArgument connectTimeoutArg = null;
  private BooleanArgument showUsageArg;
  /**
@@ -141,6 +134,7 @@
    portArg = new IntegerArgument("port", OPTION_SHORT_PORT, OPTION_LONG_PORT,
        false, false, true, INFO_PORT_PLACEHOLDER.get(),
        getDefaultAdministrationPort(), null,
        true, 1, true, 65535,
        INFO_DESCRIPTION_ADMIN_PORT.get());
    portArg.setPropertyName(OPTION_LONG_PORT);
    addArgument(portArg);
@@ -170,6 +164,16 @@
    trustAllArg.setPropertyName(OPTION_LONG_TRUSTALL);
    addArgument(trustAllArg);
    int defaultTimeout = ConnectionUtils.getDefaultLDAPTimeout();
    connectTimeoutArg = 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());
    connectTimeoutArg.setPropertyName(OPTION_LONG_CONNECT_TIMEOUT);
    addArgument(connectTimeoutArg);
    showUsageArg = new BooleanArgument("help", OPTION_SHORT_HELP,
        OPTION_LONG_HELP,
        INFO_DESCRIPTION_USAGE.get());
@@ -283,4 +287,24 @@
    return trustAllArg.isPresent();
  }
  /**
   * Returns the timeout to be used to connect in milliseconds.  The method
   * must be called after parsing the arguments.
   * @return the timeout to be used to connect in milliseconds.  Returns
   * {@code 0} if there is no timeout.
   * @throw {@code IllegalStateException} if the method is called before
   * parsing the arguments.
   */
  public int getConnectTimeout()
  {
    try
    {
      return connectTimeoutArg.getIntValue();
    }
    catch (ArgumentException ae)
    {
      throw new IllegalStateException("Argument parser is not parsed: "+ae, ae);
    }
  }
}
opends/src/guitools/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java
@@ -80,6 +80,7 @@
  private Control[] requestControls = new Control[] {};
  private ApplicationTrustManager trustManager;
  private int connectTimeout = ConnectionUtils.getDefaultLDAPTimeout();
  /**
   * Returns <CODE>true</CODE> if the connection passed is registered in the
@@ -514,13 +515,13 @@
    if (isSecureLDAPUrl(ldapUrl))
    {
      ctx = ConnectionUtils.createLdapsContext(ldapUrl.toString(), ar.dn,
          ar.password, ConnectionUtils.getDefaultLDAPTimeout(), null,
          ar.password, getConnectTimeout(), null,
          getTrustManager() , getKeyManager());
    }
    else
    {
      ctx = ConnectionUtils.createLdapContext(ldapUrl.toString(), ar.dn,
          ar.password, ConnectionUtils.getDefaultLDAPTimeout(), null);
          ar.password, getConnectTimeout(), null);
    }
    return ctx;
  }
@@ -546,6 +547,27 @@
    return trustManager;
  }
  /**
   * Returns the timeout to establish the connection in milliseconds.
   * @return the timeout to establish the connection in milliseconds.
   */
  public int getConnectTimeout()
  {
    return connectTimeout;
  }
  /**
   * Sets the timeout to establish the connection in milliseconds.
   * Use {@code 0} to express no timeout.
   * @param connectTimeout the timeout to establish the connection in
   * milliseconds.
   * Use {@code 0} to express no timeout.
   */
  public void setConnectTimeout(int connectTimeout)
  {
    this.connectTimeout = connectTimeout;
  }
  private KeyManager getKeyManager()
  {
//  TODO: we should get it from ControlPanelInfo
opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java
@@ -83,6 +83,7 @@
  private boolean stopPooling;
  private boolean pooling;
  private ApplicationTrustManager trustManager;
  private int connectTimeout = ConnectionUtils.getDefaultLDAPTimeout();
  private ConnectionProtocolPolicy connectionPolicy =
    ConnectionProtocolPolicy.USE_MOST_SECURE_AVAILABLE;
  private String ldapURL;
@@ -353,7 +354,7 @@
    {
      InitialLdapContext cloneLdc =
        ConnectionUtils.cloneInitialLdapContext(userDataCtx,
            ConnectionUtils.getDefaultLDAPTimeout(),
            getConnectTimeout(),
            getTrustManager(), null);
      connectionPool.registerConnection(cloneLdc);
    }
@@ -579,7 +580,7 @@
            ctx = Utils.createLdapsContext(lastRemoteAdministrationURL,
                lastWorkingBindDN,
                lastWorkingBindPwd,
                Utils.getDefaultLDAPTimeout(), null,
                getConnectTimeout(), null,
                getTrustManager());
          }
        }
@@ -885,6 +886,28 @@
  }
  /**
   * Returns the timeout to establish the connection in milliseconds.
   * @return the timeout to establish the connection in milliseconds.
   */
  public int getConnectTimeout()
  {
    return connectTimeout;
  }
  /**
   * Sets the timeout to establish the connection in milliseconds.
   * Use {@code 0} to express no timeout.
   * @param connectTimeout the timeout to establish the connection in
   * milliseconds.
   * Use {@code 0} to express no timeout.
   */
  public void setConnectTimeout(int connectTimeout)
  {
    this.connectTimeout = connectTimeout;
    connectionPool.setConnectTimeout(connectTimeout);
  }
  /**
   * Returns the connection policy to be used by this ControlPanelInfo (and in
   * general by the control panel).
   * @return the connection policy to be used by this ControlPanelInfo.
opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteEntryTask.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 */
package org.opends.guitools.controlpanel.task;
@@ -455,7 +455,7 @@
    try
    {
      ctx1 = ConnectionUtils.cloneInitialLdapContext(ctx,
          ConnectionUtils.getDefaultLDAPTimeout(),
          getInfo().getConnectTimeout(),
          getInfo().getTrustManager(), null);
      Control[] ctls = {
          new BasicControl(ServerConstants.OID_SUBTREE_DELETE_CONTROL)};
opends/src/guitools/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
@@ -593,7 +593,7 @@
                  new Integer(port.getText().trim()), true);
              ctx = Utils.createLdapsContext(usedUrl, dn.getText(),
                  String.valueOf(pwd.getPassword()),
                  Utils.getDefaultLDAPTimeout(), null,
                  getInfo().getConnectTimeout(), null,
                  getInfo().getTrustManager());
              checkVersion(ctx);
            }
opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
@@ -2363,7 +2363,7 @@
          ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
    }
    ctx = Utils.createLdapsContext(usedUrl,
        bindDN, pwd, Utils.getDefaultLDAPTimeout(), null,
        bindDN, pwd, controlInfo.getConnectTimeout(), null,
        controlInfo.getTrustManager());
    /*
@@ -2402,7 +2402,7 @@
            ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
      }
      ctx = Utils.createStartTLSContext(usedUrl,
          bindDN, pwd, Utils.getDefaultLDAPTimeout(), null,
          bindDN, pwd, controlInfo.getConnectTimeout(), null,
          controlInfo.getTrustManager(), null);
    }
    else if (controlInfo.connectUsingLDAPS())
@@ -2414,7 +2414,7 @@
            ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
      }
      ctx = Utils.createLdapsContext(usedUrl,
          bindDN, pwd, Utils.getDefaultLDAPTimeout(), null,
          bindDN, pwd, controlInfo.getConnectTimeout(), null,
          controlInfo.getTrustManager());
    }
    else
@@ -2426,7 +2426,7 @@
            ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
      }
      ctx = Utils.createLdapContext(usedUrl,
          bindDN, pwd, Utils.getDefaultLDAPTimeout(), null);
          bindDN, pwd, controlInfo.getConnectTimeout(), null);
    }
    checkCanReadConfig(ctx);
opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 */
package org.opends.guitools.uninstaller;
@@ -155,6 +155,8 @@
      userData.setForceOnError(args.isForceOnError());
      userData.setTrustManager(args.getTrustManager());
      userData.setConnectTimeout(getConnectTimeout());
      /*
       * Step 2: check that the provided parameters are compatible.
       */
@@ -249,6 +251,7 @@
      }
      info = ControlPanelInfo.getInstance();
      info.setTrustManager(userData.getTrustManager());
      info.setConnectTimeout(getConnectTimeout());
      info.regenerateDescriptor();
      info.setConnectionPolicy(ConnectionProtocolPolicy.USE_ADMIN);
@@ -1161,7 +1164,7 @@
    try
    {
      info.setTrustManager(userData.getTrustManager());
      info.setConnectTimeout(getConnectTimeout());
      String host = "localhost";
      int port = 389;
      String adminUid = userData.getAdminUID();
@@ -1181,7 +1184,8 @@
        LOG.log(Level.SEVERE, "Error parsing url: "+adminConnectorUrl);
      }
      ctx = createAdministrativeContext(host, port, useSSL, useStartTLS, dn,
          pwd, userData.getTrustManager());
          pwd, getConnectTimeout(),
          userData.getTrustManager());
      ADSContext adsContext = new ADSContext(ctx);
      if (interactive && (userData.getTrustManager() == null))
@@ -1195,7 +1199,7 @@
      }
      LOG.log(Level.INFO, "Reloading topology");
      TopologyCache cache = new TopologyCache(adsContext,
          userData.getTrustManager());
          userData.getTrustManager(), getConnectTimeout());
      cache.getFilter().setSearchMonitoringInformation(false);
      cache.reloadTopology();
@@ -1556,4 +1560,25 @@
     super.println(msg);
     LOG.log(Level.WARNING, msg.toString());
   }
   /**
    * Returns the timeout to be used to connect in milliseconds.  The method
    * must be called after parsing the arguments.
    * @return the timeout to be used to connect in milliseconds.  Returns
    * {@code 0} if there is no timeout.
    * @throw {@code IllegalStateException} if the method is called before
    * parsing the arguments.
    */
   private int getConnectTimeout()
   {
     try
     {
       return parser.getSecureArgsList().connectTimeoutArg.getIntValue();
     }
     catch (ArgumentException ae)
     {
       throw new IllegalStateException("Argument parser is not parsed: "+ae,
           ae);
     }
   }
}
opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
@@ -1593,7 +1593,7 @@
    if (loginDialog == null)
    {
      loginDialog = new LoginDialog(qs.getDialog().getFrame(),
          getTrustManager());
          getTrustManager(), getConnectTimeout());
      loginDialog.pack();
    }
    Utilities.centerOnComponent(loginDialog, qs.getDialog().getFrame());
@@ -1626,7 +1626,7 @@
          LOG.log(Level.INFO, "Loading Topology Cache in askForAuthentication");
          ADSContext adsContext = new ADSContext(ctx);
          TopologyCache cache = new TopologyCache(adsContext,
              getTrustManager());
              getTrustManager(), getConnectTimeout());
          cache.getFilter().setSearchMonitoringInformation(false);
          cache.reloadTopology();
          return cache;
@@ -2011,6 +2011,7 @@
            getUninstallUserData().getAdminUID());
        String pwd = getUninstallUserData().getAdminPwd();
        ctx = getRemoteConnection(server, dn, pwd, getTrustManager(),
            getConnectTimeout(),
            new LinkedHashSet<PreferredConnection>());
        // Update replication servers and domains.  If the domain
@@ -2305,5 +2306,15 @@
    }
    return isServerToUninstall;
  }
  /**
   * Returns the timeout to be used to connect in milliseconds.
   * @return the timeout to be used to connect in milliseconds.  Returns
   * {@code 0} if there is no timeout.
   */
  private int getConnectTimeout()
  {
    return getUserData().getConnectTimeout();
  }
}
opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 */
package org.opends.guitools.uninstaller;
@@ -198,12 +198,11 @@
    secureArgsList.adminUidArg.setHidden(false);
    defaultArgs.remove(secureArgsList.hostNameArg);
    defaultArgs.remove(secureArgsList.portArg);
    UserData uData = new UserData();
    referencedHostNameArg = new StringArgument("referencedHostName",
        ToolConstants.OPTION_SHORT_HOST,
        OPTION_LONG_REFERENCED_HOST_NAME, false, false, true,
        INFO_HOST_PLACEHOLDER.get(),
        uData.getHostName(), OPTION_LONG_REFERENCED_HOST_NAME,
        UserData.getDefaultHostName(), OPTION_LONG_REFERENCED_HOST_NAME,
        INFO_DESCRIPTION_REFERENCED_HOST.get());
    defaultArgs.add(referencedHostNameArg);
opends/src/guitools/org/opends/guitools/uninstaller/ui/LoginDialog.java
@@ -99,6 +99,7 @@
  private boolean isCancelled = true;
  private ApplicationTrustManager trustManager;
  private int timeout;
  private InitialLdapContext ctx;
@@ -112,8 +113,11 @@
   * @param parent the parent frame for this dialog.
   * @param trustManager the trust manager to be used for the secure
   * connections.
   * @param timeout the timeout to establish the connection in milliseconds.
   * Use {@code 0} to express no timeout.
   */
  public LoginDialog(JFrame parent, ApplicationTrustManager trustManager)
  public LoginDialog(JFrame parent, ApplicationTrustManager trustManager,
      int timeout)
  {
    super(parent);
    setTitle(INFO_LOGIN_DIALOG_TITLE.get().toString());
@@ -124,6 +128,7 @@
      throw new IllegalArgumentException("The trustmanager cannot be null.");
    }
    this.trustManager = trustManager;
    this.timeout = timeout;
    /*
     * TODO: find a way to calculate this dynamically.  This is done to avoid
     * all the text in a single line.
@@ -245,8 +250,8 @@
    gbc.weightx = 1.0;
    gbc.insets.left = UIFactory.LEFT_INSET_PRIMARY_FIELD;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    UserData uData = new UserData();
    tfHostName = UIFactory.makeJTextField(Message.raw(uData.getHostName()),
    tfHostName = UIFactory.makeJTextField(
        Message.raw(UserData.getDefaultHostName()),
        INFO_UNINSTALL_LOGIN_HOST_NAME_TOOLTIP.get(),
        UIFactory.HOST_FIELD_SIZE, UIFactory.TextStyle.TEXTFIELD);
    p2.add(tfHostName, gbc);
@@ -388,6 +393,7 @@
        {
          ControlPanelInfo info = ControlPanelInfo.getInstance();
          info.setTrustManager(getTrustManager());
          info.setConnectTimeout(timeout);
          info.regenerateDescriptor();
          ConfigFromFile conf = new ConfigFromFile();
          conf.readConfiguration();
@@ -719,7 +725,8 @@
    {
      LoginDialog dlg = new LoginDialog(
          org.opends.guitools.controlpanel.util.Utilities.createFrame(),
          new ApplicationTrustManager(null));
          new ApplicationTrustManager(null),
          5000);
      dlg.pack();
      dlg.setVisible(true);
    } catch (Exception ex)
opends/src/messages/messages/tools.properties
@@ -2561,3 +2561,6 @@
 Error code starting Windows Service: %d
INFO_DESCRIPTION_DBTEST_STATS_ONLY_1710=Do not display the JE data, \
just statistics
INFO_TIMEOUT_PLACEHOLDER_1711={timeout}
INFO_DESCRIPTION_CONNECTION_TIMEOUT_1712=Maximum length of time (in \
 milliseconds) that can be taken to establish a connection
opends/src/quicksetup/org/opends/quicksetup/Application.java
@@ -774,6 +774,8 @@
   * connection.
   * @param dn the dn to be used to authenticate.
   * @param pwd the pwd to be used to authenticate.
   * @param timeout the timeout to establish the connection in milliseconds.
   * Use {@code 0} to express no timeout.
   * @param cnx the ordered list of preferred connections to connect to the
   * server.
   * @return the InitialLdapContext to the remote server.
@@ -781,6 +783,7 @@
   */
  protected InitialLdapContext getRemoteConnection(ServerDescriptor server,
      String dn, String pwd, ApplicationTrustManager trustManager,
      int timeout,
      LinkedHashSet<PreferredConnection> cnx)
  throws ApplicationException
  {
@@ -790,7 +793,7 @@
    filter.setSearchMonitoringInformation(false);
    filter.setSearchBaseDNInformation(false);
    ServerLoader loader = new ServerLoader(adsProperties, dn, pwd,
        trustManager, cnx, filter);
        trustManager, timeout, cnx, filter);
    InitialLdapContext ctx = null;
    try
opends/src/quicksetup/org/opends/quicksetup/UserData.java
@@ -35,6 +35,7 @@
import org.opends.admin.ads.ServerDescriptor;
import org.opends.admin.ads.SuffixDescriptor;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.quicksetup.installer.AuthenticationData;
import org.opends.quicksetup.installer.DataReplicationOptions;
import org.opends.quicksetup.installer.NewSuffixOptions;
@@ -102,6 +103,8 @@
  private static String defaultHostName;
  private int connectTimeout = ConnectionUtils.getDefaultLDAPTimeout();
  /**
   * The script name to be used to get and set the java arguments for the
   * server runtime.
@@ -883,4 +886,23 @@
        "upgrade", "verify-index", "dbtest"
    };
  }
  /**
   * Sets the timeout to be used to establish a connection.
   * @param connectTimeout the timeout to be used to establish a connection.
   */
  public void setConnectTimeout(int connectTimeout)
  {
    this.connectTimeout = connectTimeout;
  }
  /**
   * Returns the timeout to be used to connect in milliseconds.
   * @return the timeout to be used to connect in milliseconds.  Returns
   * {@code 0} if there is no timeout.
   */
  public int getConnectTimeout()
  {
    return connectTimeout;
  }
}
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -242,9 +242,34 @@
  public UserData createUserData() {
    UserData ud = new UserData();
    ud.setServerLocation(getDefaultServerLocation());
    initializeUserDataWithUserArguments(ud, getUserArguments());
    return ud;
  }
  private void initializeUserDataWithUserArguments(UserData ud,
      String[] userArguments)
  {
    for (int i=0; i<userArguments.length; i++)
    {
      if (userArguments[i].equalsIgnoreCase("--connectTimeout"))
      {
        if (i < userArguments.length - 1)
        {
          String sTimeout = userArguments[i+1];
          try
          {
            ud.setConnectTimeout(new Integer(sTimeout));
          }
          catch (Throwable t)
          {
            LOG.log(Level.WARNING, "Error getting connect timeout: "+t, t);
          }
        }
        break;
      }
    }
  }
  /**
   * {@inheritDoc}
   */
@@ -1553,12 +1578,12 @@
          ApplicationTrustManager trustManager = getTrustManager();
          trustManager.setHost(auth.getHostName());
          ctx = createLdapsContext(ldapUrl, dn, pwd,
              getDefaultLDAPTimeout(), null, trustManager);
              getConnectTimeout(), null, trustManager);
        }
        else
        {
          ctx = createLdapContext(ldapUrl, dn, pwd,
              getDefaultLDAPTimeout(), null);
              getConnectTimeout(), null);
        }
        ADSContext adsContext = new ADSContext(ctx);
@@ -2619,12 +2644,12 @@
          ApplicationTrustManager trustManager = getTrustManager();
          trustManager.setHost(auth.getHostName());
          remoteCtx = createLdapsContext(ldapUrl, dn, pwd,
                  getDefaultLDAPTimeout(), null, trustManager);
              getConnectTimeout(), null, trustManager);
        }
        else
        {
          remoteCtx = createLdapContext(ldapUrl, dn, pwd,
                  getDefaultLDAPTimeout(), null);
              getConnectTimeout(), null);
        }
        adsContext = new ADSContext(remoteCtx); // adsContext owns remoteCtx
@@ -3613,7 +3638,7 @@
      try
      {
        ctx = createLdapsContext(ldapUrl, dn, pwd,
              getDefaultLDAPTimeout(), null, trustManager);
            getConnectTimeout(), null, trustManager);
      }
      catch (Throwable t)
      {
@@ -3623,7 +3648,7 @@
          dn = ADSContext.getAdministratorDN(dn);
          effectiveDn[0] = dn;
          ctx = createLdapsContext(ldapUrl, dn, pwd,
                getDefaultLDAPTimeout(), null, trustManager);
              getConnectTimeout(), null, trustManager);
        }
        else
        {
@@ -4227,7 +4252,8 @@
    {
      type = SuffixesToReplicateOptions.Type.NEW_SUFFIX_IN_TOPOLOGY;
    }
    lastLoadedCache = new TopologyCache(adsContext, trustManager);
    lastLoadedCache = new TopologyCache(adsContext, trustManager,
        getConnectTimeout());
    LinkedHashSet<PreferredConnection> cnx =
      new LinkedHashSet<PreferredConnection>();
    cnx.add(PreferredConnection.getPreferredConnection(
@@ -4409,7 +4435,7 @@
    String dn = getUserData().getDirectoryManagerDn();
    String pwd = getUserData().getDirectoryManagerPwd();
    return createLdapsContext(ldapUrl, dn, pwd,
        getDefaultLDAPTimeout(), null, null);
        getConnectTimeout(), null, null);
  }
  /**
@@ -4458,8 +4484,8 @@
      }
      server.setAdsProperties(adsProperties);
    }
    return  getRemoteConnection(server, auth.getDn(), auth.getPwd(),
        trustManager, cnx);
    return getRemoteConnection(server, auth.getDn(), auth.getPwd(),
        trustManager, getConnectTimeout(), cnx);
  }
  /**
@@ -5033,6 +5059,16 @@
      lastImportProgress = parsedMessage;
    }
  }
  /**
   * Returns the timeout to be used to connect in milliseconds.
   * @return the timeout to be used to connect in milliseconds.  Returns
   * {@code 0} if there is no timeout.
   */
  protected int getConnectTimeout()
  {
    return getUserData().getConnectTimeout();
  }
}
/**
opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java
@@ -1169,8 +1169,7 @@
    writer.close();
    String destinationFile;
    String libDir = Utils.getPath(Utils.
            getInstancePathFromInstallPath(installPath),
    String libDir = Utils.getPath(installPath,
        Installation.LIBRARIES_PATH_RELATIVE);
    if (Utils.isWindows())
    {
opends/src/quicksetup/org/opends/quicksetup/ui/DirectoryManagerAuthenticationDialog.java
File was deleted
opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java
@@ -71,6 +71,8 @@
  /** The QuickSetupDialog in control. */
  private QuickSetupDialog qs;
  private String[] args = {};
  /**
   * Constructs an instance of an application.  Subclasses
   * of this application must have a default constructor.
@@ -633,4 +635,23 @@
  public void setQuickSetupDialog(QuickSetupDialog dialog) {
    this.qs = dialog;
  }
  /**
   * Sets the arguments passed in the command-line to launch the application.
   * @param args the arguments passed in the command-line to launch the
   * application.
   */
  public void setUserArguments(String[] args)
  {
    this.args = args;
  }
  /**
   * Returns the arguments passed in the command-line to launch the application.
   * @return the arguments passed in the command-line to launch the application.
   */
  public String[] getUserArguments()
  {
    return args;
  }
}
opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java
@@ -117,7 +117,14 @@
    application = Application.create();
    application.setProgressMessageFormatter(formatter);
    application.setCurrentInstallStatus(installStatus);
    if (args != null)
    {
      application.setUserArguments(args);
    }
    else
    {
      application.setUserArguments(new String[]{});
    }
    try
    {
      initLookAndFeel();
opends/src/quicksetup/org/opends/quicksetup/util/ServerController.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 */
package org.opends.quicksetup.util;
@@ -478,7 +478,7 @@
            {
              ctx = Utils.createLdapsContext(
                  ldapUrl,
                  userDn, userPw, ConnectionUtils.getDefaultLDAPTimeout(),
                  userDn, userPw, application.getUserData().getConnectTimeout(),
                  null, null);
              connected = true;
            }
opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
@@ -1134,13 +1134,16 @@
   * @param ldapUrl the ldap URL of the server.
   * @param dn the dn to be used.
   * @param pwd the password to be used.
   * @param timeout the timeout to establish the connection in milliseconds.
   * Use {@code 0} to express no timeout.
   * @return <CODE>true</CODE> if we can connect and read the configuration and
   * <CODE>false</CODE> otherwise.
   */
  public static boolean canConnectAsAdministrativeUser(String ldapUrl,
      String dn, String pwd)
      String dn, String pwd, int timeout)
  {
    return ConnectionUtils.canConnectAsAdministrativeUser(ldapUrl, dn, pwd);
    return ConnectionUtils.canConnectAsAdministrativeUser(ldapUrl, dn, pwd,
        timeout);
  }
/**
@@ -1246,17 +1249,6 @@
    return msg;
  }
  /**
   * Returns the default LDAP timeout in milliseconds when we try to connect to
   * a server.
   * @return the default LDAP timeout in milliseconds when we try to connect to
   * a server.
   */
  public static int getDefaultLDAPTimeout()
  {
    return ConnectionUtils.getDefaultLDAPTimeout();
  }
  /**
   * Returns the path of the installation of the directory server.  Note that
opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
@@ -57,6 +57,7 @@
import org.opends.admin.ads.util.ApplicationKeyManager;
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.quicksetup.Constants;
import org.opends.server.admin.AdministrationConnector;
import org.opends.server.admin.server.ServerManagementContext;
@@ -172,6 +173,11 @@
  public StringArgument  saslOptionArg = null;
  /**
   * Argument to specify the connection timeout.
   */
  public IntegerArgument connectTimeoutArg = null;
  /**
   * Private container for global arguments.
   */
  private LinkedHashSet<Argument> argList = null;
@@ -483,6 +489,7 @@
    portArg = new IntegerArgument("port", OPTION_SHORT_PORT, OPTION_LONG_PORT,
        false, false, true, INFO_PORT_PLACEHOLDER.get(),
        AdministrationConnector.DEFAULT_ADMINISTRATION_CONNECTOR_PORT, null,
        true, 1, true, 65535,
        portDescription);
    portArg.setPropertyName(OPTION_LONG_PORT);
    argList.add(portArg);
@@ -581,6 +588,16 @@
    certNicknameArg.setPropertyName(OPTION_LONG_CERT_NICKNAME);
    argList.add(certNicknameArg);
    int defaultTimeout = ConnectionUtils.getDefaultLDAPTimeout();
    connectTimeoutArg = 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());
    connectTimeoutArg.setPropertyName(OPTION_LONG_CONNECT_TIMEOUT);
    argList.add(connectTimeoutArg);
    return argList;
  }
opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2007-2009 Sun Microsystems, Inc.
 *      Copyright 2007-2010 Sun Microsystems, Inc.
 */
package org.opends.server.admin.client.cli;
@@ -468,4 +468,24 @@
  {
    return secureArgsList.getKeyManager() ;
  }
  /**
   * Returns the timeout to be used to connect in milliseconds.  The method
   * must be called after parsing the arguments.
   * @return the timeout to be used to connect in milliseconds.  Returns
   * {@code 0} if there is no timeout.
   * @throw {@code IllegalStateException} if the method is called before
   * parsing the arguments.
   */
  public int getConnectTimeout()
  {
    try
    {
      return secureArgsList.connectTimeoutArg.getIntValue();
    }
    catch (ArgumentException ae)
    {
      throw new IllegalStateException("Argument parser is not parsed: "+ae, ae);
    }
  }
}
opends/src/server/org/opends/server/tools/InstallDS.java
@@ -761,6 +761,7 @@
    uData.setConfigurationFile(argParser.configFileArg.getValue());
    uData.setQuiet(isQuiet());
    uData.setVerbose(isVerbose());
    uData.setConnectTimeout(getConnectTimeout());
    //  Check the validity of the directory manager DNs
    String dmDN = argParser.directoryManagerDNArg.getValue();
@@ -1051,6 +1052,7 @@
    uData.setConfigurationFile(argParser.configFileArg.getValue());
    uData.setQuiet(isQuiet());
    uData.setVerbose(isVerbose());
    uData.setConnectTimeout(getConnectTimeout());
    promptIfRequiredForDirectoryManager(uData);
    promptIfRequiredForPortData(uData);
@@ -2782,4 +2784,15 @@
    }
    return hostName;
  }
  /**
   * Returns the timeout to be used to connect in milliseconds.  The method
   * must be called after parsing the arguments.
   * @return the timeout to be used to connect in milliseconds.  Returns
   * {@code 0} if there is no timeout.
   */
  private int getConnectTimeout()
  {
    return argParser.getConnectTimeout();
  }
}
opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java
@@ -36,6 +36,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.messages.Message;
import org.opends.quicksetup.Constants;
import org.opends.quicksetup.Installation;
@@ -99,6 +100,7 @@
  StringArgument    keyStorePasswordArg;
  StringArgument    certNicknameArg;
  StringArgument    progNameArg;
  IntegerArgument   connectTimeoutArg = null;
  private static final Logger LOG = Logger.getLogger(
      InstallDSArgumentParser.class.getName());
@@ -411,6 +413,17 @@
        INFO_INSTALLDS_DESCRIPTION_CERT_NICKNAME.get());
    addDefaultArgument(certNicknameArg);
    int defaultTimeout = ConnectionUtils.getDefaultLDAPTimeout();
    connectTimeoutArg = new IntegerArgument(OPTION_LONG_CONNECT_TIMEOUT,
        null, OPTION_LONG_CONNECT_TIMEOUT,
        false, false, true, INFO_TIMEOUT_PLACEHOLDER.get(),
        defaultTimeout, null,
        true, 1, true, 65535,
        INFO_DESCRIPTION_CONNECTION_TIMEOUT.get());
    connectTimeoutArg.setPropertyName(OPTION_LONG_CONNECT_TIMEOUT);
    connectTimeoutArg.setHidden(true);
    addArgument(connectTimeoutArg);
    showUsageArg = new BooleanArgument(
        OPTION_LONG_HELP.toLowerCase(), OPTION_SHORT_HELP,
        OPTION_LONG_HELP,
@@ -784,4 +797,24 @@
    String configDir = Utils.getPath(root, Installation.CONFIG_PATH_RELATIVE);
    return Utils.getPath(configDir, Installation.CURRENT_CONFIG_FILE_NAME);
  }
  /**
   * Returns the timeout to be used to connect in milliseconds.  The method
   * must be called after parsing the arguments.
   * @return the timeout to be used to connect in milliseconds.  Returns
   * {@code 0} if there is no timeout.
   * @throw {@code IllegalStateException} if the method is called before
   * parsing the arguments.
   */
  public int getConnectTimeout()
  {
    try
    {
      return connectTimeoutArg.getIntValue();
    }
    catch (ArgumentException ae)
    {
      throw new IllegalStateException("Argument parser is not parsed: "+ae, ae);
    }
  }
}
opends/src/server/org/opends/server/tools/LDAPCompare.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.BufferedReader;
@@ -63,6 +64,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.LDAPAssertionRequestControl;
@@ -380,6 +382,7 @@
    StringArgument    saslOptions            = null;
    StringArgument    trustStorePath         = null;
    StringArgument    trustStorePassword     = null;
    IntegerArgument   connectTimeout         = null;
    BooleanArgument   scriptFriendlyArgument = null;
    StringArgument    propertiesFileArgument = null;
    BooleanArgument   noPropertiesFileArgument = null;
@@ -593,6 +596,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(),
@@ -973,7 +986,10 @@
      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);
      ldapCompare = new LDAPCompare(nextMessageID, out, err);
opends/src/server/org/opends/server/tools/LDAPConnection.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2009 Sun Microsystems, Inc.
 *      Copyright 2009-2010 Sun Microsystems, Inc.
 */
package org.opends.server.tools;
import org.opends.messages.Message;
@@ -152,6 +152,30 @@
                            AtomicInteger nextMessageID)
                            throws LDAPConnectionException
  {
    connectToHost(bindDN, bindPassword, nextMessageID, 0);
  }
  /**
   * Connects to the directory server instance running on specified hostname
   * and port number.
   *
   * @param  bindDN         The DN to bind with.
   * @param  bindPassword   The password to bind with.
   * @param  nextMessageID  The message ID counter that should be used for
   *                        operations performed while establishing the
   *                        connection.
   * @param  timeout        The timeout to connect to the specified host.  The
   *                        timeout is the timeout at the socket level in
   *                        milliseconds.  If the timeout value is {@code 0},
   *                        no timeout is used.
   *
   * @throws  LDAPConnectionException  If a problem occurs while attempting to
   *                                   establish the connection to the server.
   */
  public void connectToHost(String bindDN, String bindPassword,
                            AtomicInteger nextMessageID, int timeout)
                            throws LDAPConnectionException
  {
    Socket socket;
    Socket startTLSSocket = null;
    int resultCode;
@@ -276,6 +300,10 @@
    {
      socket.setSoLinger(true, 1);
      socket.setReuseAddress(true);
      if (timeout > 0)
      {
        socket.setSoTimeout(timeout);
      }
    } catch(IOException e)
    {
      if (debugEnabled())
opends/src/server/org/opends/server/tools/LDAPDelete.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.BufferedReader;
@@ -341,6 +342,7 @@
    StringArgument    saslOptions            = null;
    StringArgument    trustStorePath         = null;
    StringArgument    trustStorePassword     = null;
    IntegerArgument   connectTimeout         = null;
    StringArgument    propertiesFileArgument = null;
    BooleanArgument   noPropertiesFileArgument = null;
@@ -537,6 +539,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',
                                       OPTION_LONG_ENCODING, false,
                                       false, true,
@@ -813,7 +825,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);
      ldapDelete = new LDAPDelete(nextMessageID, out, err);
      if(fileNameValue == null && dnStrings.isEmpty())
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);
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();
opends/src/server/org/opends/server/tools/LDAPSearch.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.BufferedReader;
@@ -707,6 +708,7 @@
    StringArgument    sortOrder                = null;
    StringArgument    trustStorePath           = null;
    StringArgument    trustStorePassword       = null;
    IntegerArgument   connectTimeout           = null;
    StringArgument    vlvDescriptor            = null;
    StringArgument    effectiveRightsUser      = null;
    StringArgument    effectiveRightsAttrs     = null;
@@ -1017,6 +1019,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(), null,
@@ -1756,7 +1768,10 @@
      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);
      int matchingEntries = 0;
      if (simplePageSize.isPresent())
opends/src/server/org/opends/server/tools/ToolConstants.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 */
package org.opends.server.tools;
@@ -431,6 +431,12 @@
           "ldapVersion";
    /**
     * The value for the long option connect timeout attribute.
     */
    public static final String OPTION_LONG_CONNECT_TIMEOUT =
      "connectTimeout";
    /**
     * The value for the long option version.
     */
     public static final char OPTION_SHORT_PRODUCT_VERSION = 'V';
opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2007-2009 Sun Microsystems, Inc.
 *      Copyright 2007-2010 Sun Microsystems, Inc.
 */
package org.opends.server.tools.dsconfig;
@@ -174,7 +174,7 @@
          try
          {
            ctx = ConnectionUtils.createLdapsContext(ldapsUrl, bindDN,
                bindPassword, ConnectionUtils.getDefaultLDAPTimeout(), null,
                bindPassword, ci.getConnectTimeout(), null,
                trustManager, keyManager);
            ctx.reconnect(null);
            conn = JNDIDirContextAdaptor.adapt(ctx);
opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2007-2009 Sun Microsystems, Inc.
 *      Copyright 2007-2010 Sun Microsystems, Inc.
 */
package org.opends.server.tools.dsreplication;
@@ -2541,7 +2541,7 @@
        InitialLdapContext ctx = createAdministrativeContext(
            uData.getHostName1(), uData.getPort1(), useSSL,
            useStartTLS, ADSContext.getAdministratorDN(adminUid),
            adminPwd, getTrustManager());
            adminPwd, getConnectTimeout(), getTrustManager());
        uData.setBindDn1(ADSContext.getAdministratorDN(adminUid));
        uData.setPwd1(adminPwd);
        ctx.close();
@@ -2576,7 +2576,7 @@
        InitialLdapContext ctx = createAdministrativeContext(
            uData.getHostName2(), uData.getPort2(), useSSL,
            useStartTLS, ADSContext.getAdministratorDN(adminUid),
            adminPwd, getTrustManager());
            adminPwd, getConnectTimeout(), getTrustManager());
        uData.setBindDn2(ADSContext.getAdministratorDN(adminUid));
        uData.setPwd2(adminPwd);
        ctx.close();
@@ -2873,7 +2873,7 @@
          // LDAPConnectionConsoleInteraction object might have changed.
          TopologyCache cache = new TopologyCache(adsContext,
              getTrustManager());
              getTrustManager(), getConnectTimeout());
          cache.getFilter().setSearchMonitoringInformation(false);
          cache.getFilter().setSearchBaseDNInformation(false);
          cache.setPreferredConnections(
@@ -2952,9 +2952,10 @@
                  {
                    ctx[0] = createAdministrativeContext(host, port, isSSL,
                        isStartTLS, ADSContext.getAdministratorDN(adminUid),
                        adminPwd, getTrustManager());
                        adminPwd, getConnectTimeout(), getTrustManager());
                    adsContext = new ADSContext(ctx[0]);
                    cache = new TopologyCache(adsContext, getTrustManager());
                    cache = new TopologyCache(adsContext, getTrustManager(),
                        getConnectTimeout());
                    cache.getFilter().setSearchMonitoringInformation(false);
                    cache.getFilter().setSearchBaseDNInformation(false);
                    cache.setPreferredConnections(
@@ -3325,7 +3326,7 @@
    {
      ctx1 = createAdministrativeContext(host1, port1, useSSL,
          useStartTLS, uData.getBindDn1(), uData.getPwd1(),
          getTrustManager());
          getConnectTimeout(), getTrustManager());
    }
    catch (NamingException ne)
    {
@@ -3338,7 +3339,7 @@
    {
      ctx2 = createAdministrativeContext(host2, port2, useSSL,
          useStartTLS, uData.getBindDn2(), uData.getPwd2(),
          getTrustManager());
          getConnectTimeout(), getTrustManager());
    }
    catch (NamingException ne)
    {
@@ -3566,7 +3567,7 @@
    try
    {
      ctx = createAdministrativeContext(uData.getHostName(), uData.getPort(),
          useSSL, useStartTLS, bindDn, uData.getAdminPwd(),
          useSSL, useStartTLS, bindDn, uData.getAdminPwd(), getConnectTimeout(),
          getTrustManager());
    }
    catch (NamingException ne)
@@ -3691,7 +3692,7 @@
      ctx = createAdministrativeContext(uData.getHostName(), uData.getPort(),
          useSSL, useStartTLS,
          ADSContext.getAdministratorDN(uData.getAdminUid()),
          uData.getAdminPwd(), getTrustManager());
          uData.getAdminPwd(), getConnectTimeout(), getTrustManager());
    }
    catch (NamingException ne)
    {
@@ -3757,7 +3758,7 @@
          uData.getPortSource(), useSSL,
          useStartTLS,
          ADSContext.getAdministratorDN(uData.getAdminUid()),
          uData.getAdminPwd(), getTrustManager());
          uData.getAdminPwd(), getConnectTimeout(), getTrustManager());
    }
    catch (NamingException ne)
    {
@@ -3774,7 +3775,7 @@
          uData.getPortDestination(), useSSL,
          useStartTLS,
          ADSContext.getAdministratorDN(uData.getAdminUid()),
          uData.getAdminPwd(), getTrustManager());
          uData.getAdminPwd(), getConnectTimeout(), getTrustManager());
    }
    catch (NamingException ne)
    {
@@ -3883,7 +3884,7 @@
      ctx = createAdministrativeContext(uData.getHostName(), uData.getPort(),
          useSSL, useStartTLS,
          ADSContext.getAdministratorDN(uData.getAdminUid()),
          uData.getAdminPwd(), getTrustManager());
          uData.getAdminPwd(), getConnectTimeout(), getTrustManager());
    }
    catch (NamingException ne)
    {
@@ -3981,7 +3982,7 @@
      ctx = createAdministrativeContext(uData.getHostName(), uData.getPort(),
          useSSL, useStartTLS,
          ADSContext.getAdministratorDN(uData.getAdminUid()),
          uData.getAdminPwd(), getTrustManager());
          uData.getAdminPwd(), getConnectTimeout(), getTrustManager());
    }
    catch (NamingException ne)
    {
@@ -4098,7 +4099,7 @@
      ctx = createAdministrativeContext(uData.getHostName(), uData.getPort(),
          useSSL, useStartTLS,
          ADSContext.getAdministratorDN(uData.getAdminUid()),
          uData.getAdminPwd(), getTrustManager());
          uData.getAdminPwd(), getConnectTimeout(), getTrustManager());
    }
    catch (NamingException ne)
    {
@@ -4982,7 +4983,8 @@
        cnx.addAll(PreferredConnection.getPreferredConnections(ctx2));
        if (adsCtx1.hasAdminData())
        {
          TopologyCache cache = new TopologyCache(adsCtx1, getTrustManager());
          TopologyCache cache = new TopologyCache(adsCtx1, getTrustManager(),
              getConnectTimeout());
          cache.setPreferredConnections(cnx);
          cache.getFilter().setSearchMonitoringInformation(false);
          for (String dn : uData.getBaseDNs())
@@ -4995,7 +4997,8 @@
        if (adsCtx2.hasAdminData())
        {
          TopologyCache cache = new TopologyCache(adsCtx2, getTrustManager());
          TopologyCache cache = new TopologyCache(adsCtx2, getTrustManager(),
              getConnectTimeout());
          cache.setPreferredConnections(cnx);
          cache.getFilter().setSearchMonitoringInformation(false);
          for (String dn : uData.getBaseDNs())
@@ -5350,7 +5353,8 @@
      cnx.addAll(PreferredConnection.getPreferredConnections(ctx2));
      if (adsCtx1.hasAdminData())
      {
        cache1 = new TopologyCache(adsCtx1, getTrustManager());
        cache1 = new TopologyCache(adsCtx1, getTrustManager(),
            getConnectTimeout());
        cache1.setPreferredConnections(cnx);
        cache1.getFilter().setSearchMonitoringInformation(false);
        for (String dn : uData.getBaseDNs())
@@ -5363,7 +5367,8 @@
      if (adsCtx2.hasAdminData())
      {
        cache2 = new TopologyCache(adsCtx2, getTrustManager());
        cache2 = new TopologyCache(adsCtx2, getTrustManager(),
            getConnectTimeout());
        cache2.setPreferredConnections(cnx);
        cache2.getFilter().setSearchMonitoringInformation(false);
        for (String dn : uData.getBaseDNs())
@@ -5711,7 +5716,8 @@
    {
      if (adsCtx.hasAdminData() && tryToUpdateRemote)
      {
        cache = new TopologyCache(adsCtx, getTrustManager());
        cache = new TopologyCache(adsCtx, getTrustManager(),
            getConnectTimeout());
        cache.setPreferredConnections(
            PreferredConnection.getPreferredConnections(ctx));
        cache.getFilter().setSearchMonitoringInformation(false);
@@ -6238,7 +6244,8 @@
    TopologyCache cache = null;
    try
    {
      cache = new TopologyCache(adsCtx, getTrustManager());
      cache = new TopologyCache(adsCtx, getTrustManager(),
          getConnectTimeout());
      cache.setPreferredConnections(
          PreferredConnection.getPreferredConnections(ctx));
      for (String dn : uData.getBaseDNs())
@@ -8161,7 +8168,7 @@
    filter.setSearchMonitoringInformation(false);
    filter.setSearchBaseDNInformation(false);
    ServerLoader loader = new ServerLoader(server.getAdsProperties(), bindDn,
        pwd, getTrustManager(), cnx, filter);
        pwd, getTrustManager(), getConnectTimeout(), cnx, filter);
    InitialLdapContext ctx = null;
    String lastBaseDN = null;
    String hostPort = null;
@@ -9874,7 +9881,8 @@
        ADSContext adsContext = new ADSContext(ctx1);
        if (adsContext.hasAdminData())
        {
          cache1 = new TopologyCache(adsContext, getTrustManager());
          cache1 = new TopologyCache(adsContext, getTrustManager(),
              getConnectTimeout());
          cache1.getFilter().setSearchMonitoringInformation(false);
          cache1.setPreferredConnections(
              PreferredConnection.getPreferredConnections(ctx1));
@@ -9895,7 +9903,8 @@
        ADSContext adsContext = new ADSContext(ctx2);
        if (adsContext.hasAdminData())
        {
          cache2 = new TopologyCache(adsContext, getTrustManager());
          cache2 = new TopologyCache(adsContext, getTrustManager(),
              getConnectTimeout());
          cache2.getFilter().setSearchMonitoringInformation(false);
          cache2.setPreferredConnections(
              PreferredConnection.getPreferredConnections(ctx2));
@@ -10017,7 +10026,7 @@
      if (adsCtx1.hasAdminData())
      {
        TopologyCache cache = new TopologyCache(adsCtx1,
            getTrustManager());
            getTrustManager(), getConnectTimeout());
        cache.getFilter().setSearchMonitoringInformation(false);
        for (String dn : uData.getBaseDNs())
        {
@@ -10038,7 +10047,7 @@
      if (adsCtx2.hasAdminData())
      {
        TopologyCache cache = new TopologyCache(adsCtx2,
            getTrustManager());
            getTrustManager(), getConnectTimeout());
        cache.getFilter().setSearchMonitoringInformation(false);
        cache.reloadTopology();
        for (String dn : uData.getBaseDNs())
@@ -10131,7 +10140,8 @@
          adsCtx2.getDirContext()));
      // Check that there are no errors.  We do not allow to do the merge with
      // errors.
      TopologyCache cache1 = new TopologyCache(adsCtx1, getTrustManager());
      TopologyCache cache1 = new TopologyCache(adsCtx1, getTrustManager(),
          getConnectTimeout());
      cache1.setPreferredConnections(cnx);
      cache1.getFilter().setSearchBaseDNInformation(false);
      try
@@ -10146,7 +10156,8 @@
            ERR_REPLICATION_READING_ADS.get(te.getMessageObject()),
            ERROR_UPDATING_ADS, te);
      }
      TopologyCache cache2 = new TopologyCache(adsCtx2, getTrustManager());
      TopologyCache cache2 = new TopologyCache(adsCtx2, getTrustManager(),
          getConnectTimeout());
      cache2.setPreferredConnections(cnx);
      cache2.getFilter().setSearchBaseDNInformation(false);
      try
@@ -10456,8 +10467,8 @@
    filter.setSearchMonitoringInformation(false);
    filter.setSearchBaseDNInformation(false);
    ServerLoader loader = new ServerLoader(server.getAdsProperties(),
        dn, pwd, getTrustManager(), cache.getPreferredConnections(),
        filter);
        dn, pwd, getTrustManager(), getConnectTimeout(),
        cache.getPreferredConnections(), filter);
    return loader.createContext();
  }
@@ -10559,6 +10570,17 @@
    }
    return false;
  }
  /**
   * Returns the timeout to be used to connect in milliseconds.  The method
   * must be called after parsing the arguments.
   * @return the timeout to be used to connect in milliseconds.  Returns
   * {@code 0} if there is no timeout.
   */
  private int getConnectTimeout()
  {
    return argParser.getConnectTimeout();
  }
}
opends/src/server/org/opends/server/tools/status/StatusCli.java
@@ -318,6 +318,7 @@
    } else {
      ControlPanelInfo controlInfo = ControlPanelInfo.getInstance();
      controlInfo.setTrustManager(getTrustManager());
      controlInfo.setConnectTimeout(argParser.getConnectTimeout());
      controlInfo.regenerateDescriptor();
      boolean authProvided = false;
      if (controlInfo.getServerDescriptor().getStatus() ==
opends/src/server/org/opends/server/tools/tasks/TaskTool.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2007-2009 Sun Microsystems, Inc.
 *      Copyright 2007-2010 Sun Microsystems, Inc.
 */
package org.opends.server.tools.tasks;
@@ -62,7 +62,6 @@
import java.util.EnumSet;
import java.util.Collections;
import java.io.IOException;
import javax.net.ssl.SSLException;
/**
 * Base class for tools that are capable of operating either by running
@@ -203,7 +202,8 @@
        null, null, INFO_DESCRIPTION_TASK_DEPENDENCY_ID.get());
      argParser.addArgument(dependencyArg, taskGroup);
      Set fdaValSet = EnumSet.allOf(FailedDependencyAction.class);
      Set<FailedDependencyAction> fdaValSet =
        EnumSet.allOf(FailedDependencyAction.class);
      failedDependencyActionArg = new StringArgument(
        OPTION_LONG_FAILED_DEPENDENCY_ACTION,
        OPTION_SHORT_FAILED_DEPENDENCY_ACTION,
@@ -300,7 +300,8 @@
      String fda = failedDependencyActionArg.getValue();
      if (null == FailedDependencyAction.fromString(fda)) {
        Set fdaValSet = EnumSet.allOf(FailedDependencyAction.class);
        Set<FailedDependencyAction> fdaValSet =
          EnumSet.allOf(FailedDependencyAction.class);
        throw new ArgumentException(ERR_TASKTOOL_INVALID_FDA.get(fda,
                        StaticUtils.collectionToString(fdaValSet, ",")));
      }
@@ -501,8 +502,9 @@
        ret = 0;
      } catch (LDAPConnectionException e) {
        Message message = null;
        if ((e.getCause() != null) && (e.getCause().getCause() != null) &&
          e.getCause().getCause() instanceof SSLException) {
        if (isWrongPortException(e,
            new Integer(argParser.getArguments().getPort())))
        {
          message = ERR_TASK_LDAP_FAILED_TO_CONNECT_WRONG_PORT.get(
            argParser.getArguments().getHostName(),
            argParser.getArguments().getPort());
@@ -566,4 +568,31 @@
    }
    return returnValue;
  }
  /**
   * Returns {@code true} if the provided exception was caused by trying to
   * connect to the wrong port and {@code false} otherwise.
   * @param t the exception to be analyzed.
   * @param port the port to which we tried to connect.
   * @return {@code true} if the provided exception was caused by trying to
   * connect to the wrong port and {@code false} otherwise.
   */
  private boolean isWrongPortException(Throwable t, int port)
  {
    boolean isWrongPortException = false;
    boolean isDefaultClearPort = (port - 389) % 1000 == 0;
    while (t != null && isDefaultClearPort)
    {
      isWrongPortException = t instanceof java.net.SocketTimeoutException;
      if (!isWrongPortException)
      {
        t = t.getCause();
      }
      else
      {
        break;
      }
    }
    return isWrongPortException;
  }
}
opends/src/server/org/opends/server/util/args/ArgumentParser.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 */
package org.opends.server.util.args;
import org.opends.messages.Message;
@@ -1788,7 +1788,8 @@
              OPTION_LONG_REPORT_AUTHZ_ID.equals(longId) ||
              OPTION_LONG_USE_PW_POLICY_CTL.equals(longId) ||
              OPTION_LONG_USE_SASL_EXTERNAL.equals(longId) ||
              OPTION_LONG_PROTOCOL_VERSION.equals(longId);
              OPTION_LONG_PROTOCOL_VERSION.equals(longId) ||
              OPTION_LONG_CONNECT_TIMEOUT.equals(longId);
    }
    return ldap;
  }
opends/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 */
package org.opends.server.util.args;
@@ -330,12 +330,15 @@
        connectionOptions.addSASLProperty(option);
      }
    }
    int timeout = args.connectTimeoutArg.getIntValue();
    return connect(
            args.hostNameArg.getValue(),
            args.portArg.getIntValue(),
            args.bindDnArg.getValue(),
            getPasswordValue(args.bindPasswordArg, args.bindPasswordFileArg),
            connectionOptions, out, err);
            connectionOptions, timeout, out, err);
  }
  /**
@@ -364,7 +367,9 @@
              ui.getPortNumber(),
              ui.getBindDN(),
              ui.getBindPassword(),
              ui.populateLDAPOptions(options), out, err);
              ui.populateLDAPOptions(options),
              ui.getConnectTimeout(),
              out, err);
    } catch (OpenDsException e) {
      if ((e.getCause() != null) && (e.getCause().getCause() != null) &&
        e.getCause().getCause() instanceof SSLException) {
@@ -399,14 +404,41 @@
                                PrintStream err)
          throws LDAPConnectionException
  {
    return connect(host, port, bindDN, bindPw, options, 0, out, err);
  }
  /**
   * Creates a connection from information provided.
   *
   * @param host of the server
   * @param port of the server
   * @param bindDN with which to connect
   * @param bindPw with which to connect
   * @param options with which to connect
   * @param timeout the timeout to establish the connection in milliseconds.
   *        Use {@code 0} to express no timeout
   * @param out stream to write messages
   * @param err stream to write messages
   * @return LDAPConnection created by this class from parsed arguments
   * @throws LDAPConnectionException if there was a problem connecting
   *         to the server indicated by the input arguments
   */
  public LDAPConnection connect(String host, int port,
                                String bindDN, String bindPw,
                                LDAPConnectionOptions options,
                                int timeout,
                                PrintStream out,
                                PrintStream err)
  throws LDAPConnectionException
  {
    // Attempt to connect and authenticate to the Directory Server.
    AtomicInteger nextMessageID = new AtomicInteger(1);
    LDAPConnection connection = new LDAPConnection(
            host, port, options, out, err);
    connection.connectToHost(bindDN, bindPw, nextMessageID);
    connection.connectToHost(bindDN, bindPw, nextMessageID, timeout);
    return connection;
  }
opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
@@ -816,13 +816,14 @@
   * @param useStartTLS whether to use StartTLS or not.
   * @param bindDn the bind dn to be used.
   * @param pwd the password.
   * @param connectTimeout the timeout in milliseconds to connect to the server.
   * @param trustManager the trust manager.
   * @return an InitialLdapContext connected.
   * @throws NamingException if there was an error establishing the connection.
   */
  protected InitialLdapContext createAdministrativeContext(String host,
      int port, boolean useSSL, boolean useStartTLS, String bindDn, String pwd,
      ApplicationTrustManager trustManager)
      int connectTimeout, ApplicationTrustManager trustManager)
  throws NamingException
  {
    InitialLdapContext ctx;
@@ -830,18 +831,18 @@
    if (useSSL)
    {
      ctx = Utils.createLdapsContext(ldapUrl, bindDn, pwd,
          Utils.getDefaultLDAPTimeout(), null, trustManager);
          connectTimeout, null, trustManager);
    }
    else if (useStartTLS)
    {
      ctx = Utils.createStartTLSContext(ldapUrl, bindDn, pwd,
          Utils.getDefaultLDAPTimeout(), null, trustManager,
          connectTimeout, null, trustManager,
          null);
    }
    else
    {
      ctx = Utils.createLdapContext(ldapUrl, bindDn, pwd,
          Utils.getDefaultLDAPTimeout(), null);
          connectTimeout, null);
    }
    if (!ConnectionUtils.connectedAsAdministrativeUser(ctx))
    {
@@ -901,7 +902,7 @@
        try
        {
          ctx = ConnectionUtils.createLdapsContext(ldapsUrl, bindDN,
              bindPassword, ConnectionUtils.getDefaultLDAPTimeout(), null,
              bindPassword, ci.getConnectTimeout(), null,
              trustManager, keyManager);
          ctx.reconnect(null);
          break;
opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 */
package org.opends.server.util.cli;
@@ -116,6 +116,9 @@
  private String truststorePassword;
  // The timeout to be used to connect
  private int connectTimeout;
  private Message heading = INFO_LDAP_CONN_HEADING_CONNECTION_PARAMETERS.get();
  // A copy of the secureArgList for convenience.
@@ -796,6 +799,7 @@
          copySecureArgsList.bindPasswordArg);
      }
    }
    connectTimeout = secureArgsList.connectTimeoutArg.getIntValue();
  }
  /**
@@ -1456,6 +1460,15 @@
  }
  /**
   * Returns the timeout to be used to connect with the server.
   * @return the timeout to be used to connect with the server.
   */
  public int getConnectTimeout()
  {
    return connectTimeout;
  }
  /**
   * Indicate if the certificate chain can be trusted.
   *
   * @param chain The certificate chain to validate