report any problematic web service URLs ( JAL-343 )
authorjprocter <Jim Procter>
Thu, 4 Nov 2010 12:41:52 +0000 (12:41 +0000)
committerjprocter <Jim Procter>
Thu, 4 Nov 2010 12:41:52 +0000 (12:41 +0000)
src/jalview/gui/Desktop.java
src/jalview/ws/jws2/JabaWsServerQuery.java
src/jalview/ws/jws2/Jws2Discoverer.java

index 6228afb..2484ba8 100755 (executable)
@@ -25,6 +25,7 @@ import java.awt.*;
 import java.awt.datatransfer.*;
 import java.awt.dnd.*;
 import java.awt.event.*;
+import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
@@ -306,6 +307,20 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         Cache.log.debug("Filechooser init thread finished.");
       }
     }).start();
+    // Add the service change listener
+    changeSupport.addJalviewPropertyChangeListener("services",
+            new PropertyChangeListener()
+            {
+
+              @Override
+              public void propertyChange(PropertyChangeEvent evt)
+              {
+                Cache.log.debug("Firing service changed event for "
+                        + evt.getNewValue());
+                JalviewServicesChanged(evt);
+              }
+
+            });
   }
 
   /**
@@ -2132,10 +2147,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     }
     if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
     {
-      if (jalview.ws.jws2.Jws2Discoverer.getDiscoverer().isRunning()) {
+      if (jalview.ws.jws2.Jws2Discoverer.getDiscoverer().isRunning())
+      {
         jalview.ws.jws2.Jws2Discoverer.getDiscoverer().setAborted(true);
       }
-      t2=jalview.ws.jws2.Jws2Discoverer.getDiscoverer().startDiscoverer(changeSupport);
+      t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer().startDiscoverer(
+              changeSupport);
       
     }
     if (blocking)
@@ -2156,6 +2173,46 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   }
 
   /**
+   * called to check if the service discovery process completed successfully.
+   * 
+   * @param evt
+   */
+  protected void JalviewServicesChanged(PropertyChangeEvent evt)
+  {
+    if (evt.getNewValue() instanceof Vector)
+    {
+      final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
+              .getErrorMessages();
+      if (ermsg != null)
+      {
+        if (serviceChangedDialog == null)
+        {
+          // only run if we aren't already displaying one of these.
+          javax.swing.SwingUtilities
+                  .invokeLater(serviceChangedDialog = new Runnable()
+                  {
+                    public void run()
+                    {
+
+                      JOptionPane
+                              .showInternalMessageDialog(
+                                      Desktop.desktop,
+                                      ermsg
+                                              + "\nPlease check the web services preferences.\n",
+                                      "Preferences Problem",
+                                      JOptionPane.WARNING_MESSAGE);
+                      serviceChangedDialog = null;
+
+                    }
+                  });
+        }
+      }
+    }
+  }
+
+  private Runnable serviceChangedDialog = null;
+
+  /**
    * start a thread to open a URL in the configured browser. Pops up a warning
    * dialog to the user if there is an exception when calling out to the browser
    * to open the URL.
index 5ca5065..2799e98 100644 (file)
@@ -53,6 +53,7 @@ public class JabaWsServerQuery implements Runnable
     {
       if (Jws2Client.validURL(jwsservers))
       {
+        boolean noservices=true;
         // look for services
         for (Services srv : Services.values())
         {
@@ -74,26 +75,35 @@ public class JabaWsServerQuery implements Runnable
             {
               e.printStackTrace();
             }
+            // For moment, report service as a problem.
+            jws2Discoverer.addInvalidServiceUrl(jwsservers);
           }
           ;
           if (service != null)
           {
+            noservices=false;
             jws2Discoverer.addService(jwsservers, srv, service);
           }
         }
-
+        if (noservices)
+        {
+          jws2Discoverer.addUrlwithnoservices(jwsservers);
+        }
       }
       else
       {
+        jws2Discoverer.addInvalidServiceUrl(jwsservers);
         Cache.log.info("Ignoring invalid Jws2 service url " + jwsservers);
       }
     } catch (Exception e)
     {
       e.printStackTrace();
       Cache.log.warn("Exception when discovering Jws2 services.", e);
+      jws2Discoverer.addInvalidServiceUrl(jwsservers);
     } catch (Error e)
     {
       Cache.log.error("Exception when discovering Jws2 services.", e);
+      jws2Discoverer.addInvalidServiceUrl(jwsservers);
     }
     running=false;
   }
index 8cc39d7..8089e1a 100644 (file)
@@ -93,6 +93,14 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
   boolean running = false, aborted = false;
 
   /**
+   * @return the aborted
+   */
+  public boolean isAborted()
+  {
+    return aborted;
+  }
+
+  /**
    * @param aborted
    *          the aborted to set
    */
