#5209 Beautify error messages related to connection / access to remote server
authorCherian Mathew <c.mathew@bgbm.org>
Thu, 26 Nov 2015 14:15:59 +0000 (15:15 +0100)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 26 Nov 2015 14:15:59 +0000 (15:15 +0100)
eu.etaxonomy.taxeditor.application/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/CdmErrorDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MessagingUtils.java

index 1d3e864..2048106 100644 (file)
@@ -14,7 +14,8 @@ Import-Package: eu.etaxonomy.cdm.database,
  org.eclipse.equinox.app,
  org.eclipse.equinox.p2.repository.metadata,
  org.osgi.framework,
- org.osgi.service.packageadmin
+ org.osgi.service.packageadmin,
+ org.springframework.remoting
 Require-Bundle: org.eclipse.ui,
  org.eclipse.core.runtime,
  eu.etaxonomy.taxeditor.store,
index f02297f..51828f2 100644 (file)
@@ -8,6 +8,8 @@ import org.eclipse.ui.application.WorkbenchAdvisor;
 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
 import org.eclipse.ui.statushandlers.AbstractStatusHandler;
 import org.eclipse.ui.statushandlers.StatusAdapter;
+import org.springframework.remoting.RemoteAccessException;
+import org.springframework.remoting.RemoteConnectFailureException;
 
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 
@@ -22,6 +24,7 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
 public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
 
        private CdmStatusHandler cdmStatusHandler;
+
        /*
         * (non-Javadoc)
         * @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
@@ -88,31 +91,73 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
         */
        class CdmStatusHandler extends AbstractStatusHandler {
 
+           private Throwable previousT;
                /* (non-Javadoc)
                 * @see org.eclipse.ui.statushandlers.AbstractStatusHandler#handle(org.eclipse.ui.statushandlers.StatusAdapter, int)
                 */
                @Override
                public void handle(StatusAdapter statusAdapter, int style)
                {
+
                    if(statusAdapter.getStatus().matches(IStatus.ERROR)) {
 
                        IStatus status = statusAdapter.getStatus();
                        Throwable t = statusAdapter.getStatus().getException();
+                       // NOTE : the global status handling mechanism in the case of
+                       //        runtime exceptions is called twice, once by the application
+                       //        throwing the exception and then by the rcp logging mechanism
+                       //        The check below is to make sure that the same exception is
+                       //        not shown twice in succession.
+                       if(t != null && previousT == t) {
+                       return;
+                   }
+                       previousT = t;
                        // NOTE : Currently we only allow RuntimeExceptions since
                        //        allowing all kinds of exceptions would also include
                        //        those in generated status objects coming from from logging triggers
                        //        leading to a recursive infinite loop of :
                        //        initial exception thrown -> status handling -> dialog opening + logging of status ->
                        //        status handling -> dialog opening + logging of status ... and so on
-                       if(t != null && t instanceof RuntimeException && ! "Widget is disposed".equals(t.getMessage())){
-                               MessagingUtils.errorDialog("Unexpected error",
-                                               null,
-                                               MessagingUtils.UNEXPECTED_ERROR_MESSAGE,
-                                               statusAdapter.getStatus().getPlugin(),
-                                               t,
-                                               true);
-                       }
+                       if(t != null &&
+                               t instanceof RuntimeException &&
+                               ! "Widget is disposed".equals(t.getMessage()) &&
+                               ! handleKnownRuntimeException(t,statusAdapter.getStatus().getPlugin())) {
+
+                           MessagingUtils.errorDialog("Unexpected error",
+                                   null,
+                                   MessagingUtils.UNEXPECTED_ERROR_MESSAGE,
+                                   statusAdapter.getStatus().getPlugin(),
+                                   t,
+                                   true);
+
+                       }
+                   }
+               }
+
+               private boolean handleKnownRuntimeException(Throwable t, String pluginId) {
+                   if(t instanceof RemoteConnectFailureException ||
+                           t.getCause() instanceof RemoteConnectFailureException) {
+                       MessagingUtils.errorDialog("Connection Failure",
+                               null,
+                               MessagingUtils.CONNECTION_FAILURE_MESSAGE + System.getProperty("line.separator"),
+                               pluginId,
+                               t,
+                               true,
+                               false);
+                       return true;
+                   }
+                   if(t instanceof RemoteAccessException ||
+                           t.getCause() instanceof RemoteAccessException) {
+                       MessagingUtils.errorDialog("Remote Access Error",
+                               null,
+                               MessagingUtils.REMOTE_ACCESS_FAILURE_MESSAGE + System.getProperty("line.separator"),
+                               pluginId,
+                               t,
+                               true,
+                               false);
+                       return true;
                    }
+                   return false;
                }
        }
 
