From 18dc6866af53fb06efb0879f9c9c369e698d7379 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 18 Apr 2016 06:57:37 +0000
Subject: [PATCH] Remove ConnectionWrapper constructor accepting an InitialLdapContext
---
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ServerLoader.java | 66 ++++++++------------------------
1 files changed, 17 insertions(+), 49 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ServerLoader.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ServerLoader.java
index e8e17dc..30b5800 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ServerLoader.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ServerLoader.java
@@ -24,7 +24,6 @@
import javax.naming.NamingException;
import javax.naming.NoPermissionException;
import javax.naming.TimeLimitExceededException;
-import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapName;
import org.forgerock.i18n.LocalizableMessage;
@@ -38,8 +37,6 @@
import com.forgerock.opendj.cli.Utils;
-import static org.opends.server.util.StaticUtils.*;
-
/**
* Class used to load the configuration of a server. Basically the code
* uses some provided properties and authentication information to connect
@@ -151,11 +148,11 @@
public void run()
{
lastException = null;
- InitialLdapContext ctx = null;
- try
+ boolean connCreated = false;
+ try (ConnectionWrapper conn = createConnectionWrapper())
{
- ctx = createContext();
- serverDescriptor = ServerDescriptor.createStandalone(ctx, filter);
+ connCreated = true;
+ serverDescriptor = ServerDescriptor.createStandalone(conn.getLdapContext(), filter);
serverDescriptor.setAdsProperties(serverProperties);
serverDescriptor.updateAdsPropertiesWithServerProperties();
}
@@ -181,7 +178,7 @@
{
logger.warn(LocalizableMessage.raw(
"NamingException error reading server: " + getLastLdapUrl(), e));
- Type type = ctx != null
+ Type type = connCreated
? TopologyCacheException.Type.GENERIC_READING_SERVER
: TopologyCacheException.Type.GENERIC_CREATING_CONNECTION;
lastException = new TopologyCacheException(type, e, trustManager, getLastLdapUrl());
@@ -200,21 +197,18 @@
finally
{
isOver = true;
- close(ctx);
}
}
/**
- * Create an InitialLdapContext based in the provide server properties and
- * authentication data provided in the constructor.
- * @return an InitialLdapContext based in the provide server properties and
- * authentication data provided in the constructor.
- * @throws NamingException if an error occurred while creating the
- * InitialLdapContext.
+ * Returns a Connection Wrapper.
+ *
+ * @return the connection wrapper
+ * @throws NamingException
+ * If an error occurs.
*/
- public InitialLdapContext createContext() throws NamingException
+ public ConnectionWrapper createConnectionWrapper() throws NamingException
{
- InitialLdapContext ctx = null;
if (trustManager != null)
{
trustManager.resetLastRefusedItems();
@@ -226,42 +220,16 @@
/* Try to connect to the server in a certain order of preference. If an
* URL fails, we will try with the others.
*/
- LinkedHashSet<PreferredConnection> conns = getLDAPURLsByPreference();
-
- for (PreferredConnection connection : conns)
+ for (PreferredConnection connection : getLDAPURLsByPreference())
{
- if (ctx == null)
+ lastLdapUrl = connection.getLDAPURL();
+ ConnectionWrapper conn = new ConnectionWrapper(lastLdapUrl, connection.getType(), dn, pwd, timeout, trustManager);
+ if (conn.getLdapContext() != null)
{
- lastLdapUrl = connection.getLDAPURL();
- switch (connection.getType())
- {
- case LDAPS:
- ctx = ConnectionUtils.createLdapsContext(lastLdapUrl, dn, pwd,
- timeout, null, trustManager, null);
- break;
- case START_TLS:
- ctx = ConnectionUtils.createStartTLSContext(lastLdapUrl, dn, pwd,
- timeout, null, trustManager, null, null);
- break;
- default:
- ctx = ConnectionUtils.createLdapContext(lastLdapUrl, dn, pwd,
- timeout, null);
- }
+ return conn;
}
}
- return ctx;
- }
-
- /**
- * Returns a Connection Wrapper.
- *
- * @return the connection wrapper
- * @throws NamingException
- * If an error occurs.
- */
- public ConnectionWrapper createConnectionWrapper() throws NamingException
- {
- return new ConnectionWrapper(createContext(), timeout, trustManager);
+ return null;
}
/**
--
Gitblit v1.10.0