From 787b6469989dbb2326833b24b6d82fbc90cc3f17 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Thu, 18 Oct 2007 12:48:52 +0000
Subject: [PATCH] Fix for issue 2465: New - dsreplication -q -X : Java exception

---
 opendj-sdk/opends/src/ads/org/opends/admin/ads/TopologyCache.java                         |    2 
 opendj-sdk/opends/src/ads/org/opends/admin/ads/util/ServerLoader.java                     |   10 +++-
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java          |   16 ++++++-
 opendj-sdk/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java |   80 +++++++++++++++++++++++++++++-----------
 4 files changed, 79 insertions(+), 29 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 4b0cff2..798ef62 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
@@ -240,7 +240,7 @@
       Map<ServerProperty,Object> serverProperties)
   {
     return new ServerLoader(serverProperties, dn, pwd,
-        trustManager.createCopy());
+        trustManager == null ? null : trustManager.createCopy());
   }
 
   /**
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 6a48647..8ca9732 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
@@ -236,9 +236,13 @@
   public InitialLdapContext createContext() throws NamingException
   {
     InitialLdapContext ctx = null;
-    trustManager.resetLastRefusedItems();
-    String host = (String)serverProperties.get(ServerProperty.HOST_NAME);
-    trustManager.setHost(host);
+    if (trustManager != null)
+    {
+      trustManager.resetLastRefusedItems();
+
+      String host = (String)serverProperties.get(ServerProperty.HOST_NAME);
+      trustManager.setHost(host);
+    }
     lastLdapUrl = getLdapsUrl(serverProperties);
 
     if (lastLdapUrl == null)
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
index 622964f..793e449 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
@@ -365,13 +365,22 @@
     EnableReplicationUserData uData = new EnableReplicationUserData();
     if (argParser.isInteractive())
     {
-      if (promptIfRequired(uData))
+      try
       {
-        returnValue = enableReplication(uData);
+        if (promptIfRequired(uData))
+        {
+          returnValue = enableReplication(uData);
+        }
+        else
+        {
+          returnValue = USER_CANCELLED;
+        }
       }
-      else
+      catch (ReplicationCliException rce)
       {
-        returnValue = USER_CANCELLED;
+        returnValue = rce.getErrorCode();
+        printLineBreak();
+        printErrorMessage(getCriticalExceptionMessage(rce));
       }
     }
     else
@@ -394,13 +403,22 @@
     DisableReplicationUserData uData = new DisableReplicationUserData();
     if (argParser.isInteractive())
     {
-      if (promptIfRequired(uData))
+      try
       {
-        returnValue = disableReplication(uData);
+        if (promptIfRequired(uData))
+        {
+          returnValue = disableReplication(uData);
+        }
+        else
+        {
+          returnValue = USER_CANCELLED;
+        }
       }
-      else
+      catch (ReplicationCliException rce)
       {
-        returnValue = USER_CANCELLED;
+        returnValue = rce.getErrorCode();
+        printLineBreak();
+        printErrorMessage(getCriticalExceptionMessage(rce));
       }
     }
     else
@@ -453,13 +471,22 @@
     StatusReplicationUserData uData = new StatusReplicationUserData();
     if (argParser.isInteractive())
     {
-      if (promptIfRequired(uData))
+      try
       {
-        returnValue = statusReplication(uData);
+        if (promptIfRequired(uData))
+        {
+          returnValue = statusReplication(uData);
+        }
+        else
+        {
+          returnValue = USER_CANCELLED;
+        }
       }
-      else
+      catch (ReplicationCliException rce)
       {
-        returnValue = USER_CANCELLED;
+        returnValue = rce.getErrorCode();
+        printLineBreak();
+        printErrorMessage(getCriticalExceptionMessage(rce));
       }
     }
     else
@@ -507,8 +534,11 @@
    * @param uData the object to be updated.
    * @return <CODE>true</CODE> if the object was successfully updated and
    * <CODE>false</CODE> if the user cancelled the operation.
+   * @throws ReplicationCliException if a critical error occurs reading the
+   * ADS.
    */
   private boolean promptIfRequired(EnableReplicationUserData uData)
