From 97f7d39cf58d120fc84c99c20bdb36ae35476ab3 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 04 Apr 2016 13:38:35 +0000
Subject: [PATCH] Use HostPort throughout
---
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java | 13
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java | 30 -
opendj-server-legacy/src/main/java/org/opends/quicksetup/UserData.java | 23 +
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/DataReplicationPanel.java | 6
opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java | 6
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java | 7
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/Task.java | 7
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionUtils.java | 141 +++-------
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java | 10
opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java | 24 -
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/EnableReplicationUserData.java | 54 ++--
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java | 142 ++++------
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/PurgeHistoricalUserData.java | 7
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java | 28 -
opendj-server-legacy/src/main/java/org/opends/server/types/HostPort.java | 29 --
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/AuthenticationData.java | 37 +-
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java | 77 +----
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java | 20
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/MonoServerReplicationUserData.java | 47 +--
opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java | 2
opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java | 3
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/InstallReviewPanel.java | 20
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/RemoteReplicationPortsPanel.java | 26 -
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java | 7
24 files changed, 297 insertions(+), 469 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
index e34ec18..71232a4 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
@@ -1413,7 +1413,7 @@
catch (ADSContextException ace)
{
ServerDescriptor s = ServerDescriptor.createStandalone(serverProperties);
- return makeDNFromServerUniqueId(s.getHostPort(true));
+ return makeDNFromServerUniqueId(s.getHostPort(true).toString());
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java
index 9f5d841..943718d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ServerDescriptor.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2007-2010 Sun Microsystems, Inc.
- * Portions Copyright 2013-2015 ForgeRock AS.
+ * Portions Copyright 2013-2016 ForgeRock AS.
*/
package org.opends.admin.ads;
@@ -47,6 +47,7 @@
import org.opends.quicksetup.Constants;
import org.opends.server.config.ConfigConstants;
import org.opends.server.schema.SchemaConstants;
+import org.opends.server.types.HostPort;
/** The object of this class represent an OpenDS server. */
public class ServerDescriptor
@@ -352,7 +353,7 @@
* of the returning String or not.
* @return a String of type host-name:port-number for the server.
*/
- public String getHostPort(boolean securePreferred)
+ public HostPort getHostPort(boolean securePreferred)
{
int port = -1;
@@ -409,9 +410,7 @@
}
}
}
-
- String host = getHostName();
- return host + ":" + port;
+ return new HostPort(getHostName(), port);
}
private ADSContext.ServerProperty getPortProperty(ADSContext.ServerProperty prop)
@@ -1402,20 +1401,7 @@
*/
public static String getReplicationServer(String hostName, int replicationPort)
{
- return getServerRepresentation(hostName, replicationPort);
- }
-
- /**
- * Returns the normalized server representation for a given host name and
- * port.
- * @param hostName the host name.
- * @param port the port.
- * @return the normalized server representation for a given host name and
- * port.
- */
- public static String getServerRepresentation(String hostName, int port)
- {
- return hostName.toLowerCase() + ":" + port;
+ return new HostPort(hostName, replicationPort).toString();
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionUtils.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionUtils.java
index 6477a39..952be21 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionUtils.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionUtils.java
@@ -12,9 +12,8 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2008-2010 Sun Microsystems, Inc.
- * Portions Copyright 2012-2015 ForgeRock AS.
+ * Portions Copyright 2012-2016 ForgeRock AS.
*/
-
package org.opends.admin.ads.util;
import java.io.IOException;
@@ -44,6 +43,7 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.replication.plugin.EntryHistorical;
import org.opends.server.schema.SchemaConstants;
+import org.opends.server.types.HostPort;
import com.forgerock.opendj.cli.Utils;
@@ -383,18 +383,7 @@
*/
public static String getLdapUrl(InitialLdapContext ctx)
{
- String s = null;
- try
- {
- s = (String)ctx.getEnvironment().get(Context.PROVIDER_URL);
- }
- catch (NamingException ne)
- {
- // This is really strange. Seems like a bug somewhere.
- logger.warn(LocalizableMessage.raw("Naming exception getting environment of "+ctx,
- ne));
- }
- return s;
+ return getEnvProperty(ctx, Context.PROVIDER_URL);
}
/**
@@ -404,18 +393,8 @@
*/
public static String getHostName(InitialLdapContext ctx)
{
- String s = null;
- try
- {
- URI ldapURL = new URI(getLdapUrl(ctx));
- s = ldapURL.getHost();
- }
- catch (Throwable t)
- {
- // This is really strange. Seems like a bug somewhere.
- logger.warn(LocalizableMessage.raw("Error getting host: "+t, t));
- }
- return s;
+ HostPort hp = getHostPort(ctx);
+ return hp != null ? hp.getHost() : null;
}
/**
@@ -425,18 +404,8 @@
*/
public static int getPort(InitialLdapContext ctx)
{
- int port = -1;
- try
- {
- URI ldapURL = new URI(getLdapUrl(ctx));
- port = ldapURL.getPort();
- }
- catch (Throwable t)
- {
- // This is really strange. Seems like a bug somewhere.
- logger.warn(LocalizableMessage.raw("Error getting port: "+t, t));
- }
- return port;
+ HostPort hp = getHostPort(ctx);
+ return hp != null ? hp.getPort() : -1;
}
/**
@@ -446,9 +415,19 @@
* @return the host port representation of the server to which this
* context is connected.
*/
- public static String getHostPort(InitialLdapContext ctx)
+ public static HostPort getHostPort(InitialLdapContext ctx)
{
- return getHostName(ctx)+":"+getPort(ctx);
+ try
+ {
+ URI ldapURL = new URI(getLdapUrl(ctx));
+ return new HostPort(ldapURL.getHost(), ldapURL.getPort());
+ }
+ catch (Throwable t)
+ {
+ // This is really strange. Seems like a bug somewhere.
+ logger.warn(LocalizableMessage.raw("Error getting host: "+t, t));
+ return null;
+ }
}
/**
@@ -458,18 +437,7 @@
*/
public static String getBindDN(InitialLdapContext ctx)
{
- String bindDN = null;
- try
- {
- bindDN = (String)ctx.getEnvironment().get(Context.SECURITY_PRINCIPAL);
- }
- catch (NamingException ne)
- {
- // This is really strange. Seems like a bug somewhere.
- logger.warn(LocalizableMessage.raw("Naming exception getting environment of "+ctx,
- ne));
- }
- return bindDN;
+ return getEnvProperty(ctx, Context.SECURITY_PRINCIPAL);
}
/**
@@ -479,18 +447,17 @@
*/
public static String getBindPassword(InitialLdapContext ctx)
{
- String bindPwd = null;
- try
- {
- bindPwd = (String)ctx.getEnvironment().get(Context.SECURITY_CREDENTIALS);
- }
- catch (NamingException ne)
- {
+ return getEnvProperty(ctx, Context.SECURITY_CREDENTIALS);
+ }
+
+ private static String getEnvProperty(InitialLdapContext ctx, String property) {
+ try {
+ return (String) ctx.getEnvironment().get(property);
+ } catch (NamingException ne) {
// This is really strange. Seems like a bug somewhere.
- logger.warn(LocalizableMessage.raw("Naming exception getting environment of "+ctx,
- ne));
+ logger.warn(LocalizableMessage.raw("Naming exception getting environment of " + ctx, ne));
+ return null;
}
- return bindPwd;
}
/**
@@ -501,17 +468,16 @@
*/
public static boolean isSSL(InitialLdapContext ctx)
{
- boolean isSSL = false;
try
{
- isSSL = getLdapUrl(ctx).toLowerCase().startsWith("ldaps");
+ return getLdapUrl(ctx).toLowerCase().startsWith("ldaps");
}
catch (Throwable t)
{
// This is really strange. Seems like a bug somewhere.
logger.warn(LocalizableMessage.raw("Error getting if is SSL "+t, t));
+ return false;
}
- return isSSL;
}
/**
@@ -522,19 +488,7 @@
*/
public static boolean isStartTLS(InitialLdapContext ctx)
{
- boolean isStartTLS = false;
- try
- {
- isStartTLS = "true".equalsIgnoreCase((String)ctx.getEnvironment().get(
- STARTTLS_PROPERTY));
- }
- catch (NamingException ne)
- {
- // This is really strange. Seems like a bug somewhere.
- logger.warn(LocalizableMessage.raw("Naming exception getting environment of "+ctx,
- ne));
- }
- return isStartTLS;
+ return "true".equalsIgnoreCase(getEnvProperty(ctx, STARTTLS_PROPERTY));
}
/**
@@ -551,7 +505,6 @@
public static boolean canConnectAsAdministrativeUser(String ldapUrl,
String dn, String pwd, int timeout)
{
- boolean canConnectAsAdministrativeUser = false;
try
{
InitialLdapContext ctx;
@@ -566,15 +519,15 @@
null, null, null);
}
- canConnectAsAdministrativeUser = connectedAsAdministrativeUser(ctx);
+ return connectedAsAdministrativeUser(ctx);
} catch (NamingException ne)
{
// Nothing to do.
+ return false;
} catch (Throwable t)
{
throw new IllegalStateException("Unexpected throwable.", t);
}
- return canConnectAsAdministrativeUser;
}
/**
@@ -586,12 +539,9 @@
*/
public static boolean connectedAsAdministrativeUser(InitialLdapContext ctx)
{
- boolean connectedAsAdministrativeUser = false;
try
{
- /*
- * Search for the config to check that it is the directory manager.
- */
+ // Search for the config to check that it is the directory manager.
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(
SearchControls. OBJECT_SCOPE);
@@ -618,15 +568,15 @@
"Unexpected error closing enumeration on cn=Config entry", ex));
}
}
- connectedAsAdministrativeUser = true;
+ return true;
} catch (NamingException ne)
{
// Nothing to do.
+ return false;
} catch (Throwable t)
{
throw new IllegalStateException("Unexpected throwable.", t);
}
- return connectedAsAdministrativeUser;
}
/**
@@ -682,10 +632,8 @@
if (throwException)
{
- NamingException xx;
- ConnectException x = new ConnectException("Connection timed out");
- xx = new CommunicationException("Connection timed out");
- xx.initCause(x);
+ NamingException xx = new CommunicationException("Connection timed out");
+ xx.initCause(new ConnectException("Connection timed out"));
throw xx;
}
@@ -710,6 +658,17 @@
/**
* Returns the LDAP URL for the provided parameters.
+ * @param hostPort the host name and LDAP port.
+ * @param useSSL whether to use SSL or not.
+ * @return the LDAP URL for the provided parameters.
+ */
+ public static String getLDAPUrl(HostPort hostPort, boolean useSSL)
+ {
+ return getLDAPUrl(hostPort.getHost(), hostPort.getPort(), useSSL);
+ }
+
+ /**
+ * Returns the LDAP URL for the provided parameters.
* @param host the host name.
* @param port the LDAP port.
* @param useSSL whether to use SSL or not.
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
index 8816c03..14407f8 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
@@ -21,8 +21,7 @@
import static org.forgerock.opendj.ldap.LDAPConnectionFactory.SSL_USE_STARTTLS;
import static org.opends.admin.ads.util.ConnectionUtils.getBindDN;
import static org.opends.admin.ads.util.ConnectionUtils.getBindPassword;
-import static org.opends.admin.ads.util.ConnectionUtils.getHostName;
-import static org.opends.admin.ads.util.ConnectionUtils.getPort;
+import static org.opends.admin.ads.util.ConnectionUtils.getHostPort;
import static org.opends.admin.ads.util.ConnectionUtils.isSSL;
import static org.opends.admin.ads.util.ConnectionUtils.isStartTLS;
@@ -46,6 +45,7 @@
import org.forgerock.opendj.server.config.client.RootCfgClient;
import org.forgerock.util.Options;
import org.forgerock.util.time.Duration;
+import org.opends.server.types.HostPort;
import org.opends.server.util.StaticUtils;
/**
@@ -87,7 +87,8 @@
options.set(SSL_CONTEXT, getSSLContext(trustManager)).set(SSL_USE_STARTTLS, isStartTLS(ctx));
}
options.set(AUTHN_BIND_REQUEST, Requests.newSimpleBindRequest(getBindDN(ctx), getBindPassword(ctx).toCharArray()));
- connectionFactory = new LDAPConnectionFactory(getHostName(ctx), getPort(ctx), options);
+ HostPort hostPort = getHostPort(ctx);
+ connectionFactory = new LDAPConnectionFactory(hostPort.getHost(), hostPort.getPort(), options);
try
{
connection = connectionFactory.getConnection();
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
index 0042905..7fcdc5e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2008-2010 Sun Microsystems, Inc.
- * Portions Copyright 2014-2015 ForgeRock AS.
+ * Portions Copyright 2014-2016 ForgeRock AS.
*/
package org.opends.guitools.controlpanel.browser;
@@ -62,8 +62,10 @@
import org.opends.guitools.controlpanel.util.NumSubordinateHacker;
import org.opends.guitools.controlpanel.util.Utilities;
import org.opends.server.config.ConfigConstants;
+import org.opends.server.types.HostPort;
import org.opends.server.types.LDAPURL;
+import static org.opends.admin.ads.util.ConnectionUtils.getPort;
import static org.opends.server.util.ServerConstants.*;
/**
@@ -195,11 +197,9 @@
this.ctxConfiguration = ctxConfiguration;
this.ctxUserData = ctxUserData;
- this.ctxConfiguration.setRequestControls(
- getConfigurationRequestControls());
+ this.ctxConfiguration.setRequestControls(getConfigurationRequestControls());
this.ctxUserData.setRequestControls(getRequestControls());
- rootNodeName = server.getHostname() + ":" +
- ConnectionUtils.getPort(ctxConfiguration);
+ rootNodeName = new HostPort(server.getHostname(), getPort(ctxConfiguration)).toString();
}
else {
rootNodeName = "";
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java
index aa2c966..1e988e7 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java
@@ -28,6 +28,7 @@
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.guitools.controlpanel.event.ReferralAuthenticationListener;
import org.forgerock.opendj.ldap.DN;
+import org.opends.server.types.HostPort;
import org.opends.server.types.LDAPURL;
import org.forgerock.opendj.ldap.SearchScope;
@@ -84,9 +85,10 @@
for (String key : connectionTable.keySet())
{
ConnectionRecord cr = connectionTable.get(key);
+ HostPort hostPort = getHostPort(ctx);
+ HostPort crHostPort = getHostPort(cr.ctx);
if (cr.ctx != null
- && getHostName(cr.ctx).equals(getHostName(ctx))
- && getPort(cr.ctx) == getPort(ctx)
+ && hostPort.equals(crHostPort)
&& getBindDN(cr.ctx).equals(getBindDN(ctx))
&& getBindPassword(cr.ctx).equals(getBindPassword(ctx))
&& isSSL(cr.ctx) == isSSL(ctx)
@@ -389,7 +391,7 @@
*/
private static String makeKeyFromRecord(ConnectionRecord rec) {
String protocol = ConnectionUtils.isSSL(rec.ctx) ? "LDAPS" : "LDAP";
- return protocol + ":" + getHostName(rec.ctx) + ":" + getPort(rec.ctx);
+ return protocol + ":" + getHostPort(rec.ctx);
}
/**
@@ -476,18 +478,9 @@
}
private LDAPURL makeLDAPUrl(InitialLdapContext ctx) {
- return new LDAPURL(
- isSSL(ctx) ? "ldaps" : LDAPURL.DEFAULT_SCHEME,
- getHostName(ctx),
- getPort(ctx),
- "",
- null, // no attributes
- SearchScope.BASE_OBJECT,
- null, // No filter
- null); // No extensions
+ return makeLDAPUrl(ctx, "");
}
-
/**
* Make an url from the specified arguments.
* @param ctx the connection to the server.
@@ -495,15 +488,16 @@
* @return an LDAP URL from the specified arguments.
*/
public static LDAPURL makeLDAPUrl(InitialLdapContext ctx, String dn) {
+ HostPort hostPort = ConnectionUtils.getHostPort(ctx);
return new LDAPURL(
- ConnectionUtils.isSSL(ctx) ? "ldaps" : LDAPURL.DEFAULT_SCHEME,
- ConnectionUtils.getHostName(ctx),
- ConnectionUtils.getPort(ctx),
+ isSSL(ctx) ? "ldaps" : LDAPURL.DEFAULT_SCHEME,
+ hostPort.getHost(),
+ hostPort.getPort(),
dn,
null, // No attributes
SearchScope.BASE_OBJECT,
- null,
- null); // No filter
+ null, // No filter
+ null); // No extensions
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java
index 42c6623..7d708dc 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java
@@ -16,6 +16,8 @@
*/
package org.opends.guitools.controlpanel.browser;
+import static org.opends.admin.ads.util.ConnectionUtils.getHostPort;
+import static org.opends.admin.ads.util.ConnectionUtils.isSSL;
import static org.opends.messages.AdminToolMessages.*;
import java.util.ArrayList;
@@ -42,6 +44,7 @@
import org.opends.messages.AdminToolMessages;
import org.opends.server.schema.SchemaConstants;
import org.opends.server.types.DirectoryException;
+import org.opends.server.types.HostPort;
import org.opends.server.types.LDAPURL;
import org.opends.server.types.OpenDsException;
@@ -486,9 +489,10 @@
{
// Use the local server connection.
ctx = controller.getUserDataConnection();
- url.setHost(ConnectionUtils.getHostName(ctx));
- url.setPort(ConnectionUtils.getPort(ctx));
- url.setScheme(ConnectionUtils.isSSL(ctx)?"ldaps":"ldap");
+ HostPort hostPort = getHostPort(ctx);
+ url.setHost(hostPort.getHost());
+ url.setPort(hostPort.getPort());
+ url.setScheme(isSSL(ctx) ? "ldaps" : "ldap");
}
ctx = connectionPool.getConnection(url);
remoteDn = url.getRawBaseDN();
@@ -1120,23 +1124,11 @@
DN dn2 = url.getBaseDN();
if (dn2.isSuperiorOrEqualTo(dn1))
{
- String host = url.getHost();
- int port = url.getPort();
- String adminHost = ConnectionUtils.getHostName(
- controller.getConfigurationConnection());
- int adminPort =
- ConnectionUtils.getPort(controller.getConfigurationConnection());
- checkSucceeded = port != adminPort ||
- !adminHost.equalsIgnoreCase(host);
-
+ HostPort urlHostPort = new HostPort(url.getHost(), url.getPort());
+ checkSucceeded = urlHostPort.equals(getHostPort(controller.getConfigurationConnection()));
if (checkSucceeded)
{
- String hostUserData = ConnectionUtils.getHostName(
- controller.getUserDataConnection());
- int portUserData =
- ConnectionUtils.getPort(controller.getUserDataConnection());
- checkSucceeded = port != portUserData ||
- !hostUserData.equalsIgnoreCase(host);
+ checkSucceeded = urlHostPort.equals(getHostPort(controller.getUserDataConnection()));
}
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/Task.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/Task.java
index d5df37e..d2e7a4f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/Task.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/Task.java
@@ -52,6 +52,7 @@
import org.opends.quicksetup.Installation;
import org.opends.quicksetup.UserData;
import org.forgerock.opendj.ldap.DN;
+import org.opends.server.types.HostPort;
import org.opends.server.types.Schema;
import org.opends.server.util.Base64;
import org.opends.server.util.SetupUtils;
@@ -766,12 +767,12 @@
}
if (isServerRunning() && ctx != null)
{
+ HostPort hostPort = ConnectionUtils.getHostPort(ctx);
String hostName = localHostName;
if (hostName == null || !getInfo().getServerDescriptor().isLocal())
{
- hostName = ConnectionUtils.getHostName(ctx);
+ hostName = hostPort.getHost();
}
- int port = ConnectionUtils.getPort(ctx);
boolean isSSL = ConnectionUtils.isSSL(ctx);
boolean isStartTLS = ConnectionUtils.isStartTLS(ctx);
String bindDN = ConnectionUtils.getBindDN(ctx);
@@ -779,7 +780,7 @@
args.add("--hostName");
args.add(hostName);
args.add("--port");
- args.add(String.valueOf(port));
+ args.add(String.valueOf(hostPort.getPort()));
args.add("--bindDN");
args.add(bindDN);
args.add("--bindPassword");
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
index bba580f..8459a18 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
@@ -14,7 +14,6 @@
* Copyright 2009-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2016 ForgeRock AS.
*/
-
package org.opends.guitools.controlpanel.ui;
import java.awt.Component;
@@ -45,7 +44,6 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
-import org.opends.admin.ads.ServerDescriptor;
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.admin.ads.util.ConnectionWrapper;
@@ -64,6 +62,7 @@
import org.opends.quicksetup.util.Utils;
import org.opends.server.monitors.VersionMonitorProvider;
import org.forgerock.opendj.ldap.DN;
+import org.opends.server.types.HostPort;
import org.opends.server.types.OpenDsException;
import org.opends.server.util.DynamicConstants;
import org.opends.server.util.StaticUtils;
@@ -84,7 +83,7 @@
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
private static final long serialVersionUID = 5051556513294844797L;
- private JComboBox combo;
+ private JComboBox<LocalizableMessage> combo;
private JLabel portLabel;
private JTextField hostName;
private JTextField port;
@@ -267,8 +266,8 @@
localServerInstallPath = instancePath.getAbsolutePath();
}
combo = Utilities.createComboBox();
- combo.setModel(new DefaultComboBoxModel(
- new Object[] {INFO_CTRL_PANEL_LOCAL_SERVER.get(),
+ combo.setModel(new DefaultComboBoxModel<LocalizableMessage>(
+ new LocalizableMessage[] {INFO_CTRL_PANEL_LOCAL_SERVER.get(),
INFO_CTRL_PANEL_REMOTE_SERVER.get()}));
combo.setSelectedIndex(0);
gbc.gridwidth = 2;
@@ -687,11 +686,11 @@
}
else
{
- String hostPort = ServerDescriptor.getServerRepresentation(
+ HostPort hostPort = new HostPort(
hostName.getText().trim(),
Integer.valueOf(port.getText().trim()));
NamingException ne = (NamingException)throwable;
- errors.add(getMessageForException(ne, hostPort));
+ errors.add(getMessageForException(ne, hostPort.toString()));
setPrimaryInvalid(portLabel);
}
setPrimaryInvalid(dnLabel);
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java
index ccadb8b..058486f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java
@@ -58,6 +58,7 @@
import org.forgerock.opendj.server.config.client.ReplicationSynchronizationProviderCfgClient;
import org.forgerock.opendj.server.config.client.RootCfgClient;
import org.opends.server.core.DirectoryServer;
+import org.opends.server.types.HostPort;
import org.opends.server.util.DynamicConstants;
import org.opends.server.util.StaticUtils;
@@ -1974,7 +1975,7 @@
* @throws ApplicationException if an error occurs while updating the remote
* OpenDS server configuration.
*/
- private void removeReferences(ConnectionWrapper connWrapper, String serverDisplay,
+ private void removeReferences(ConnectionWrapper connWrapper, HostPort serverDisplay,
Map<ADSContext.ServerProperty, Object> serverADSProperties)
throws ApplicationException
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/UserData.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/UserData.java
index a3a7b20..c7de89a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/UserData.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/UserData.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2008-2010 Sun Microsystems, Inc.
- * Portions Copyright 2011-2015 ForgeRock AS.
+ * Portions Copyright 2011-2016 ForgeRock AS.
*/
package org.opends.quicksetup;
@@ -31,6 +31,7 @@
import org.opends.quicksetup.installer.NewSuffixOptions;
import org.opends.quicksetup.installer.SuffixesToReplicateOptions;
import org.opends.quicksetup.util.Utils;
+import org.opends.server.types.HostPort;
import org.opends.server.util.CollectionUtils;
import com.forgerock.opendj.cli.CliConstants;
@@ -42,8 +43,7 @@
public class UserData
{
private String serverLocation;
- private String hostName;
- private int serverPort;
+ private HostPort hostPort = new HostPort(null, 0);
private int adminConnectorPort;
private String directoryManagerDn;
private String directoryManagerPwd;
@@ -161,7 +161,7 @@
*/
public void setHostName(String hostName)
{
- this.hostName = hostName;
+ hostPort = new HostPort(hostName, hostPort.getPort());
}
/**
@@ -170,7 +170,16 @@
*/
public String getHostName()
{
- return hostName;
+ return hostPort.getHost();
+ }
+
+ /**
+ * Returns the server host name and LDAP port.
+ * @return the server host name and LDAP port.
+ */
+ public HostPort getHostPort()
+ {
+ return hostPort;
}
/**
@@ -179,7 +188,7 @@
*/
public void setServerPort(int serverPort)
{
- this.serverPort = serverPort;
+ hostPort = new HostPort(hostPort.getHost(), serverPort);
}
/**
@@ -188,7 +197,7 @@
*/
public int getServerPort()
{
- return serverPort;
+ return hostPort.getPort();
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/AuthenticationData.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/AuthenticationData.java
index c37864c..2914aad 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/AuthenticationData.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/AuthenticationData.java
@@ -12,27 +12,23 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2006-2008 Sun Microsystems, Inc.
+ * Portions Copyright 2016 ForgeRock AS.
*/
-
package org.opends.quicksetup.installer;
+import org.opends.server.types.HostPort;
+
/**
* This class is used to provide a data model for the different parameters used
* to connect to a server that we want to replicate contents with.
*
* @see DataReplicationOptions
- *
*/
public class AuthenticationData
{
- private String hostName;
-
- private int port;
-
+ private HostPort hostPort = new HostPort(null, 0);
private String dn;
-
private String pwd;
-
private boolean useSecureConnection;
/**
@@ -41,7 +37,7 @@
*/
public void setPort(int port)
{
- this.port = port;
+ hostPort = new HostPort(hostPort.getHost(), port);
}
/**
@@ -50,7 +46,7 @@
*/
public int getPort()
{
- return port;
+ return getHostPort().getPort();
}
/**
@@ -90,21 +86,21 @@
}
/**
- * Returns the host name to connect to.
- * @return the host name to connect to.
+ * Returns the host name and port to connect to.
+ * @return the host name and port to connect to.
*/
- public String getHostName()
+ public HostPort getHostPort()
{
- return hostName;
+ return hostPort;
}
/**
* Sets the host name to connect to.
- * @param hostName the host name to connect to.
+ * @param hostport the host name and port to connect to.
*/
- public void setHostName(String hostName)
+ public void setHostPort(HostPort hostport)
{
- this.hostName = hostName;
+ this.hostPort = hostport;
}
/**
@@ -125,4 +121,11 @@
{
this.useSecureConnection = useSecureConnection;
}
+
+ String getLdapUrl()
+ {
+ HostPort hostPort = getHostPort();
+ String scheme = useSecureConnection() ? "ldaps" : "ldap";
+ return scheme + "://" + hostPort.getHost() + ":" + hostPort.getPort();
+ }
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
index 79c4791..4f93d32 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
@@ -121,6 +121,7 @@
import org.opends.quicksetup.util.Utils;
import org.opends.server.tools.BackendTypeHelper;
import org.opends.server.tools.BackendTypeHelper.BackendTypeUIAdapter;
+import org.opends.server.types.HostPort;
import org.opends.server.util.CertificateManager;
import org.opends.server.util.DynamicConstants;
import org.opends.server.util.SetupUtils;
@@ -1422,7 +1423,7 @@
AuthenticationData auth = repl.getAuthenticationData();
if (isVerbose())
{
- notifyListeners(getFormattedWithPoints(INFO_PROGRESS_UNCONFIGURING_ADS_ON_REMOTE.get(getHostDisplay(auth))));
+ notifyListeners(getFormattedWithPoints(INFO_PROGRESS_UNCONFIGURING_ADS_ON_REMOTE.get(auth.getHostPort())));
}
try
{
@@ -1674,7 +1675,7 @@
adsServers.add(getLocalReplicationServer());
for (String dn : baseDns)
{
- replicationServers.put(dn, new HashSet<String>(h));
+ replicationServers.put(dn, h);
}
}
else
@@ -1692,8 +1693,9 @@
AuthenticationData repPort = getUserData().getRemoteWithNoReplicationPort().get(server);
if (repPort != null)
{
- h.add(server.getHostName() + ":" + repPort.getPort());
- adsServers.add(server.getHostName() + ":" + repPort.getPort());
+ String serverDisplay = server.getHostName() + ":" + repPort.getPort();
+ h.add(serverDisplay);
+ adsServers.add(serverDisplay);
}
}
replicationServers.put(suffix.getDN(), h);
@@ -1705,14 +1707,14 @@
ConnectionWrapper connWrapper = null;
long localTime = -1;
long localTimeMeasureTime = -1;
- String localServerDisplay = null;
+ HostPort localServerDisplay = null;
try
{
connWrapper = createLocalConnection();
helper.configureReplication(connWrapper, replicationServers,
getUserData().getReplicationOptions().getReplicationPort(),
getUserData().getReplicationOptions().useSecureReplication(),
- getLocalHostPort(),
+ getUserData().getHostPort(),
knownReplicationServerIds, knownServerIds);
localTimeMeasureTime = System.currentTimeMillis();
localTime = Utils.getServerClock(connWrapper.getLdapContext());
@@ -2177,7 +2179,7 @@
ReplicaDescriptor replica = suffix.getReplicas().iterator().next();
ServerDescriptor server = replica.getServer();
- String hostPort = getHostPort(server);
+ HostPort hostPort = getHostPort(server);
boolean isADS = areDnsEqual(dn, ADSContext.getAdministrationSuffixDN());
boolean isSchema = areDnsEqual(dn, Constants.SCHEMA_DN);
@@ -2323,7 +2325,7 @@
{
if (isVerbose())
{
- notifyListeners(getFormattedWithPoints(INFO_PROGRESS_CREATING_ADS_ON_REMOTE.get(getHostDisplay(auth))));
+ notifyListeners(getFormattedWithPoints(INFO_PROGRESS_CREATING_ADS_ON_REMOTE.get(auth.getHostPort())));
}
adsContext.createAdminData(null);
@@ -2427,7 +2429,7 @@
LocalizableMessage msg;
if (isRemoteServer)
{
- msg = getMessageForException(ne, getHostDisplay(auth));
+ msg = getMessageForException(ne, auth.getHostPort().toString());
}
else
{
@@ -2438,7 +2440,7 @@
catch (ADSContextException ace)
{
throw new ApplicationException(ReturnCode.CONFIGURATION_ERROR, (isRemoteServer ? INFO_REMOTE_ADS_EXCEPTION.get(
- getHostDisplay(auth), ace.getMessageObject()) : INFO_ADS_EXCEPTION.get(ace)), ace);
+ auth.getHostPort(), ace.getMessageObject()) : INFO_ADS_EXCEPTION.get(ace)), ace);
}
finally
{
@@ -2448,16 +2450,15 @@
private ConnectionWrapper createConnection(AuthenticationData auth) throws NamingException
{
- String ldapUrl = getLdapUrl(auth);
+ String ldapUrl = auth.getLdapUrl();
String dn = auth.getDn();
String pwd = auth.getPwd();
- InitialLdapContext context = null;
-
+ InitialLdapContext context;
if (auth.useSecureConnection())
{
ApplicationTrustManager trustManager = getTrustManager();
- trustManager.setHost(auth.getHostName());
+ trustManager.setHost(auth.getHostPort().getHost());
context = createLdapsContext(ldapUrl, dn, pwd, getConnectTimeout(), null, trustManager, null);
}
else
@@ -2619,26 +2620,12 @@
{
type = PreferredConnection.Type.LDAP;
}
- cnx.add(new PreferredConnection(getLdapUrl(auth), type));
+ cnx.add(new PreferredConnection(auth.getLdapUrl(), type));
}
}
return cnx;
}
- private String getLdapUrl(AuthenticationData auth)
- {
- if (auth.useSecureConnection())
- {
- return "ldaps://" + auth.getHostName() + ":" + auth.getPort();
- }
- return "ldap://" + auth.getHostName() + ":" + auth.getPort();
- }
-
- private String getHostDisplay(AuthenticationData auth)
- {
- return auth.getHostName() + ":" + auth.getPort();
- }
-
private Map<ADSContext.ServerProperty, Object> getNewServerAdsProperties(UserData userData)
{
Map<ADSContext.ServerProperty, Object> serverProperties = new HashMap<>();
@@ -2979,11 +2966,7 @@
if (errorMsgs.isEmpty())
{
AuthenticationData auth = new AuthenticationData();
- auth.setHostName(host);
- if (port != null)
- {
- auth.setPort(port);
- }
+ auth.setHostPort(new HostPort(host, port != null ? port : 0));
auth.setDn(dn);
auth.setPwd(pwd);
auth.setUseSecureConnection(true);
@@ -3635,19 +3618,6 @@
getUserData().setEnableWindowsService(b);
}
- /**
- * Returns the number of free disk space in bytes required to install Open DS
- * For the moment we just return 20 Megabytes. TODO we might want to have
- * something dynamic to calculate the required free disk space for the
- * installation.
- *
- * @return the number of free disk space required to install Open DS.
- */
- private long getRequiredInstallSpace()
- {
- return 20 * 1024 * 1024;
- }
-
/** Update the UserInstallData with the contents we discover in the ADS. */
private Set<TopologyCacheException> updateUserDataWithSuffixesInADS(ADSContext adsContext,
ApplicationTrustManager trustManager) throws TopologyCacheException
@@ -3919,7 +3889,7 @@
* if the replication mechanism cannot find a peer.
*/
public void initializeSuffix(InitialLdapContext ctx, int replicaId, String suffixDn, boolean displayProgress,
- String sourceServerDisplay) throws ApplicationException, PeerNotFoundException
+ HostPort sourceServerDisplay) throws ApplicationException, PeerNotFoundException
{
boolean taskCreated = false;
int i = 1;
@@ -4190,12 +4160,7 @@
return getUserData().getHostName() + ":" + getUserData().getReplicationOptions().getReplicationPort();
}
- private String getLocalHostPort()
- {
- return getUserData().getHostName() + ":" + getUserData().getServerPort();
- }
-
- private void resetGenerationId(InitialLdapContext ctx, String suffixDn, String sourceServerDisplay)
+ private void resetGenerationId(InitialLdapContext ctx, String suffixDn, HostPort sourceServerDisplay)
throws ApplicationException
{
boolean taskCreated = false;
@@ -4368,9 +4333,9 @@
* the ServerDescriptor.
* @return the host port string representation of the provided server.
*/
- protected String getHostPort(ServerDescriptor server)
+ protected HostPort getHostPort(ServerDescriptor server)
{
- String hostPort = null;
+ HostPort hostPort = null;
for (PreferredConnection connection : getPreferredConnections())
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java
index 6cf9af4..d1731f3 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java
@@ -81,6 +81,7 @@
import org.opends.server.tools.JavaPropertiesTool;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DirectoryException;
+import org.opends.server.types.HostPort;
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.OpenDsException;
import org.opends.server.util.LDIFException;
@@ -361,7 +362,7 @@
* if something goes wrong.
*/
public void createBackend(ConnectionWrapper connWrapper, String backendName, Set<String> baseDNs,
- String serverDisplay, ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType)
+ HostPort serverDisplay, ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType)
throws ApplicationException
{
try
@@ -438,7 +439,7 @@
*/
public ConfiguredReplication configureReplication(
ConnectionWrapper connWrapper, Map<String,Set<String>> replicationServers,
- int replicationPort, boolean useSecureReplication, String serverDisplay,
+ int replicationPort, boolean useSecureReplication, HostPort serverDisplay,
Set<Integer> usedReplicationServerIds, Set<Integer> usedServerIds)
throws ApplicationException
{
@@ -647,7 +648,7 @@
* if something goes wrong.
*/
public void unconfigureReplication(ConnectionWrapper connWrapper, ConfiguredReplication replConf,
- String serverDisplay) throws ApplicationException
+ HostPort serverDisplay) throws ApplicationException
{
try
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/DataReplicationPanel.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/DataReplicationPanel.java
index 7461151..e3e49b4 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/DataReplicationPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/DataReplicationPanel.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2008-2009 Sun Microsystems, Inc.
- * Portions Copyright 2013-2015 ForgeRock AS.
+ * Portions Copyright 2013-2016 ForgeRock AS.
*/
package org.opends.quicksetup.installer.ui;
@@ -303,9 +303,9 @@
case REMOTE_SERVER_PWD:
return auth.getPwd();
case REMOTE_SERVER_HOST:
- return auth.getHostName();
+ return auth.getHostPort().getHost();
case REMOTE_SERVER_PORT:
- return auth.getPort();
+ return auth.getHostPort().getPort();
case REPLICATION_OPTIONS:
return defaultUserData.getReplicationOptions().getType();
default:
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/InstallReviewPanel.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/InstallReviewPanel.java
index 8e3c03e..5c2a542 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/InstallReviewPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/InstallReviewPanel.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions Copyright 2013-2015 ForgeRock AS.
+ * Portions Copyright 2013-2016 ForgeRock AS.
*/
package org.opends.quicksetup.installer.ui;
@@ -37,6 +37,7 @@
import org.opends.quicksetup.util.HtmlProgressMessageFormatter;
import org.opends.quicksetup.util.ProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
+import org.opends.server.types.HostPort;
import javax.swing.Box;
import javax.swing.DefaultComboBoxModel;
@@ -79,7 +80,7 @@
private JCheckBox enableWindowsServiceCheckBox;
private JLabel warningLabel;
- private JComboBox viewCombo;
+ private JComboBox<LocalizableMessage> viewCombo;
private final LocalizableMessage DISPLAY_TEXT = INFO_REVIEW_DISPLAY_TEXT.get();
private final LocalizableMessage DISPLAY_EQUIVALENT_COMMAND = INFO_REVIEW_DISPLAY_EQUIVALENT_COMMAND.get();
@@ -150,14 +151,11 @@
final JLabel l = new JLabel(instructions.toString());
l.setFont(UIFactory.INSTRUCTIONS_FONT);
- final LocalizableMessage[] values = {
+ viewCombo = new JComboBox<LocalizableMessage>();
+ viewCombo.setModel(new DefaultComboBoxModel<>(new LocalizableMessage[] {
DISPLAY_TEXT,
DISPLAY_EQUIVALENT_COMMAND
- };
-
- final DefaultComboBoxModel model = new DefaultComboBoxModel(values);
- viewCombo = new JComboBox();
- viewCombo.setModel(model);
+ }));
viewCombo.setSelectedIndex(0);
viewCombo.addActionListener(new ActionListener()
@@ -351,7 +349,7 @@
&& !remotePorts.isEmpty())
{
final AuthenticationData authData = userInstallData.getReplicationOptions().getAuthenticationData();
- final String serverToConnectDisplay = authData == null ? "" : authData.getHostName() + ":" + authData.getPort();
+ final HostPort serverToConnectDisplay = authData != null ? authData.getHostPort() : new HostPort(null, 0);
String s;
if (userInstallData.getReplicationOptions().useSecureReplication())
{
@@ -367,8 +365,8 @@
final TreeSet<LocalizableMessage> remoteServerLines = new TreeSet<>();
for (final ServerDescriptor server : remotePorts.keySet())
{
- String serverDisplay;
- if (server.getHostPort(false).equalsIgnoreCase(serverToConnectDisplay))
+ HostPort serverDisplay;
+ if (server.getHostPort(false).equals(serverToConnectDisplay))
{
serverDisplay = serverToConnectDisplay;
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/RemoteReplicationPortsPanel.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/RemoteReplicationPortsPanel.java
index c1dac9d..10cbfeb 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/RemoteReplicationPortsPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/RemoteReplicationPortsPanel.java
@@ -12,9 +12,8 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2008-2009 Sun Microsystems, Inc.
- * Portions Copyright 2014-2015 ForgeRock AS.
+ * Portions Copyright 2014-2016 ForgeRock AS.
*/
-
package org.opends.quicksetup.installer.ui;
import org.forgerock.i18n.LocalizableMessage;
@@ -47,6 +46,7 @@
import org.opends.quicksetup.ui.LabelFieldDescriptor;
import org.opends.quicksetup.ui.QuickSetupStepPanel;
import org.opends.quicksetup.ui.UIFactory;
+import org.opends.server.types.HostPort;
/**
* This class is used to provide a data model for the list of servers for which
@@ -62,9 +62,9 @@
private HashMap<String, JCheckBox> hmCbs = new HashMap<>();
private JScrollPane scroll;
private JPanel fieldsPanel;
- private TreeSet<ServerDescriptor> orderedServers = new TreeSet<>(this);
+ private TreeSet<ServerDescriptor> orderedServers = new TreeSet<>();
/** The display of the server the user provided in the replication options panel. */
- private String serverToConnectDisplay;
+ private HostPort serverToConnectDisplay;
/**
* Constructor of the panel.
@@ -152,7 +152,7 @@
/** {@inheritDoc} */
public int compare(ServerDescriptor desc1, ServerDescriptor desc2)
{
- return desc1.getHostPort(true).compareTo(desc2.getHostPort(true));
+ return desc1.getHostPort(true).toString().compareTo(desc2.getHostPort(true).toString());
}
/** {@inheritDoc} */
@@ -197,15 +197,7 @@
data.getRemoteWithNoReplicationPort().keySet());
AuthenticationData authData =
data.getReplicationOptions().getAuthenticationData();
- String newServerDisplay;
- if (authData != null)
- {
- newServerDisplay = authData.getHostName()+":"+authData.getPort();
- }
- else
- {
- newServerDisplay = "";
- }
+ HostPort newServerDisplay = authData != null ? authData.getHostPort() : new HostPort(null, 0);
if (!array.equals(orderedServers) ||
!newServerDisplay.equals(serverToConnectDisplay))
{
@@ -240,8 +232,8 @@
hmLabels.clear();
for (ServerDescriptor server : orderedServers)
{
- String serverDisplay;
- if (server.getHostPort(false).equalsIgnoreCase(serverToConnectDisplay))
+ HostPort serverDisplay;
+ if (server.getHostPort(false).equals(serverToConnectDisplay))
{
serverDisplay = serverToConnectDisplay;
}
@@ -250,7 +242,7 @@
serverDisplay = server.getHostPort(true);
}
LabelFieldDescriptor desc = new LabelFieldDescriptor(
- LocalizableMessage.raw(serverDisplay),
+ LocalizableMessage.raw(serverDisplay.toString()),
INFO_REPLICATION_PORT_TOOLTIP.get(),
LabelFieldDescriptor.FieldType.TEXTFIELD,
LabelFieldDescriptor.LabelType.PRIMARY,
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java
index ae7873b..6483b8f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2008-2010 Sun Microsystems, Inc.
- * Portions Copyright 2013-2015 ForgeRock AS.
+ * Portions Copyright 2013-2016 ForgeRock AS.
*/
package org.opends.quicksetup.installer.ui;
@@ -59,6 +59,7 @@
import org.opends.server.config.ConfigConstants;
import org.opends.server.tools.BackendTypeHelper;
import org.opends.server.tools.BackendTypeHelper.BackendTypeUIAdapter;
+import org.opends.server.types.HostPort;
/**
* This class is used to provide a data model for the list of suffixes that we
@@ -73,11 +74,8 @@
private final Set<SuffixDescriptor> orderedSuffixes = new TreeSet<>(this);
private final Map<String, JCheckBox> hmCheckBoxes = new HashMap<>();
private final Map<String, JComboBox<BackendTypeUIAdapter>> backendTypeComboBoxes = new HashMap<>();
- /**
- * The display of the server the user provided in the replication options
- * panel.
- */
- private String serverToConnectDisplay;
+ /** The display of the server the user provided in the replication options panel. */
+ private HostPort serverToConnectDisplay;
private JLabel noSuffixLabel;
private Component labelGlue;
@@ -216,8 +214,7 @@
{
Set<SuffixDescriptor> array = orderSuffixes(data.getSuffixesToReplicateOptions().getAvailableSuffixes());
AuthenticationData authData = data.getReplicationOptions().getAuthenticationData();
- String newServerDisplay;
- newServerDisplay = authData != null ? authData.getHostName() + ":" + authData.getPort() : "";
+ HostPort newServerDisplay = authData != null ? authData.getHostPort() : new HostPort(null, 0);
if (!array.equals(orderedSuffixes) || !newServerDisplay.equals(serverToConnectDisplay))
{
@@ -422,14 +419,14 @@
Set<String> replicaDisplays = new TreeSet<>();
for (ReplicaDescriptor rep : desc.getReplicas())
{
- replicaDisplays.add(getServerDisplay(rep));
+ replicaDisplays.add(getServerDisplay(rep).toString());
}
return joinAsString("\n", replicaDisplays);
}
- private String getServerDisplay(ReplicaDescriptor replica)
+ private HostPort getServerDisplay(ReplicaDescriptor replica)
{
- final boolean isServerToConnect = replica.getServer().getHostPort(false).equalsIgnoreCase(serverToConnectDisplay);
+ final boolean isServerToConnect = replica.getServer().getHostPort(false).equals(serverToConnectDisplay);
return isServerToConnect ? serverToConnectDisplay : replica.getServer().getHostPort(true);
}
@@ -450,5 +447,4 @@
{
return getSuffixString(desc1).compareTo(getSuffixString(desc2));
}
-
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java
index 7acf1a3..95d5896 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java
@@ -1854,10 +1854,9 @@
if (s.getAdminConnectorURL().equals(server.getAdminConnectorURL()))
{
AuthenticationData remoteRepl = userData.getRemoteWithNoReplicationPort().get(server);
- int remoteReplicationPort = remoteRepl.getPort();
cmdLine.add("--replicationPort1");
- cmdLine.add(String.valueOf(remoteReplicationPort));
+ cmdLine.add(String.valueOf(remoteRepl.getPort()));
if (remoteRepl.useSecureConnection())
{
cmdLine.add("--secureReplication1");
@@ -2029,8 +2028,7 @@
Set<SuffixDescriptor> suffixes = userData.getSuffixesToReplicateOptions().getSuffixes();
AuthenticationData authData = userData.getReplicationOptions().getAuthenticationData();
- String ldapURL =
- ConnectionUtils.getLDAPUrl(authData.getHostName(), authData.getPort(), authData.useSecureConnection());
+ String ldapURL = ConnectionUtils.getLDAPUrl(authData.getHostPort(), authData.useSecureConnection());
for (SuffixDescriptor suffix : suffixes)
{
boolean found = false;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/EnableReplicationUserData.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/EnableReplicationUserData.java
index 8dc8bbd..91230db 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/EnableReplicationUserData.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/EnableReplicationUserData.java
@@ -12,10 +12,12 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2008-2009 Sun Microsystems, Inc.
- * Portions Copyright 2015 ForgeRock AS.
+ * Portions Copyright 2015-2016 ForgeRock AS.
*/
package org.opends.server.tools.dsreplication;
+import org.opends.server.types.HostPort;
+
/**
* This class is used to store the information provided by the user to enable
* replication. It is required because when we are in interactive mode the
@@ -26,8 +28,7 @@
/** Data for enabling replication on a server. */
static final class EnableReplicationServerData
{
- private String hostName;
- private int port;
+ private HostPort hostPort = new HostPort(null, 0);
private String bindDn;
private String pwd;
private int replicationPort;
@@ -36,24 +37,34 @@
private boolean configureReplicationDomain = true;
/**
+ * Returns the host name and port of this server.
+ *
+ * @return the host name and port of this server.
+ */
+ HostPort getHostPort()
+ {
+ return hostPort;
+ }
+
+ /**
+ * Sets the host name and port of this server.
+ *
+ * @param hostPort
+ * the host name and port of this server
+ */
+ void setHostPort(HostPort hostPort)
+ {
+ this.hostPort = hostPort;
+ }
+
+ /**
* Returns the host name of this server.
*
* @return the host name of this server.
*/
String getHostName()
{
- return hostName;
- }
-
- /**
- * Sets the host name of this server.
- *
- * @param hostName
- * the host name of this server
- */
- void setHostName(String hostName)
- {
- this.hostName = hostName;
+ return hostPort.getHost();
}
/**
@@ -63,18 +74,7 @@
*/
int getPort()
{
- return port;
- }
-
- /**
- * Sets the port of this server.
- *
- * @param port
- * the port of this server
- */
- void setPort(int port)
- {
- this.port = port;
+ return hostPort.getPort();
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/MonoServerReplicationUserData.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/MonoServerReplicationUserData.java
index c060cf3..952b9fc 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/MonoServerReplicationUserData.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/MonoServerReplicationUserData.java
@@ -12,57 +12,38 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2008-2009 Sun Microsystems, Inc.
+ * Portions Copyright 2016 ForgeRock AS.
*/
-
package org.opends.server.tools.dsreplication;
-/**
- * This is an abstract class used for code refactorization.
- *
- */
+import org.opends.server.types.HostPort;
+
+/** This is an abstract class used for code factorization. */
abstract class MonoServerReplicationUserData extends ReplicationUserData
{
- private String hostName;
- private int port;
+ private HostPort hostPort = new HostPort(null, 0);
private boolean useStartTLS;
private boolean useSSL;
/**
- * Returns the host name of the server.
- * @return the host name of the server.
+ * Returns the host name and port of the server.
+ * @return the host name and port of the server.
*/
- public String getHostName()
+ public HostPort getHostPort()
{
- return hostName;
+ return hostPort;
}
/**
- * Sets the host name of the server.
- * @param hostName the host name of the server.
+ * Sets the host name and port of the server.
+ * @param hostPort the host name and port of the server.
*/
- public void setHostName(String hostName)
+ public void setHostPort(HostPort hostPort)
{
- this.hostName = hostName;
+ this.hostPort = hostPort;
}
/**
- * Returns the port of the server.
- * @return the port of the server.
- */
- public int getPort()
- {
- return port;
- }
-
- /**
- * Sets the port of the server.
- * @param port the port of the server.
- */
- public void setPort(int port)
- {
- this.port = port;
- }
- /**
* Returns <CODE>true</CODE> if we must use SSL to connect to the server and
* <CODE>false</CODE> otherwise.
* @return <CODE>true</CODE> if we must use SSL to connect to the server and
@@ -102,5 +83,3 @@
this.useStartTLS = useStartTLS;
}
}
-
-
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/PurgeHistoricalUserData.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/PurgeHistoricalUserData.java
index 2bc5698..5963fb8 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/PurgeHistoricalUserData.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/PurgeHistoricalUserData.java
@@ -12,7 +12,7 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2010 Sun Microsystems, Inc.
- * Portions Copyright 2014-2015 ForgeRock AS.
+ * Portions Copyright 2014-2016 ForgeRock AS.
*/
package org.opends.server.tools.dsreplication;
@@ -29,6 +29,7 @@
import org.opends.server.admin.client.cli.TaskScheduleArgs;
import org.opends.server.tools.tasks.TaskClient;
import org.opends.server.tools.tasks.TaskScheduleUserData;
+import org.opends.server.types.HostPort;
import org.opends.server.types.RawAttribute;
/** This class is used to store the information provided by the user to purge historical data. */
@@ -121,8 +122,8 @@
{
uData.setAdminUid(argParser.getAdministratorUIDOrDefault());
uData.setAdminPwd(argParser.getBindPasswordAdmin());
- uData.setHostName(argParser.getHostNameToStatusOrDefault());
- uData.setPort(argParser.getPortToStatusOrDefault());
+ uData.setHostPort(new HostPort(
+ argParser.getHostNameToStatusOrDefault(), argParser.getPortToStatusOrDefault()));
uData.setOnline(true);
TaskScheduleUserData taskSchedule = new TaskScheduleUserData();
TaskScheduleArgs taskArgs = argParser.getTaskArgsList();
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
index 94598bb..3ff3743 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -142,7 +142,6 @@
import static org.opends.admin.ads.util.ConnectionUtils.*;
import static org.opends.admin.ads.util.PreferredConnection.*;
import static org.opends.admin.ads.ServerDescriptor.getReplicationServer;
-import static org.opends.admin.ads.ServerDescriptor.getServerRepresentation;
import static org.opends.admin.ads.ServerDescriptor.getSuffixDisplay;
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
@@ -1042,10 +1041,8 @@
* Returns an InitialLdapContext using the provided parameters. We try to
* guarantee that the connection is able to read the configuration.
*
- * @param host
- * the host name.
- * @param port
- * the port to connect.
+ * @param hostPort
+ * the host name and port to connect.
* @param useSSL
* whether to use SSL or not.
* @param useStartTLS
@@ -1062,13 +1059,13 @@
* @throws NamingException
* if there was an error establishing the connection.
*/
- private InitialLdapContext createAdministrativeContext(String host,
- int port, boolean useSSL, boolean useStartTLS, String bindDn, String pwd,
+ private InitialLdapContext createAdministrativeContext(HostPort hostPort,
+ boolean useSSL, boolean useStartTLS, String bindDn, String pwd,
int connectTimeout, ApplicationTrustManager trustManager)
throws NamingException
{
InitialLdapContext ctx;
- String ldapUrl = getLDAPUrl(host, port, useSSL);
+ String ldapUrl = getLDAPUrl(hostPort, useSSL);
if (useSSL)
{
ctx = createLdapsContext(ldapUrl, bindDn, pwd, connectTimeout, null, trustManager, null);
@@ -1229,9 +1226,8 @@
ReturnCode.CLIENT_SIDE_CONNECT_ERROR, message);
}
}
- String hostPort =
- ServerDescriptor.getServerRepresentation(hostName, portNumber);
- LocalizableMessage message = getMessageForException(e, hostPort);
+ HostPort hostPort = new HostPort(hostName, portNumber);
+ LocalizableMessage message = getMessageForException(e, hostPort.toString());
throw new ClientException(ReturnCode.CLIENT_SIDE_CONNECT_ERROR, message);
}
}
@@ -1361,7 +1357,6 @@
private ReplicationCliReturnCode resetChangeNumber()
{
- final String changeNumber;
final SourceDestinationServerUserData uData = new SourceDestinationServerUserData();
if (!argParser.isInteractive())
@@ -1593,8 +1588,7 @@
}
catch (NamingException e)
{
- String hostPort = getServerRepresentation(uData.getHostName(), uData.getPort());
- logger.error(LocalizableMessage.raw("Error when creating connection for:" + hostPort));
+ logger.error(LocalizableMessage.raw("Error when creating connection for:" + uData.getHostPort()));
return null;
}
}
@@ -1603,15 +1597,13 @@
{
try
{
- return createAdministrativeContext(uData.getHostName(), uData.getPort(),
- useSSL, useStartTLS, bindDn,
+ return createAdministrativeContext(uData.getHostPort(), useSSL, useStartTLS, bindDn,
uData.getAdminPwd(), getConnectTimeout(), getTrustManager(sourceServerCI));
}
catch (NamingException ne)
{
- String hostPort = getServerRepresentation(uData.getHostName(), uData.getPort());
errPrintln();
- errPrintln(getMessageForException(ne, hostPort));
+ errPrintln(getMessageForException(ne, uData.getHostPort().toString()));
logger.error(LocalizableMessage.raw("Complete error stack:"), ne);
return null;
}
@@ -1773,7 +1765,7 @@
private LocalizableMessage getPurgeErrorMsg(String lastLogMsg, String state, InitialLdapContext ctx)
{
- String server = getHostPort(ctx);
+ HostPort server = getHostPort(ctx);
if (lastLogMsg != null)
{
return ERR_UNEXPECTED_DURING_TASK_WITH_LOG.get(lastLogMsg, state, server);
@@ -2122,8 +2114,7 @@
if (ctx != null)
{
uData.setOnline(true);
- uData.setHostName(sourceServerCI.getHostName());
- uData.setPort(sourceServerCI.getPortNumber());
+ uData.setHostPort(new HostPort(sourceServerCI.getHostName(), sourceServerCI.getPortNumber()));
uData.setAdminUid(sourceServerCI.getAdministratorUID());
uData.setAdminPwd(sourceServerCI.getBindPassword());
}
@@ -2263,8 +2254,7 @@
if (!cancelled)
{
- uData.getServer1().setHostName(host1);
- uData.getServer1().setPort(port1);
+ uData.getServer1().setHostPort(new HostPort(host1, port1));
uData.getServer1().setBindDn(bindDn1);
uData.getServer1().setPwd(pwd1);
}
@@ -2531,8 +2521,7 @@
if (!cancelled)
{
- uData.getServer2().setHostName(host2);
- uData.getServer2().setPort(port2);
+ uData.getServer2().setHostPort(new HostPort(host2, port2));
uData.getServer2().setBindDn(bindDn2);
uData.getServer2().setPwd(pwd2);
}
@@ -2834,8 +2823,7 @@
if (!cancelled)
{
- uData.setHostName(host);
- uData.setPort(port);
+ uData.setHostPort(new HostPort(host, port));
uData.setAdminUid(adminUid);
uData.setBindDn(bindDn);
uData.setAdminPwd(adminPwd);
@@ -3027,7 +3015,7 @@
private LocalizableMessage getPrompt(InitializeAllReplicationUserData uData, InitialLdapContext ctx)
{
- String hostPortSource = getHostPort(ctx);
+ HostPort hostPortSource = getHostPort(ctx);
if (initializeADS(uData.getBaseDNs()))
{
return INFO_REPLICATION_CONFIRM_INITIALIZE_ALL_ADS.get(ADSContext.getAdministrationSuffixDN(), hostPortSource);
@@ -3108,8 +3096,7 @@
InitialLdapContext ctx = createInitialLdapContextInteracting(sourceServerCI);
if (ctx != null)
{
- uData.setHostName(sourceServerCI.getHostName());
- uData.setPort(sourceServerCI.getPortNumber());
+ uData.setHostPort(new HostPort(sourceServerCI.getHostName(), sourceServerCI.getPortNumber()));
uData.setAdminUid(sourceServerCI.getAdministratorUID());
uData.setAdminPwd(sourceServerCI.getBindPassword());
if (uData instanceof StatusReplicationUserData)
@@ -3357,8 +3344,8 @@
private LocalizableMessage getInitializeReplicationPrompt(SourceDestinationServerUserData uData,
InitialLdapContext ctxSource, InitialLdapContext ctxDestination)
{
- String hostPortSource = getHostPort(ctxSource);
- String hostPortDestination = getHostPort(ctxDestination);
+ HostPort hostPortSource = getHostPort(ctxSource);
+ HostPort hostPortDestination = getHostPort(ctxDestination);
if (initializeADS(uData.getBaseDNs()))
{
final String adminSuffixDN = ADSContext.getAdministrationSuffixDN();
@@ -3413,8 +3400,8 @@
private void setConnectionDetails(
EnableReplicationServerData server, ServerArgs args, String adminDN, String adminPwd)
{
- server.setHostName(getValueOrDefault(args.hostNameArg));
- server.setPort(getValueOrDefault(args.portArg));
+ server.setHostPort(new HostPort(
+ getValueOrDefault(args.hostNameArg), getValueOrDefault(args.portArg)));
String pwd = args.getBindPassword();
if (pwd == null)
@@ -3427,7 +3414,7 @@
// Best-effort: try to use admin, if it does not work, use bind DN.
try
{
- InitialLdapContext ctx = createAdministrativeContext(server.getHostName(), server.getPort(),
+ InitialLdapContext ctx = createAdministrativeContext(server.getHostPort(),
useSSL, useStartTLS, adminDN, adminPwd, getConnectTimeout(), getTrustManager(sourceServerCI));
server.setBindDn(adminDN);
server.setPwd(adminPwd);
@@ -3488,8 +3475,8 @@
uData.setBindDn(bindDn);
uData.setAdminPwd(argParser.getBindPasswordAdmin());
- uData.setHostName(argParser.getHostNameToDisableOrDefault());
- uData.setPort(argParser.getPortToDisableOrDefault());
+ uData.setHostPort(new HostPort(
+ argParser.getHostNameToDisableOrDefault(), argParser.getPortToDisableOrDefault()));
uData.setDisableAll(argParser.disableAllArg.isPresent());
uData.setDisableReplicationServer(argParser.disableReplicationServerArg.isPresent());
@@ -3504,8 +3491,8 @@
{
initialize(uData);
- uData.setHostName(argParser.getHostNameToInitializeAllOrDefault());
- uData.setPort(argParser.getPortToInitializeAllOrDefault());
+ uData.setHostPort(new HostPort(
+ argParser.getHostNameToInitializeAllOrDefault(), argParser.getPortToInitializeAllOrDefault()));
}
/**
@@ -3518,8 +3505,7 @@
{
initialize(uData);
- uData.setHostName(argParser.getHostNameToStatusOrDefault());
- uData.setPort(argParser.getPortToStatusOrDefault());
+ uData.setHostPort(new HostPort(argParser.getHostNameToStatusOrDefault(), argParser.getPortToStatusOrDefault()));
uData.setScriptFriendly(argParser.isScriptFriendly());
}
@@ -3602,8 +3588,7 @@
boolean triedWithUserProvidedAdmin = false;
final ConnectionWrapper connWrapper1 = connWrapper.get();
final InitialLdapContext ctx1 = connWrapper1.getLdapContext();
- String host = getHostName(ctx1);
- int port = getPort(ctx1);
+ HostPort hostPort = getHostPort(ctx1);
boolean isSSL = isSSL(ctx1);
boolean isStartTLS = isStartTLS(ctx1);
if (getTrustManager(ci) == null)
@@ -3695,9 +3680,8 @@
close(ctx1);
try
{
- final InitialLdapContext ctx2 = createAdministrativeContext(host, port, isSSL,
- isStartTLS, getAdministratorDN(adminUid),
- adminPwd, getConnectTimeout(), getTrustManager(ci));
+ final InitialLdapContext ctx2 = createAdministrativeContext(hostPort, isSSL, isStartTLS,
+ getAdministratorDN(adminUid), adminPwd, getConnectTimeout(), getTrustManager(ci));
final ConnectionWrapper connWrapper2 =
new ConnectionWrapper(ctx2, getConnectTimeout(), getTrustManager(ci));
connWrapper.set(connWrapper2);
@@ -3712,9 +3696,7 @@
catch (Throwable t)
{
errPrintln();
- errPrintln(
- ERR_ERROR_CONNECTING_TO_SERVER_PROMPT_AGAIN.get(
- getServerRepresentation(host, port), t.getMessage()));
+ errPrintln(ERR_ERROR_CONNECTING_TO_SERVER_PROMPT_AGAIN.get(hostPort, t.getMessage()));
logger.warn(LocalizableMessage.raw("Complete error stack:", t));
errPrintln();
}
@@ -4188,8 +4170,7 @@
}
catch (NamingException e)
{
- String hostPort = getServerRepresentation(server.getHostName(), server.getPort());
- logger.error(LocalizableMessage.raw("Error when creating connection for:" + hostPort));
+ logger.error(LocalizableMessage.raw("Error when creating connection for:" + server.getHostPort()));
return null;
}
}
@@ -4201,13 +4182,12 @@
try
{
return createAdministrativeContext(
- server.getHostName(), server.getPort(), useSSL, useStartTLS, server.getBindDn(), server.getPwd(),
+ server.getHostPort(), useSSL, useStartTLS, server.getBindDn(), server.getPwd(),
getConnectTimeout(), getTrustManager(sourceServerCI));
}
catch (NamingException ne)
{
- String hostPort = getServerRepresentation(server.getHostName(), server.getPort());
- errorMessages.add(getMessageForException(ne, hostPort));
+ errorMessages.add(getMessageForException(ne, server.getHostPort().toString()));
logger.error(LocalizableMessage.raw("Complete error stack:"), ne);
return null;
}
@@ -4401,7 +4381,7 @@
try
{
return createAdministrativeContext(
- server.getHost(), server.getPort(), useSSL, useStartTLS,
+ server, useSSL, useStartTLS,
getAdministratorDN(uData.getAdminUid()), uData.getAdminPwd(),
getConnectTimeout(), getTrustManager(sourceServerCI));
}
@@ -5706,7 +5686,7 @@
catch (NamingException ne)
{
throw new ReplicationCliException(
- getMessageForException(ne, getHostPort(ctx)),
+ getMessageForException(ne, getHostPort(ctx).toString()),
ERROR_READING_CONFIGURATION, ne);
}
}
@@ -6332,7 +6312,7 @@
Set<ServerDescriptor> serversWithNoReplica)
{
Set<ReplicaDescriptor> orderedReplicas = new LinkedHashSet<>();
- Set<String> hostPorts = new TreeSet<>();
+ Set<HostPort> hostPorts = new TreeSet<>();
Set<ServerDescriptor> notAddedReplicationServers = new TreeSet<>(new ReplicationServerComparator());
for (Set<ReplicaDescriptor> replicas : orderedReplicaLists)
{
@@ -6340,7 +6320,7 @@
{
hostPorts.add(getHostPort2(replica.getServer(), cnx));
}
- for (String hostPort : hostPorts)
+ for (HostPort hostPort : hostPorts)
{
for (ReplicaDescriptor replica : replicas)
{
@@ -6401,8 +6381,7 @@
// Suffix DN
tableBuilder.appendCell(LocalizableMessage.raw(replica.getSuffix().getDN()));
// Server port
- tableBuilder.appendCell(
- LocalizableMessage.raw(getHostPort2(replica.getServer(), cnx)));
+ tableBuilder.appendCell(LocalizableMessage.raw("%s", getHostPort2(replica.getServer(), cnx)));
// Number of entries
int nEntries = replica.getEntries();
if (nEntries >= 0)
@@ -6496,7 +6475,7 @@
// Suffix DN
tableBuilder.appendCell(EMPTY_MSG);
// Server port
- tableBuilder.appendCell(LocalizableMessage.raw(getHostPort2(server, cnx)));
+ tableBuilder.appendCell(LocalizableMessage.raw("%s", getHostPort2(server, cnx)));
// Number of entries
if (scriptFriendly)
{
@@ -6600,7 +6579,7 @@
{
tableBuilder.startRow();
// Server port
- tableBuilder.appendCell(LocalizableMessage.raw(getHostPort2(server, cnx)));
+ tableBuilder.appendCell(LocalizableMessage.raw("%s", getHostPort2(server, cnx)));
// Replication port
int replicationPort = server.getReplicationServerPort();
if (replicationPort >= 0)
@@ -7143,16 +7122,15 @@
}
catch (NamingException ne)
{
- String hostPort = getHostPort2(s, cache.getPreferredConnections());
- LocalizableMessage msg = getMessageForException(ne, hostPort);
+ HostPort hostPort = getHostPort2(s, cache.getPreferredConnections());
+ LocalizableMessage msg = getMessageForException(ne, hostPort.toString());
throw new ReplicationCliException(msg, ERROR_CONNECTING, ne);
}
catch (Exception ode)
{
- String hostPort = getHostPort2(s, cache.getPreferredConnections());
+ HostPort hostPort = getHostPort2(s, cache.getPreferredConnections());
LocalizableMessage msg = getMessageForEnableException(hostPort, baseDN);
- throw new ReplicationCliException(msg,
- ERROR_ENABLING_REPLICATION_ON_BASEDN, ode);
+ throw new ReplicationCliException(msg, ERROR_ENABLING_REPLICATION_ON_BASEDN, ode);
}
finally
{
@@ -7203,8 +7181,7 @@
}
catch (NamingException ne)
{
- String hostPort = getHostPort(ctxSource);
- LocalizableMessage msg = getMessageForException(ne, hostPort);
+ LocalizableMessage msg = getMessageForException(ne, getHostPort(ctxSource).toString());
throw new ReplicationCliException(msg, ERROR_READING_CONFIGURATION, ne);
}
@@ -7425,7 +7402,7 @@
private LocalizableMessage getPrePostErrorMsg(String lastLogMsg, String state, InitialLdapContext ctx)
{
- String server = getHostPort(ctx);
+ HostPort server = getHostPort(ctx);
if (lastLogMsg != null)
{
return ERR_UNEXPECTED_DURING_TASK_WITH_LOG.get(lastLogMsg, state, server);
@@ -7461,7 +7438,7 @@
{
boolean isOver = false;
String dn = null;
- String serverDisplay = getHostPort(ctx);
+ HostPort serverDisplay = getHostPort(ctx);
Map<String, String> attrsMap = new TreeMap<>();
attrsMap.put("ds-task-initialize-domain-dn", baseDN);
attrsMap.put("ds-task-initialize-replica-server-id", "all");
@@ -7667,7 +7644,7 @@
}
}
- private LocalizableMessage getInitializeAllErrorMsg(String serverDisplay, String lastLogMsg, String state)
+ private LocalizableMessage getInitializeAllErrorMsg(HostPort serverDisplay, String lastLogMsg, String state)
{
if (lastLogMsg != null)
{
@@ -7752,7 +7729,7 @@
pwd, getTrustManager(sourceServerCI), getConnectTimeout(), cnx, filter);
ConnectionWrapper ctx = null;
String lastBaseDN = null;
- String hostPort = null;
+ HostPort hostPort = null;
try
{
@@ -7842,7 +7819,7 @@
catch (NamingException ne)
{
hostPort = getHostPort2(server, cnx);
- LocalizableMessage msg = getMessageForException(ne, hostPort);
+ LocalizableMessage msg = getMessageForException(ne, hostPort.toString());
throw new ReplicationCliException(msg, ERROR_CONNECTING, ne);
}
catch (Exception ode)
@@ -7877,7 +7854,7 @@
*/
private void deleteReplicationDomain(ConnectionWrapper ctx, String baseDN) throws ReplicationCliException
{
- String hostPort = getHostPort(ctx.getLdapContext());
+ HostPort hostPort = getHostPort(ctx.getLdapContext());
try
{
RootCfgClient root = ctx.getRootConfiguration();
@@ -7933,7 +7910,7 @@
private void disableReplicationServer(ConnectionWrapper connWrapper)
throws ReplicationCliException
{
- String hostPort = getHostPort(connWrapper.getLdapContext());
+ HostPort hostPort = getHostPort(connWrapper.getLdapContext());
try
{
RootCfgClient root = connWrapper.getRootConfiguration();
@@ -7990,7 +7967,7 @@
* the replication domain or updating the list of replication servers of
* the replication domain).
*/
- private LocalizableMessage getMessageForEnableException(String hostPort, String baseDN)
+ private LocalizableMessage getMessageForEnableException(HostPort hostPort, String baseDN)
{
return ERR_REPLICATION_CONFIGURING_BASEDN.get(baseDN, hostPort);
}
@@ -8009,7 +7986,7 @@
* the replication domain or updating the list of replication servers of
* the replication domain).
*/
- private LocalizableMessage getMessageForDisableException(String hostPort, String baseDN)
+ private LocalizableMessage getMessageForDisableException(HostPort hostPort, String baseDN)
{
return ERR_REPLICATION_CONFIGURING_BASEDN.get(baseDN, hostPort);
}
@@ -8352,10 +8329,9 @@
* @param cnx the preferred connections list.
* @return the host port string representation of the provided server.
*/
- private String getHostPort2(ServerDescriptor server,
- Collection<PreferredConnection> cnx)
+ private HostPort getHostPort2(ServerDescriptor server, Collection<PreferredConnection> cnx)
{
- String hostPort = null;
+ HostPort hostPort = null;
for (PreferredConnection connection : cnx)
{
String url = connection.getLDAPURL();
@@ -9495,8 +9471,8 @@
ctxDestination = adsCtx1.getDirContext();
}
- String hostPortSource = getHostPort(ctxSource);
- String hostPortDestination = getHostPort(ctxDestination);
+ HostPort hostPortSource = getHostPort(ctxSource);
+ HostPort hostPortDestination = getHostPort(ctxDestination);
if (isInteractive())
{
LocalizableMessage msg = INFO_REPLICATION_MERGING_REGISTRIES_CONFIRMATION.get(hostPortSource,
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/HostPort.java b/opendj-server-legacy/src/main/java/org/opends/server/types/HostPort.java
index 7cc61f3..af639d9 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/HostPort.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/HostPort.java
@@ -12,13 +12,14 @@
* information: "Portions Copyright [year] [name of copyright owner]".
*
* Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2013-2015 ForgeRock AS.
+ * Portions Copyright 2013-2016 ForgeRock AS.
*/
package org.opends.server.types;
import java.net.*;
import java.util.Enumeration;
import java.util.HashSet;
+import java.util.Objects;
import java.util.Set;
import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -385,17 +386,6 @@
}
/**
- * Returns a normalized string representation of this {@code HostPort} object.
- *
- * @return A string representation of this {@code HostPort} object.
- * @see #normalizedHost what host normalization covers
- */
- private String toNormalizedString()
- {
- return toString(normalizedHost);
- }
-
- /**
* Inner computation for #toString() and {@link #toNormalizedString()}.
*
* @param hostName
@@ -501,19 +491,7 @@
}
HostPort other = (HostPort) obj;
- if (normalizedHost == null)
- {
- if (other.normalizedHost != null)
- {
- return false;
- }
- }
- else if (!normalizedHost.equals(other.normalizedHost))
- {
- return false;
- }
-
- return port == other.port;
+ return port == other.port && Objects.equals(normalizedHost, other.normalizedHost);
}
/**
@@ -531,5 +509,4 @@
result = prime * result + port;
return result;
}
-
}
--
Gitblit v1.10.0