index 087fa83..8e39946 100644 (file)
@@ -47,33 +47,20 @@ public      class CdmErrorDialog extends ErrorDialog {
             String dialogTitle,
             String message,
             IStatus status,
-            String stackTrace) {
+            String stackTrace,
+            boolean showStatusMessage) {
         super(parentShell,
                 dialogTitle,
                 message, status,
                 IStatus.OK| IStatus.INFO | IStatus.WARNING | IStatus.ERROR);
         this.stackTrace = stackTrace;
-
-
+        String statusMessage = "";
+        if(showStatusMessage) {
+            statusMessage = status.getMessage();
+        }
+        this.message = message == null ? statusMessage : message + "\n " + statusMessage;
     }
 
-    /**
-     * @param parentShell
-     * @param dialogTitle
-     * @param message
-     * @param status
-     * @param stackTrace
-     */
-    public CdmErrorDialog(Shell parentShell,
-            String dialogTitle,
-            String message,
-            IStatus status,
-            String stackTrace,
-            Object[] updatedObjects) {
-        this(parentShell, dialogTitle, message, status, stackTrace);
-        this.message = message == null ? status.getMessage()
-                : message + "\n " + status.getMessage(); //$NON-NLS-1$
-    }
 
     /**
      * @param parentShell
@@ -85,7 +72,7 @@ public        class CdmErrorDialog extends ErrorDialog {
             String dialogTitle,
             String message,
             IStatus status) {
-        this(parentShell, dialogTitle, message, status, "");
+        this(parentShell, dialogTitle, message, status, "", true);
     }
 
        /* (non-Javadoc)
index 36777e8..3988724 100644 (file)
@@ -31,6 +31,8 @@ public class MessagingUtils {
     public final static String UNEXPECTED_ERROR_MESSAGE = "This is an unexpected error.";
     public final static String CONTACT_MESSAGE = System.getProperty("line.separator") +  "Please contact EDIT Support (EditSupport@bgbm.org) with the error trace below (click on the 'Details' button).";
     public final static String DEFAULT_MESSAGE = "Error thrown but no associated message";
+    public final static String CONNECTION_FAILURE_MESSAGE = "The connection to the remote server has been broken";
+    public final static String REMOTE_ACCESS_FAILURE_MESSAGE = "Problem accessing remote server";
 
     /**
      * Gets the Log4J logger for a given class
@@ -253,14 +255,15 @@ public class MessagingUtils {
             final Throwable t,
             final List<String> contextInfo,
             final String message,
-            final MultiStatus status) {
+            final MultiStatus status,
+            final boolean showReason) {
 
         Display.getDefault().asyncExec(new Runnable() {
 
             @Override
             public void run() {
                 String stackTraceWithContext = getStackTraceAndContextInfo(t, contextInfo);
-                CdmErrorDialog ced = new CdmErrorDialog(AbstractUtility.getShell(), title, message, status, stackTraceWithContext);
+                CdmErrorDialog ced = new CdmErrorDialog(AbstractUtility.getShell(), title, message, status, stackTraceWithContext, showReason);
                 ced.open();
                 Class<? extends Object> clazz = source != null ? source.getClass() : this.getClass();
 
@@ -275,6 +278,15 @@ public class MessagingUtils {
         });
     }
 
+    public static void errorDialog(final String title,
+            final Object source,
+            final String message,
+            final String pluginId,
+            final Throwable t,
+            boolean addContactMesg) {
+        errorDialog(title, source, message, pluginId, t, addContactMesg, true);
+
+    }
     /**
      * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
      *
@@ -289,7 +301,8 @@ public class MessagingUtils {
             final String message,
             final String pluginId,
             final Throwable t,
-            boolean addContactMesg) {
+            boolean addContactMesg,
+            boolean showReason) {
 
         Throwable throwable = t;
         StringBuffer sbStackTrace = new StringBuffer();
@@ -356,7 +369,7 @@ public class MessagingUtils {
                 throwable.toString(),
                 throwable);
 
-        errorDialog(title, source, throwable, contextInfo, finalMessage, ms);
+        errorDialog(title, source, throwable, contextInfo, finalMessage, ms, showReason);
     }
 
     /**