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

jvergara
09.57.2009 7202af24c668dba3f56c85a178bbe57c69d15691
Fix for issue 4224 (The error messages connecting to server are not consistent)

Create a method in org.opends.quicksetup.util.Utils to generate a method that generates a message.

8 files modified
204 ■■■■■ changed files
opends/src/guitools/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java 12 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/LoginPanel.java 5 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/uninstaller/ui/LoginDialog.java 2 ●●● patch | view | raw | blame | history
opends/src/messages/messages/admin_tool.properties 6 ●●●●● patch | view | raw | blame | history
opends/src/messages/messages/quicksetup.properties 17 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java 60 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/util/Utils.java 86 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/cli/ConsoleApplication.java 16 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
@@ -56,6 +56,7 @@
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import org.opends.admin.ads.ServerDescriptor;
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.guitools.controlpanel.datamodel.ConfigReadException;
@@ -556,17 +557,18 @@
                }
                else
                {
                  errors.add(ERR_CANNOT_CONNECT_TO_LOGIN_WITHOUT_CAUSE.get());
                  errors.add(Utils.getMessageForException(
                      (NamingException)throwable));
                }
                localServerErrorConnecting = true;
              }
              else
              {
                String msg = throwable.toString();
                errors.add(ERR_CANNOT_CONNECT_TO_REMOTE.get(
                String hostPort = ServerDescriptor.getServerRepresentation(
                    hostName.getText().trim(),
                    port.getText().trim(),
                    msg));
                    new Integer(port.getText().trim()));
                NamingException ne = (NamingException)throwable;
                errors.add(Utils.getMessageForException(ne, hostPort));
                setPrimaryInvalid(portLabel);
              }
              setPrimaryInvalid(dnLabel);
opends/src/guitools/org/opends/guitools/controlpanel/ui/LoginPanel.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 */
package org.opends.guitools.controlpanel.ui;
@@ -354,7 +354,8 @@
              }
              else
              {
                errors.add(ERR_CANNOT_CONNECT_TO_LOGIN_WITHOUT_CAUSE.get());
                errors.add(Utils.getMessageForException(
                    (NamingException)throwable));
              }
              setPrimaryInvalid(dnLabel);
opends/src/guitools/org/opends/guitools/uninstaller/ui/LoginDialog.java
@@ -533,7 +533,7 @@
            {
              // Generic message
              displayError(
                  ERR_CANNOT_CONNECT_TO_LOGIN_WITHOUT_CAUSE.get(),
                  Utils.getMessageForException((NamingException)throwable),
                  INFO_ERROR_TITLE.get());
            }
          }
opends/src/messages/messages/admin_tool.properties
@@ -59,12 +59,6 @@
INFO_CANCEL_BUTTON_UNINSTALL_TOOLTIP=Cancel Uninstall
MILD_ERR_CANNOT_CONNECT_TO_LOGIN_WITH_CAUSE=Could not connect to the Directory \
 Server with the provided credentials.  The possible causes for this are:%n%s
MILD_ERR_CANNOT_CONNECT_TO_LOGIN_WITHOUT_CAUSE=Could not connect to the Directory \
 Server with the provided credentials.%nCheck that the Administrative User DN \
 and password are valid.
MILD_ERR_CANNOT_CONNECT_WITH_ADS_CREDENTIALS_WITHOUT_CAUSE=Could not connect to \
 the Directory Server with the provided credentials.%nCheck that the \
 Administrative User ID and password are valid.
INFO_CLI_UNINSTALL_CONFIRM_BACKUPS=Remove Backup Files Contained in bak \
 Directory?
INFO_CLI_UNINSTALL_CONFIRM_CONFIGURATION_SCHEMA=Remove Configuration and \
opends/src/messages/messages/quicksetup.properties
@@ -80,13 +80,26 @@
 port could be already in use by another application or maybe you do not have \
 the rights to access it.
INFO_CANNOT_CONNECT_TO_REMOTE_AUTHENTICATION=The provided credentials are not \
 valid.
 valid in server %s.  Details: %s
INFO_CANNOT_CONNECT_TO_REMOTE_GENERIC=Could not connect to %s.  Check that the \
 server is running and that the provided credentials are valid.%nError \
 details:%n%s
SEVERE_ERR_CANNOT_CONNECT_TO_REMOTE_COMMUNICATION=Could not connect to the \
 remote server %s.  Check that the server is running and that is accessible \
 from the local machine.  Details: %s
