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

jvergara
07.12.2009 b9b49c232ad28c2ace82cd573ff7bef0ab98f294
Improve the displayed messages when an ADSContextException occurs.
i18n the messages of the ADSContextException.
Make dsreplication consistent with the fix made for dsconfig (see issue 4091).
Fix a bug in ADSContext when deleting the contents of the ADS.
Fix a bug in the equivalent command display when the user chooses to disable all replication on a server or to disable the replication server.
6 files modified
177 ■■■■■ changed files
opends/src/ads/org/opends/admin/ads/ADSContextException.java 61 ●●●●● patch | view | raw | blame | history
opends/src/ads/org/opends/admin/ads/SubtreeDeleteControl.java 43 ●●●● patch | view | raw | blame | history
opends/src/messages/messages/quicksetup.properties 5 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java 1 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java 65 ●●●● patch | view | raw | blame | history
opends/src/ads/org/opends/admin/ads/ADSContextException.java
@@ -22,11 +22,13 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 */
package org.opends.admin.ads;
import static org.opends.messages.QuickSetupMessages.*;
import org.opends.messages.Message;
import org.opends.server.types.OpenDsException;
@@ -120,7 +122,7 @@
   */
  public ADSContextException(ErrorType error)
  {
    this.error = error;
    this(error, null);
  }
  /**
@@ -131,8 +133,14 @@
   */
  public ADSContextException(ErrorType error, Throwable x)
  {
    super(getMessage(error, x), x);
    this.error = error;
    this.embeddedException = x;
    toString = "ADSContextException: error type "+error+".";
    if (getCause() != null)
    {
      toString += "  Root cause: "+getCause().toString();
    }
  }
  /**
@@ -154,24 +162,6 @@
  }
  /**
   * Retrieves a message providing the reason for this exception.
   *
   * @return  A message providing the reason for this exception.
   */
  public Message getReason()
  {
    if (toString == null)
    {
      toString = "ADSContextException: error type "+error+".";
      if (getCause() != null)
      {
        toString += "  Root cause: "+getCause().toString();
      }
    }
    return Message.raw(toString); // TODO: i18n
  }
  /**
   * {@inheritDoc}
   */
  public void printStackTrace()
@@ -184,4 +174,35 @@
      System.out.println("}");
    }
  }
  /**
   * {@inheritDoc}
   */
  public String toString()
  {
    return toString;
  }
  private static Message getMessage(ErrorType error, Throwable x)
  {
    Message msg;
    if (x != null)
    {
      if (x instanceof OpenDsException)
      {
        msg = INFO_ADS_CONTEXT_EXCEPTION_WITH_DETAILS_MSG.get(error.toString(),
            ((OpenDsException)x).getMessageObject());
      }
      else
      {
        msg = INFO_ADS_CONTEXT_EXCEPTION_WITH_DETAILS_MSG.get(error.toString(),
            x.toString());
      }
    }
    else
    {
      msg = INFO_ADS_CONTEXT_EXCEPTION_MSG.get(error.toString());
    }
    return msg;
  }
}
opends/src/ads/org/opends/admin/ads/SubtreeDeleteControl.java
@@ -22,17 +22,17 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 */
package org.opends.admin.ads;
import javax.naming.ldap.Control;
import javax.naming.ldap.BasicControl;
/**
 * This class implements the LDAP subtree delete control for JNDI.
 */
public class SubtreeDeleteControl implements Control
public class SubtreeDeleteControl extends BasicControl
{
  /**
   * The serial version identifier required to satisfy the compiler
@@ -44,39 +44,10 @@
  static final long serialVersionUID = 3941576361457157921L;
  /**
    * Retrieves the object identifier assigned for the LDAP control.
    *
    * @return The non-null object identifier string.
    * Default constructor.
    */
  public String getID() {
    return "1.2.840.113556.1.4.805";
  public SubtreeDeleteControl()
  {
    super("1.2.840.113556.1.4.805");
  }
  /**
    * Determines the criticality of the LDAP control.
    * A critical control must not be ignored by the server.
    * In other words, if the server receives a critical control
    * that it does not support, regardless of whether the control
    * makes sense for the operation, the operation will not be performed
    * and an <tt>OperationNotSupportedException</tt> will be thrown.
    * @return true if this control is critical; false otherwise.
    */
  public boolean isCritical() {
    return true;
  }
  /**
    * Retrieves the ASN.1 BER encoded value of the LDAP control.
    * The result is the raw BER bytes including the tag and length of
    * the control's value. It does not include the controls OID or criticality.
    *
    * Null is returned if the value is absent.
    *
    * @return A possibly null byte array representing the ASN.1 BER encoded
    *         value of the LDAP control.
    */
  public byte[] getEncodedValue() {
    return new byte[] {};
  }
}
opends/src/messages/messages/quicksetup.properties
@@ -1350,3 +1350,8 @@
 the upgrader (%s).%n%nTo fix this problem delete the file %s and click on \
 'Next' again.%nOnce the upgrader finishes you will have to set again the \
 java arguments by running the command-line %s.
INFO_ADS_CONTEXT_EXCEPTION_MSG=Registration information error.  Error type: \
 '%s'.
INFO_ADS_CONTEXT_EXCEPTION_WITH_DETAILS_MSG=Registration information error.  \
 Error type: '%s'.  Details: %s
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -2697,7 +2697,7 @@
              ReturnCode.CONFIGURATION_ERROR,
              ((isRemoteServer)
                      ? INFO_REMOTE_ADS_EXCEPTION.get(
                      getHostDisplay(auth), ace.getReason())
                      getHostDisplay(auth), ace.getMessageObject())
                      : INFO_ADS_EXCEPTION.get(ace.toString())), ace);
    }
    finally
opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java
@@ -74,7 +74,6 @@
import org.opends.server.types.InitializationException;
import org.opends.server.util.EmbeddedUtils;
import org.opends.server.util.ServerConstants;
import org.opends.server.util.SetupUtils;
import org.opends.server.util.StaticUtils;
import org.opends.server.util.args.ArgumentException;
import org.opends.server.util.args.BooleanArgument;
opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -5137,7 +5137,7 @@
    catch (ADSContextException adce)
    {
      throw new ReplicationCliException(
          ERR_REPLICATION_UPDATING_ADS.get(adce.getReason()),
          ERR_REPLICATION_UPDATING_ADS.get(adce.getMessageObject()),
          ERROR_UPDATING_ADS, adce);
    }
    if (!adsAlreadyReplicated)
@@ -5789,10 +5789,12 @@
      {
        LOG.log(Level.INFO, "Error unregistering server: "+
            server.getAdsProperties(), adce);
        println();
        println(
            ERR_REPLICATION_UPDATING_ADS.get(adce.getMessage()));
        println();
        if (adce.getError() != ADSContextException.ErrorType.NOT_YET_REGISTERED)
        {
          throw new ReplicationCliException(
              ERR_REPLICATION_UPDATING_ADS.get(adce.getMessageObject()),
              ERROR_READING_ADS, adce);
        }
      }
    }
@@ -5942,10 +5944,13 @@
          {
            LOG.log(Level.WARNING, "Error unregistering server: "+
                s.getAdsProperties(), adce);
            println();
            println(
                ERR_REPLICATION_UPDATING_ADS.get(adce.getMessage()));
            println();
            if (adce.getError() !=
              ADSContextException.ErrorType.NOT_YET_REGISTERED)
            {
              throw new ReplicationCliException(
                  ERR_REPLICATION_UPDATING_ADS.get(adce.getMessageObject()),
                  ERROR_READING_ADS, adce);
            }
          }
        }
      }
@@ -5977,15 +5982,15 @@
        }
        adsCtx.createAdminData(adminBackendName);
        printProgress(formatter.getFormattedDone());
        printlnProgress();
      }
      catch (ADSContextException adce)
      {
        LOG.log(Level.SEVERE, "Error resetting contents of cn=admin data: "+
            adce, adce);
        println();
        println(
            ERR_REPLICATION_UPDATING_ADS.get(adce.getMessage()));
        println();
        throw new ReplicationCliException(
            ERR_REPLICATION_UPDATING_ADS.get(adce.getMessageObject()),
            ERROR_READING_ADS, adce);
      }
    }
  }
@@ -8307,6 +8312,10 @@
      {
        s = ((NamingException)c).toString(true);
      }
      else if (c instanceof OpenDsException)
      {
        s = ((OpenDsException)c).getMessageObject().toString();
      }
      else
      {
        s = c.toString();
@@ -8903,9 +8912,14 @@
      try
      {
        BufferedWriter writer =
          new BufferedWriter(new FileWriter(file, false));
          new BufferedWriter(new FileWriter(file, true));
        writer.write(SHELL_COMMENT_SEPARATOR+getCurrentOperationDateMessage());
        writer.newLine();
        writer.write(commandBuilder.toString());
        writer.newLine();
        writer.newLine();
        writer.flush();
        writer.close();
@@ -8999,6 +9013,29 @@
      }
    }
    if (subcommandName.equals(
        ReplicationCliArgumentParser.DISABLE_REPLICATION_SUBCMD_NAME))
    {
      DisableReplicationUserData disableData =
        (DisableReplicationUserData)uData;
      if (disableData.disableAll())
      {
        commandBuilder.addArgument(new BooleanArgument(
            argParser.disableAllArg.getName(),
            argParser.disableAllArg.getShortIdentifier(),
            argParser.disableAllArg.getLongIdentifier(),
            INFO_DESCRIPTION_DISABLE_ALL.get()));
      }
      else if (disableData.disableReplicationServer())
      {
        commandBuilder.addArgument(new BooleanArgument(
            argParser.disableReplicationServerArg.getName(),
            argParser.disableReplicationServerArg.getShortIdentifier(),
            argParser.disableReplicationServerArg.getLongIdentifier(),
            INFO_DESCRIPTION_DISABLE_REPLICATION_SERVER.get()));
      }
    }
    addGlobalArguments(commandBuilder, uData);
    return commandBuilder;
  }