@@ -134,15 +142,25 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     } catch (ClassNotFoundException e)
     {
       System.err
-              .println("Not enabling Jalview Webservices version 2: client jar is not available."
+              .println("Not enabling JABA Webservices : client jar is not available."
                       + "\nPlease check that your webstart JNLP file is up to date!");
       running = false;
       return;
     }
+    // reinitialise records of good and bad service URLs
     if (services != null)
     {
       services.removeAllElements();
     }
+    if (urlsWithoutServices != null)
+    {
+      urlsWithoutServices.removeAllElements();
+    }
+    if (invalidServiceUrls != null)
+    {
+      invalidServiceUrls.removeAllElements();
+    }
+
     List<JabaWsServerQuery> qrys = new ArrayList<JabaWsServerQuery>();
     for (final String jwsservers : getServiceUrls())
     {
@@ -486,13 +504,15 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
 
   public static void main(String[] args)
   {
-    Thread runner = getDiscoverer().startDiscoverer(new PropertyChangeListener()
+    Thread runner = getDiscoverer().startDiscoverer(
+            new PropertyChangeListener()
     {
 
       public void propertyChange(PropertyChangeEvent evt)
       {
         if (getDiscoverer().services!=null)
-          {System.out.println("Changesupport: There are now "
+                {
+                  System.out.println("Changesupport: There are now "
                 + getDiscoverer().services.size() + " services");
           
           }
@@ -626,19 +646,25 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
       { "-h=" + foo.toString() });
     } catch (Exception e)
     {
+      e.printStackTrace();
       return false;
     } catch (OutOfMemoryError e)
     {
+      e.printStackTrace();
       return false;
     } catch (Error e)
     {
+      e.printStackTrace();
       return false;
     }
     return true;
   }
 
   /**
-   * Start a fresh discovery thread and notify the given object when we're finished. Any known existing threads will be killed before this one is started. 
+   * Start a fresh discovery thread and notify the given object when we're
+   * finished. Any known existing threads will be killed before this one is
+   * started.
+   * 
    * @param changeSupport2
    * @return new thread
    */
@@ -654,4 +680,107 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     return thr;
   }
 
+  Vector<String> invalidServiceUrls = null, urlsWithoutServices = null;
+
+  /**
+   * @return the invalidServiceUrls
+   */
+  public Vector<String> getInvalidServiceUrls()
+  {
+    return invalidServiceUrls;
+  }
+
+  /**
+   * @return the urlsWithoutServices
+   */
+  public Vector<String> getUrlsWithoutServices()
+  {
+    return urlsWithoutServices;
+  }
+
+  /**
+   * add an 'empty' JABA server to the list
+   * 
+   * @param jwsservers
+   */
+  public synchronized void addUrlwithnoservices(String jwsservers)
+  {
+    if (urlsWithoutServices == null)
+    {
+      urlsWithoutServices = new Vector<String>();
+    }
+    if (!urlsWithoutServices.contains(jwsservers))
+    {
+      urlsWithoutServices.add(jwsservers);
+    }
+  }
+
+  /**
+   * add a bad URL to the list
+   * 
+   * @param jwsservers
+   */
+  public synchronized void addInvalidServiceUrl(String jwsservers)
+  {
+    if (invalidServiceUrls == null)
+    {
+      invalidServiceUrls = new Vector<String>();
+    }
+    if (!invalidServiceUrls.contains(jwsservers))
+    {
+      invalidServiceUrls.add(jwsservers);
+    }
+  }
+
+  /**
+   * 
+   * @return a human readable report of any problems with the service URLs used
+   *         for discovery
+   */
+  public String getErrorMessages()
+  {
+    if (!isRunning() && !isAborted())
+    {
+      StringBuffer ermsg = new StringBuffer();
+      boolean list = false;
+      if (getInvalidServiceUrls() != null
+              && getInvalidServiceUrls().size() > 0)
+      {
+        ermsg.append("Invalid Service URLS: \n");
+        for (String svcurl : getInvalidServiceUrls())
+        {
+          if (list)
+          {
+            ermsg.append(", ");
+          }
+          list = true;
+          ermsg.append(svcurl);
+        }
+        ermsg.append("\n\n");
+      }
+      list = false;
+      if (getUrlsWithoutServices() != null
+              && getUrlsWithoutServices().size() > 0)
+      {
+        ermsg.append("URLs without any JABA Services : \n");
+        for (String svcurl : getUrlsWithoutServices())
+        {
+          if (list)
+          {
+            ermsg.append(", ");
+          }
+          list = true;
+          ermsg.append(svcurl);
+        }
+        ermsg.append("\n");
+      }
+      if (ermsg.length() > 1)
+      {
+        return ermsg.toString();
+      }
+
+    }
+    return null;
+  }
+
 }