INFO_CANNOT_CONNECT_TO_REMOTE_PERMISSIONS=You do not have enough access \
 rights to read the configuration in %s. %nProvide credentials with enough \
 rights.
 rights.  Details: %s
SEVERE_ERR_CANNOT_CONNECT_TO_LOCAL_AUTHENTICATION=The provided credentials are \
 not valid.  Details: %s
SEVERE_ERR_CANNOT_CONNECT_TO_LOCAL_GENERIC=Could not connect to the server.  \
 Check that the server is running and that the provided credentials are \
 valid.%nError details:%n%s
SEVERE_ERR_CANNOT_CONNECT_TO_LOCAL_COMMUNICATION=Could not connect to the \
 server.  Check that the server is running.  Details: %s
SEVERE_ERR_CANNOT_CONNECT_TO_LOCAL_PERMISSIONS=You do not have enough access \
 rights to read the configuration in the server. %nProvide credentials \
 with enough rights.  Details: %s
INFO_CANNOT_CONNECT_TO_SHUTDOWN_WITH_CAUSE=Could not connect to the Directory \
 Server with the provided credentials.  The possible causes for this are:%n%s
INFO_CANNOT_CONNECT_TO_SHUTDOWN_WITHOUT_CAUSE=Could not connect to the \
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -34,12 +34,11 @@
import java.util.logging.Logger;
import java.awt.event.WindowEvent;
import javax.naming.AuthenticationException;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.NoPermissionException;
import javax.naming.NamingSecurityException;
import javax.naming.directory.Attribute;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
@@ -2636,40 +2635,21 @@
        }
      }
    }
    catch (NoPermissionException ne)
    {
      if (isRemoteServer)
      {
        throw new ApplicationException(
                ReturnCode.CONFIGURATION_ERROR,
                INFO_CANNOT_CONNECT_TO_REMOTE_PERMISSIONS.get(
                        getHostDisplay(auth)), ne);
      }
      else
      {
        // TODO: INFO for local PERMISSIONS exception?
        Message failedMsg = getThrowableMsg(
                INFO_ERROR_CONNECTING_TO_LOCAL.get(), ne);
        throw new ApplicationException(
                ReturnCode.CONFIGURATION_ERROR,
                failedMsg, ne);
      }
    }
    catch (NamingException ne)
    {
      Message msg;
      if (isRemoteServer)
      {
        throw new ApplicationException(
                ReturnCode.CONFIGURATION_ERROR,
                INFO_CANNOT_CONNECT_TO_REMOTE_GENERIC.get(
                        getHostDisplay(auth), ne.toString(true)), ne);
        msg = Utils.getMessageForException(ne, getHostDisplay(auth));
      }
      else
      {
        throw new ApplicationException(
                ReturnCode.CONFIGURATION_ERROR,
                getThrowableMsg(INFO_ERROR_CONNECTING_TO_LOCAL.get(), ne), ne);
        msg = Utils.getMessageForException(ne);
      }
      throw new ApplicationException(
          ReturnCode.CONFIGURATION_ERROR,
          msg,
          ne);
    }
    catch (ADSContextException ace)
    {
@@ -3641,27 +3621,17 @@
                  host+":"+port, t.toString()));
        }
      }
      else if (t instanceof AuthenticationException)
      {
        errorMsgs.add(INFO_CANNOT_CONNECT_TO_REMOTE_AUTHENTICATION.get());
        qs.displayFieldInvalid(FieldName.REMOTE_SERVER_DN, true);
        qs.displayFieldInvalid(FieldName.REMOTE_SERVER_PWD, true);
      }
      else if (t instanceof NoPermissionException)
      {
        errorMsgs.add(INFO_CANNOT_CONNECT_TO_REMOTE_PERMISSIONS.get(
                  host+":"+port));
        qs.displayFieldInvalid(FieldName.REMOTE_SERVER_DN, true);
        qs.displayFieldInvalid(FieldName.REMOTE_SERVER_PWD, true);
      }
      else if (t instanceof NamingException)
      {
        errorMsgs.add(INFO_CANNOT_CONNECT_TO_REMOTE_GENERIC.get(
                host+":"+port, ((NamingException)t).toString(true)));
        qs.displayFieldInvalid(FieldName.REMOTE_SERVER_HOST, true);
        qs.displayFieldInvalid(FieldName.REMOTE_SERVER_PORT, true);
        errorMsgs.add(Utils.getMessageForException((NamingException)t,
            host+":"+port));
        qs.displayFieldInvalid(FieldName.REMOTE_SERVER_DN, true);
        qs.displayFieldInvalid(FieldName.REMOTE_SERVER_PWD, true);
        if (!(t instanceof NamingSecurityException))
        {
          qs.displayFieldInvalid(FieldName.REMOTE_SERVER_HOST, true);
          qs.displayFieldInvalid(FieldName.REMOTE_SERVER_PORT, true);
        }
      }
      else if (t instanceof ADSContextException)
      {
opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
@@ -48,8 +48,12 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.AuthenticationException;
import javax.naming.CommunicationException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.NamingSecurityException;
import javax.naming.NoPermissionException;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
@@ -1122,6 +1126,88 @@
  }
  /**
   * Returns a message object for the given NamingException.
   * @param ne the NamingException.
   * @param hostPort the hostPort representation of the server we were
   * contacting when the NamingException occurred.
   * @return a message object for the given NamingException.
   */
  public static Message getMessageForException(NamingException ne,
      String hostPort)
  {
    Message msg;
    if (Utils.isCertificateException(ne))
    {
      msg = INFO_ERROR_READING_CONFIG_LDAP_CERTIFICATE_SERVER.get(
              hostPort, ne.toString(true));
    }
    else if (ne instanceof AuthenticationException)
    {
      msg = INFO_CANNOT_CONNECT_TO_REMOTE_AUTHENTICATION.get(hostPort,
          ne.toString(true));
    }
    else if (ne instanceof NoPermissionException)
    {
      msg = INFO_CANNOT_CONNECT_TO_REMOTE_PERMISSIONS.get(hostPort,
          ne.toString(true));
    }
    else if (ne instanceof NamingSecurityException)
    {
      msg = INFO_CANNOT_CONNECT_TO_REMOTE_PERMISSIONS.get(hostPort,
          ne.toString(true));
    }
    else if (ne instanceof CommunicationException)
    {
      msg = ERR_CANNOT_CONNECT_TO_REMOTE_COMMUNICATION.get(
          hostPort, ne.toString(true));
    }
    else
    {
       msg = INFO_CANNOT_CONNECT_TO_REMOTE_GENERIC.get(
          hostPort, ne.toString(true));
    }
    return msg;
  }
  /**
   * Returns a message object for the given NamingException.  The code assume
   * that we are trying to connect to the local server.
   * @param ne the NamingException.
   * @return a message object for the given NamingException.
   */
  public static Message getMessageForException(NamingException ne)
  {
    Message msg;
    if (Utils.isCertificateException(ne))
    {
      msg = INFO_ERROR_READING_CONFIG_LDAP_CERTIFICATE.get(ne.toString(true));
    }
    else if (ne instanceof AuthenticationException)
    {
      msg = ERR_CANNOT_CONNECT_TO_LOCAL_AUTHENTICATION.get(ne.toString(true));
    }
    else if (ne instanceof NoPermissionException)
    {
      msg = ERR_CANNOT_CONNECT_TO_LOCAL_PERMISSIONS.get(ne.toString(true));
    }
    else if (ne instanceof NamingSecurityException)
    {
      msg = ERR_CANNOT_CONNECT_TO_LOCAL_PERMISSIONS.get(ne.toString(true));
    }
    else if (ne instanceof CommunicationException)
    {
      msg = ERR_CANNOT_CONNECT_TO_LOCAL_COMMUNICATION.get(ne.toString(true));
    }
    else
    {
       msg = ERR_CANNOT_CONNECT_TO_LOCAL_GENERIC.get(ne.toString(true));
    }
    return msg;
  }
  /**
   * Returns the default LDAP timeout in milliseconds when we try to connect to
   * a server.
   * @return the default LDAP timeout in milliseconds when we try to connect to
opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
@@ -654,20 +654,10 @@
   * contacting when the NamingException occurred.
   * @return a message object for the given NamingException.
   */
  protected Message getMessageForException(NamingException ne, String hostPort)
  protected Message getMessageForException(NamingException ne,
      String hostPort)
  {
    Message msg;
    if (Utils.isCertificateException(ne))
    {
      msg = INFO_ERROR_READING_CONFIG_LDAP_CERTIFICATE_SERVER.get(
              hostPort, ne.toString(true));
    }
    else
    {
       msg = INFO_CANNOT_CONNECT_TO_REMOTE_GENERIC.get(
          hostPort, ne.toString(true));
    }
    return msg;
    return Utils.getMessageForException(ne, hostPort);
  }
  /**