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/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java | 3
opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java | 19
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java | 56 ++
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ControlPanel.java | 1
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java | 4
opendj-sdk/opends/src/server/org/opends/server/tools/tasks/TaskTool.java | 41 +
opendj-sdk/opends/src/ads/org/opends/admin/ads/TopologyCache.java | 25
opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java | 82 ++-
opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java | 15
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java | 18
opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java | 5
opendj-sdk/opends/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java | 40 +
opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java | 22
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/UserData.java | 22 +
opendj-sdk/opends/src/messages/messages/tools.properties | 3
opendj-sdk/opends/src/server/org/opends/server/tools/LDAPModify.java | 19
opendj-sdk/opends/src/server/org/opends/server/tools/LDAPCompare.java | 20
opendj-sdk/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java | 11
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java | 27 +
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java | 2
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java | 9
opendj-sdk/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java | 24 +
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Application.java | 5
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/ServerController.java | 4
opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java | 5
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ControlPanelArgumentParser.java | 54 +
opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/ui/LoginDialog.java | 15
opendj-sdk/opends/src/server/org/opends/server/tools/ToolConstants.java | 8
opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java | 15
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteEntryTask.java | 4
opendj-sdk/opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java | 33 +
opendj-sdk/opends/src/server/org/opends/server/tools/LDAPConnection.java | 30 +
/dev/null | 504 ----------------------
opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java | 17
opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java | 15
opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java | 1
opendj-sdk/opends/src/server/org/opends/server/tools/LDAPDelete.java | 18
opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ServerLoader.java | 13
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java | 26 +
opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java | 8
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java | 21
opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java | 33 +
opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java | 13
43 files changed, 661 insertions(+), 649 deletions(-)
diff --git a/opendj-sdk/opends/src/ads/org/opends/admin/ads/TopologyCache.java b/opendj-sdk/opends/src/ads/org/opends/admin/ads/TopologyCache.java
index 3dc2954..8d36d01 100644
--- a/opendj-sdk/opends/src/ads/org/opends/admin/ads/TopologyCache.java
+++ b/opendj-sdk/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;
diff --git a/opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java b/opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java
index 1290f9b..7dfe426 100644
--- a/opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java
+++ b/opendj-sdk/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.
*/
diff --git a/opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ServerLoader.java b/opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ServerLoader.java
index 7e108d3..d8aa18f 100644
--- a/opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ServerLoader.java
+++ b/opendj-sdk/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);
}
}
}
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ControlPanel.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ControlPanel.java
index bea1928..bf9a9a9 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ControlPanel.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ControlPanel.java
@@ -126,6 +126,7 @@
{
info.setTrustManager(new BlindApplicationTrustManager());
}
+ info.setConnectTimeout(argParser.getConnectTimeout());
}
/**
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ControlPanelArgumentParser.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ControlPanelArgumentParser.java
index adf08fd..ef04b1e 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ControlPanelArgumentParser.java
+++ b/opendj-sdk/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);
+ }
+ }
+
}
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java
index 70eaa3f..b6fba3a 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java
+++ b/opendj-sdk/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
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java
index 8c1b313..d1276bd 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java
+++ b/opendj-sdk/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.
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteEntryTask.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteEntryTask.java
index 50dc82d..775d164 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/task/DeleteEntryTask.java
+++ b/opendj-sdk/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)};
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
index 7f90e52..95ef96f 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
+++ b/opendj-sdk/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);
}
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
index 7654c1c..f67322f 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
+++ b/opendj-sdk/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);
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
index 503c6ae..26282cb 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
+++ b/opendj-sdk/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);
+ }
+ }
}
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
index b9c5ef6..17f049e 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
+++ b/opendj-sdk/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();
+ }
}
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
index 599f5d5..48482eb 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
+++ b/opendj-sdk/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);
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/ui/LoginDialog.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/ui/LoginDialog.java
index fd9a1a3..3e07e4c 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/ui/LoginDialog.java
+++ b/opendj-sdk/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)
diff --git a/opendj-sdk/opends/src/messages/messages/tools.properties b/opendj-sdk/opends/src/messages/messages/tools.properties
index a2e94f4..7139858 100644
--- a/opendj-sdk/opends/src/messages/messages/tools.properties
+++ b/opendj-sdk/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
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Application.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Application.java
index e36874e..baa273c 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Application.java
+++ b/opendj-sdk/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
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/UserData.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/UserData.java
index 2260c03..7cbbaa9 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/UserData.java
+++ b/opendj-sdk/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;
+ }
}
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
index e4f57d6..b898478 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
+++ b/opendj-sdk/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();
+ }
}
/**
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java
index 3102027..28c9d45 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java
+++ b/opendj-sdk/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())
{
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/DirectoryManagerAuthenticationDialog.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/DirectoryManagerAuthenticationDialog.java
deleted file mode 100644
index 1797336..0000000
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/DirectoryManagerAuthenticationDialog.java
+++ /dev/null
@@ -1,504 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2006-2010 Sun Microsystems, Inc.
- */
-
-package org.opends.quicksetup.ui;
-
-import java.awt.Dimension;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.io.IOException;
-
-import javax.naming.NamingException;
-import javax.naming.directory.SearchControls;
-import javax.naming.ldap.InitialLdapContext;
-import javax.swing.Box;
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JTextField;
-import javax.swing.text.JTextComponent;
-
-import org.opends.quicksetup.Installation;
-import org.opends.quicksetup.event.MinimumSizeComponentListener;
-
-import org.opends.quicksetup.util.BackgroundTask;
-import static org.opends.quicksetup.util.Utils.*;
-import static org.opends.quicksetup.ui.Utilities.*;
-import org.opends.messages.Message;
-import static org.opends.messages.QuickSetupMessages.*;
-
-
-/**
- * This class is a dialog that appears when the user must provide authentication
- * of Directory Manager to connect to the Directory Server in order to be
- * able to do a shutdown.
- */
-public class DirectoryManagerAuthenticationDialog extends JDialog
-{
- private static final Logger LOG =
- Logger.getLogger(
- DirectoryManagerAuthenticationDialog.class.getName());
-
- private static final long serialVersionUID = 9049409381101152000L;
-
- private JFrame parent;
-
- private JLabel lDn;
- private JLabel lPwd;
-
- private JTextField tfDn;
- private JTextField tfPwd;
-
- private JButton cancelButton;
- private JButton shutDownButton;
-
- private boolean isCancelled;
-
- private boolean isServerRunning;
-
- /**
- * Constructor of the DirectoryManagerAuthenticationDialog.
- * @param parent the parent frame for this dialog.
- * status.
- */
- public DirectoryManagerAuthenticationDialog(JFrame parent)
- {
- super(parent);
- setTitle(INFO_SHUTDOWN_DIRECTORY_MANAGER_DIALOG_TITLE.get().toString());
- this.parent = parent;
- getContentPane().add(createPanel());
- }
-
- /**
- * Returns <CODE>true</CODE> if the user clicked on cancel and
- * <CODE>false</CODE> otherwise.
- * @return <CODE>true</CODE> if the user clicked on cancel and
- * <CODE>false</CODE> otherwise.
- */
- public boolean isCancelled()
- {
- return isCancelled;
- }
-
- /**
- * Packs and displays this dialog.
- *
- */
- public void packAndShow()
- {
- /*
- * TODO: find a way to calculate this dynamically. This is done to avoid
- * all the text in a single line.
- */
- setPreferredSize(new Dimension(500, 300));
- addComponentListener(new MinimumSizeComponentListener(this,
- 500, 300));
- getRootPane().setDefaultButton(shutDownButton);
- pack();
- Utilities.centerOnComponent(this, parent);
- tfPwd.requestFocusInWindow();
- setVisible(true);
- }
-
- /**
- * Tells whether we must stop the server or not.
- * @return <CODE>true</CODE> if we must stop the server and <CODE>false</CODE>
- * otherwise
- */
- public boolean getStopServer()
- {
- return isServerRunning;
- }
-
- /**
- * Returns the Directory Manager DN provided by the user.
- * @return the Directory Manager DN provided by the user.
- */
- public String getDirectoryManagerDn()
- {
- return tfDn.getText();
- }
-
- /**
- * Returns the Directory Manager password provided by the user.
- * @return the Directory Manager password provided by the user.
- */
- public String getDirectoryManagerPwd()
- {
- return tfPwd.getText();
- }
-
- /**
- * Creates and returns the panel of the dialog.
- * @return the panel of the dialog.
- */
- private JPanel createPanel()
- {
- JPanel p1 = new JPanel(new GridBagLayout());
- p1.setBackground(UIFactory.CURRENT_STEP_PANEL_BACKGROUND);
- p1.setBorder(UIFactory.DIALOG_PANEL_BORDER);
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.gridwidth = GridBagConstraints.RELATIVE;
- gbc.anchor = GridBagConstraints.NORTHWEST;
- gbc.insets = UIFactory.getCurrentStepPanelInsets();
- p1.add(UIFactory.makeJLabel(UIFactory.IconType.INFORMATION_LARGE, null,
- UIFactory.TextStyle.NO_STYLE), gbc);
- gbc.weightx = 1.0;
- gbc.fill = GridBagConstraints.BOTH;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gbc.insets.left = 0;
- Message msg = INFO_SHUTDOWN_DIRECTORY_MANAGER_DIALOG_MSG.get();
- JTextComponent textPane =
- UIFactory.makeHtmlPane(msg, UIFactory.INSTRUCTIONS_FONT);
- textPane.setOpaque(false);
- textPane.setEditable(false);
- p1.add(textPane, gbc);
-
- JPanel p2 = new JPanel(new GridBagLayout());
- p2.setOpaque(false);
- gbc.gridwidth = GridBagConstraints.RELATIVE;
- gbc.weightx = 0.0;
- gbc.insets.top = UIFactory.TOP_INSET_PRIMARY_FIELD;
- gbc.insets.left = 0;
- gbc.anchor = GridBagConstraints.WEST;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- lDn = UIFactory.makeJLabel(UIFactory.IconType.NO_ICON,
- INFO_SHUTDOWN_DIRECTORY_MANAGER_DN_LABEL.get(),
- UIFactory.TextStyle.PRIMARY_FIELD_VALID);
- p2.add(lDn, gbc);
- gbc.weightx = 1.0;
- gbc.insets.left = UIFactory.LEFT_INSET_PRIMARY_FIELD;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- tfDn = UIFactory.makeJTextField(
- Message.raw(getProposedDirectoryManagerDn()),
- INFO_SHUTDOWN_DIRECTORY_MANAGER_DN_TOOLTIP.get(),
- UIFactory.DN_FIELD_SIZE, UIFactory.TextStyle.TEXTFIELD);
- p2.add(tfDn, gbc);
-
- gbc.insets.top = 0;
- gbc.gridwidth = GridBagConstraints.RELATIVE;
- gbc.weightx = 0.0;
- gbc.insets.left = 0;
- lPwd = UIFactory.makeJLabel(UIFactory.IconType.NO_ICON,
- INFO_SHUTDOWN_DIRECTORY_MANAGER_PWD_LABEL.get(),
- UIFactory.TextStyle.PRIMARY_FIELD_VALID);
- p2.add(lPwd, gbc);
- gbc.weightx = 1.0;
- gbc.insets.left = UIFactory.LEFT_INSET_PRIMARY_FIELD;
- gbc.fill = GridBagConstraints.NONE;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- JPanel p3 = new JPanel(new GridBagLayout());
- p3.setOpaque(false);
- tfPwd = UIFactory.makeJPasswordField(null,
- INFO_SHUTDOWN_DIRECTORY_MANAGER_PWD_TOOLTIP.get(),
- UIFactory.PASSWORD_FIELD_SIZE, UIFactory.TextStyle.PASSWORD_FIELD);
- p2.add(tfPwd, gbc);
- p2.add(p3, gbc);
- gbc.insets = UIFactory.getEmptyInsets();
- gbc.gridwidth = GridBagConstraints.RELATIVE;
- gbc.weightx = 0.0;
- p3.add(tfPwd, gbc);
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gbc.weightx = 1.0;
- p3.add(Box.createHorizontalGlue(), gbc);
-
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.insets = UIFactory.getEmptyInsets();
- gbc.gridwidth = GridBagConstraints.RELATIVE;
- gbc.weightx = 0.0;
- gbc.insets.top = 0;
- p1.add(Box.createHorizontalGlue(), gbc);
- gbc.weightx = 1.0;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- p1.add(p2, gbc);
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.VERTICAL;
- p1.add(Box.createVerticalGlue(), gbc);
-
- JPanel buttonPanel = new JPanel(new GridBagLayout());
- buttonPanel.setOpaque(false);
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.weightx = 1.0;
- gbc.insets = UIFactory.getEmptyInsets();
- gbc.gridwidth = 3;
- buttonPanel.add(Box.createHorizontalGlue(), gbc);
- gbc.gridwidth = GridBagConstraints.RELATIVE;
- gbc.fill = GridBagConstraints.NONE;
- gbc.weightx = 0.0;
- shutDownButton =
- UIFactory.makeJButton(INFO_SHUTDOWN_BUTTON_LABEL.get(),
- INFO_SHUTDOWN_DIRECTORY_MANAGER_SHUTDOWN_BUTTON_TOOLTIP.get());
- buttonPanel.add(shutDownButton, gbc);
- shutDownButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent ev)
- {
- shutDownClicked();
- }
- });
-
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gbc.insets.left = UIFactory.HORIZONTAL_INSET_BETWEEN_BUTTONS;
- cancelButton =
- UIFactory.makeJButton(INFO_CANCEL_BUTTON_LABEL.get(),
- INFO_SHUTDOWN_DIRECTORY_MANAGER_CANCEL_BUTTON_TOOLTIP.get());
- buttonPanel.add(cancelButton, gbc);
- cancelButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent ev)
- {
- cancelClicked();
- }
- });
-
- JPanel p = new JPanel(new GridBagLayout());
- p.setBackground(UIFactory.DEFAULT_BACKGROUND);
- gbc.insets = UIFactory.getEmptyInsets();
- gbc.fill = GridBagConstraints.BOTH;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- p.add(p1, gbc);
- gbc.weighty = 0.0;
- gbc.insets = UIFactory.getButtonsPanelInsets();
- p.add(buttonPanel, gbc);
-
- return p;
- }
-
- private String getProposedDirectoryManagerDn()
- {
- String dn;
- Set<String> dns = null;
- try {
- dns = Installation.getLocal().getCurrentConfiguration().
- getDirectoryManagerDns();
- } catch (IOException ioe) {
- LOG.log(Level.INFO, "error obtaining dirmanager DNs", ioe);
- }
- if (dns != null && dns.size() > 0)
- {
- dn = dns.iterator().next();
- }
- else
- {
- dn = null;
- }
- return dn;
- }
-
- private void cancelClicked()
- {
- isCancelled = true;
- dispose();
- }
-
- private void shutDownClicked()
- {
- isCancelled = false;
- BackgroundTask<Boolean> worker = new BackgroundTask<Boolean>()
- {
- public Boolean processBackgroundTask() throws NamingException
- {
- Boolean isServerRunning = Boolean.TRUE;
- try
- {
- Installation installation = Installation.getLocal();
- int port = installation.getCurrentConfiguration().getPort();
- String ldapUrl = "ldap://localhost:"+port;
- InitialLdapContext ctx =
- createLdapContext(ldapUrl, tfDn.getText(),
- tfPwd.getText(), getDefaultLDAPTimeout(), null);
-
- /*
- * Search for the config to check that it is the directory manager.
- */
- SearchControls searchControls = new SearchControls();
- searchControls.setCountLimit(1);
- searchControls.setSearchScope(
- SearchControls. OBJECT_SCOPE);
- searchControls.setReturningAttributes(
- new String[] {"1.1"});
- ctx.search("cn=config", "objectclass=*", searchControls);
-
- } catch (NamingException ne)
- {
- if (Installation.getLocal().getStatus().isServerRunning())
- {
- throw ne;
- }
- isServerRunning = Boolean.FALSE;
- } catch (Throwable t)
- {
- throw new IllegalStateException("Unexpected throwable.", t);
- }
- return isServerRunning;
- }
-
- public void backgroundTaskCompleted(Boolean returnValue,
- Throwable throwable)
- {
- if (throwable != null)
- {
- if (throwable instanceof NamingException)
- {
- boolean dnInvalid = false;
- boolean pwdInvalid = false;
-
- String dn = tfDn.getText();
- ArrayList<Message> possibleCauses = new ArrayList<Message>();
- if ("".equals(dn.trim()))
- {
- dnInvalid = true;
- possibleCauses.add(INFO_EMPTY_DIRECTORY_MANAGER_DN.get());
- }
- else if (!isDn(dn))
- {
- dnInvalid = true;
- possibleCauses.add(INFO_NOT_A_DIRECTORY_MANAGER_DN.get());
- }
- else
- {
- boolean found = false;
- try {
- Set<String> dns;
- dns = Installation.getLocal().getCurrentConfiguration()
- .getDirectoryManagerDns();
- Iterator<String> it = dns.iterator();
- while (it.hasNext() && !found)
- {
- found = areDnsEqual(dn, it.next());
- }
- } catch (IOException ioe) {
- LOG.log(Level.INFO, "error obtaining dirmanager DNs", ioe);
- }
- if (!found)
- {
- dnInvalid = true;
- possibleCauses.add(
- INFO_NOT_A_DIRECTORY_MANAGER_IN_CONFIG.get());
- }
- }
-
- if ("".equals(tfPwd.getText()))
- {
- pwdInvalid = true;
- possibleCauses.add(INFO_EMPTY_PWD.get());
- }
-
- if (dnInvalid)
- {
- UIFactory.setTextStyle(lDn,
- UIFactory.TextStyle.PRIMARY_FIELD_INVALID);
- }
- else
- {
- UIFactory.setTextStyle(lDn,
- UIFactory.TextStyle.PRIMARY_FIELD_VALID);
- pwdInvalid = true;
- }
- if (pwdInvalid)
- {
- UIFactory.setTextStyle(lPwd,
- UIFactory.TextStyle.PRIMARY_FIELD_INVALID);
- }
- else
- {
- UIFactory.setTextStyle(lPwd,
- UIFactory.TextStyle.PRIMARY_FIELD_VALID);
- }
-
- if (possibleCauses.size() > 0)
- {
- displayError(parent,
- INFO_CANNOT_CONNECT_TO_SHUTDOWN_WITH_CAUSE.get(
- getMessageFromCollection(possibleCauses, "\n")),
- INFO_ERROR_TITLE.get());
- }
- else
- {
- // Generic message
- displayError(parent,
- INFO_CANNOT_CONNECT_TO_SHUTDOWN_WITHOUT_CAUSE.get(),
- INFO_ERROR_TITLE.get());
- }
- }
- else
- {
- // This is a bug
- throwable.printStackTrace();
- displayError(parent,
- getThrowableMsg(INFO_BUG_MSG.get(), throwable),
- INFO_ERROR_TITLE.get());
- }
- cancelButton.setEnabled(true);
- shutDownButton.setEnabled(true);
- } else
- {
- isServerRunning = Boolean.TRUE.equals(returnValue);
- if (!isServerRunning)
- {
- displayInformationMessage(parent, INFO_SERVER_NOT_RUNNING_MSG.get(),
- INFO_SERVER_NOT_RUNNING_TITLE.get());
- }
- isCancelled = false;
- dispose();
- }
- }
- };
- cancelButton.setEnabled(false);
- shutDownButton.setEnabled(false);
- worker.startBackgroundTask();
- }
-
- /**
- * Method written for testing purposes.
- * @param args the arguments to be passed to the test program.
- */
- public static void main(String[] args)
- {
- try
- {
- // UIFactory.initialize();
- DirectoryManagerAuthenticationDialog dlg =
- new DirectoryManagerAuthenticationDialog(new JFrame());
- dlg.packAndShow();
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
-}
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java
index dd387a1..518caf7 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java
+++ b/opendj-sdk/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;
+ }
}
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java
index ae97416..0b87aba 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java
+++ b/opendj-sdk/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();
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/ServerController.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/ServerController.java
index b2c737a..a791ec0 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/ServerController.java
+++ b/opendj-sdk/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;
}
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
index 0e48c73..5911286 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
+++ b/opendj-sdk/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
diff --git a/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java b/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
index f3e68a9..60f3a0c 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
+++ b/opendj-sdk/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;
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java b/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
index 9765e3b..9a80e34 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
+++ b/opendj-sdk/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);
+ }
+ }
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java b/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java
index 0a96b1b..454b892 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDS.java
+++ b/opendj-sdk/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();
+ }
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java b/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java
index 3cf450b..900d30b 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java
+++ b/opendj-sdk/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);
+ }
+ }
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPCompare.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPCompare.java
index 414dc90..7fc1d41 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPCompare.java
+++ b/opendj-sdk/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);
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPConnection.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPConnection.java
index d3fd72d..5703deb 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPConnection.java
+++ b/opendj-sdk/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())
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPDelete.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPDelete.java
index 0a070f8..66545f2 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPDelete.java
+++ b/opendj-sdk/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())
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);
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java
index da82045..700c971 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java
+++ b/opendj-sdk/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();
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java
index 13b131a..7b8dcdd 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java
+++ b/opendj-sdk/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())
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/ToolConstants.java b/opendj-sdk/opends/src/server/org/opends/server/tools/ToolConstants.java
index 10323cd..e60b940 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/ToolConstants.java
+++ b/opendj-sdk/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';
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
index d4be8b2..bd1164d 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
+++ b/opendj-sdk/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);
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
index b38c1fb..9f3b6bf 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
+++ b/opendj-sdk/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();
+ }
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java b/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java
index 2a494de..0c28efb 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java
+++ b/opendj-sdk/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() ==
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/tasks/TaskTool.java b/opendj-sdk/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
index 86de53a..59b5679 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
+++ b/opendj-sdk/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;
+ }
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java b/opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java
index 15d67ca..a202617 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java
+++ b/opendj-sdk/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;
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java b/opendj-sdk/opends/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java
index 7590cec..494bd20 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java
+++ b/opendj-sdk/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;
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java b/opendj-sdk/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
index 8971d24..9042e3f 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
+++ b/opendj-sdk/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;
diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java b/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
index 665cbaa..f266ad8 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
+++ b/opendj-sdk/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
--
Gitblit v1.10.0