report any problematic web service URLs ( JAL-343 )
[jalview.git] / src / jalview / ws / jws2 / Jws2Discoverer.java
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;
+  }
+
 }