+  throws ReplicationCliException
   {
     boolean cancelled = false;
 
@@ -1025,8 +1055,11 @@
    * @param uData the object to be updated.
    * @return <CODE>true</CODE> if the object was successfully updated and
    * <CODE>false</CODE> if the user cancelled the operation.
+   * @throws ReplicationCliException if there is a critical error reading the
+   * ADS.
    */
   private boolean promptIfRequired(DisableReplicationUserData uData)
+  throws ReplicationCliException
   {
     boolean cancelled = false;
 
@@ -1392,8 +1425,11 @@
    * @param uData the object to be updated.
    * @return <CODE>true</CODE> if the object was successfully updated and
    * <CODE>false</CODE> if the user cancelled the operation.
+   * @throws ReplicationCliException if a critical error occurs reading the
+   * ADS.
    */
   private boolean promptIfRequired(StatusReplicationUserData uData)
+  throws ReplicationCliException
   {
     boolean cancelled = false;
 
@@ -2167,13 +2203,15 @@
    * @param isFirstOrSourceServer whether this is the first server in the
    * enable replication subcommand or the source server in the initialize server
    * subcommand.
+   * @throws ReplicationCliException if a critical error occurred.
    * @return <CODE>true</CODE> if everything went fine and the user accepted
    * all the certificates and confirmed everything.  Returns <CODE>false</CODE>
-   * if a critical error occurred or the user did not accept a certificate or
-   * any of the confirmation messages.
+   * if the user did not accept a certificate or any of the confirmation
+   * messages.
    */
   private boolean loadADSAndAcceptCertificates(InitialLdapContext[] ctx,
       ReplicationUserData uData, boolean isFirstOrSourceServer)
+  throws ReplicationCliException
   {
     boolean cancelled = false;
     boolean triedWithUserProvidedAdmin = false;
@@ -2339,19 +2377,17 @@
     }
     catch (ADSContextException ace)
     {
-      printLineBreak();
-      printErrorMessage(Utils.getThrowableMsg(INFO_BUG_MSG.get(), ace));
-
       LOG.log(Level.SEVERE, "Complete error stack:", ace);
-      cancelled = true;
+      throw new ReplicationCliException(
+          ERR_REPLICATION_READING_ADS.get(ace.getMessage()),
+          ERROR_READING_ADS, ace);
     }
     catch (TopologyCacheException tce)
     {
-      printLineBreak();
-      printErrorMessage(Utils.getMessage(tce));
-
       LOG.log(Level.SEVERE, "Complete error stack:", tce);
-      cancelled = true;
+      throw new ReplicationCliException(
+          ERR_REPLICATION_READING_ADS.get(tce.getMessage()),
+          ERROR_READING_TOPOLOGY_CACHE, tce);
     }
     return !cancelled;
   }
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java
index 79588bb..480d6bd 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java
@@ -798,8 +798,15 @@
       ApplicationTrustManager trustManager)
   {
     boolean returnValue = false;
-    ApplicationTrustManager.Cause cause =
-      usedTrustManager.getLastRefusedCause();
+    ApplicationTrustManager.Cause cause;
+    if (usedTrustManager != null)
+    {
+      cause = usedTrustManager.getLastRefusedCause();
+    }
+    else
+    {
+      cause = null;
+    }
 
     LOG.log(Level.INFO, "Certificate exception cause: "+cause);
     UserDataCertificateException.Type excType = null;
@@ -948,7 +955,10 @@
       if ((chain != null) && (authType != null) && (host != null))
       {
         LOG.log(Level.INFO, "Accepting certificate presented by host "+host);
-        trustManager.acceptCertificate(chain, authType, host);
+        if (trustManager != null)
+        {
+          trustManager.acceptCertificate(chain, authType, host);
+        }
         accepted = true;
       }
       else

--
Gitblit v1.10.0