2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.jws1;
23 import jalview.util.MessageManager;
25 import java.util.Hashtable;
26 import java.util.StringTokenizer;
27 import java.util.Vector;
29 import javax.swing.JOptionPane;
31 import ext.vamsas.IRegistry;
32 import ext.vamsas.IRegistryServiceLocator;
33 import ext.vamsas.RegistryServiceSoapBindingStub;
34 import ext.vamsas.ServiceHandle;
35 import ext.vamsas.ServiceHandles;
37 public class Discoverer implements Runnable
39 ext.vamsas.IRegistry registry; // the root registry service.
41 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
45 * change listeners are notified of "services" property changes
48 * to be added that consumes new services Hashtable object.
50 public void addPropertyChangeListener(
51 java.beans.PropertyChangeListener listener)
53 changeSupport.addPropertyChangeListener(listener);
62 public void removePropertyChangeListener(
63 java.beans.PropertyChangeListener listener)
65 changeSupport.removePropertyChangeListener(listener);
69 * Property change listener firing routine
78 public void firePropertyChange(String prop, Object oldvalue,
81 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
85 * Initializes the server field with a valid service implementation.
87 * @return true if service was located.
89 private IRegistry locateWebService(java.net.URL WsURL)
91 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
92 IRegistry server = null;
95 server = loc.getRegistryService(WsURL);
96 ((RegistryServiceSoapBindingStub) server).setTimeout(60000); // One
99 } catch (Exception ex)
101 jalview.bin.Cache.log
102 .error("Serious! Service location failed\nfor URL :" + WsURL
108 loc.getEngine().setOption("axis", "1");
113 static private java.net.URL RootServiceURL = null;
115 static public Vector ServiceURLList = null;
117 static private boolean reallyDiscoverServices = true;
119 public static java.util.Hashtable services = null; // vectors of services
122 // abstractServiceType
125 public static java.util.Vector serviceList = null; // flat list of services
127 static private Vector getDiscoveryURLS()
129 Vector urls = new Vector();
130 String RootServiceURLs = jalview.bin.Cache
131 .getDefault("DISCOVERY_URLS",
132 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ServiceRegistry");
136 StringTokenizer st = new StringTokenizer(RootServiceURLs, ",");
137 while (st.hasMoreElements())
142 java.net.URL u = new java.net.URL(url = st.nextToken());
143 if (!urls.contains(u))
149 jalview.bin.Cache.log
150 .info("Ignoring duplicate url in DISCOVERY_URLS list");
152 } catch (Exception ex)
154 jalview.bin.Cache.log
155 .warn("Problem whilst trying to make a URL from '"
156 + ((url != null) ? url : "<null>") + "'");
157 jalview.bin.Cache.log
158 .warn("This was probably due to a malformed comma separated list"
159 + " in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
160 jalview.bin.Cache.log.debug("Exception was ", ex);
163 } catch (Exception ex)
165 jalview.bin.Cache.log
166 .warn("Error parsing comma separated list of urls in DISCOVERY_URLS.",
177 * fetch new services or reset to hardwired defaults depending on preferences.
179 static public void doDiscovery()
181 jalview.bin.Cache.log
182 .debug("(Re)-Initialising the discovery URL list.");
185 reallyDiscoverServices = jalview.bin.Cache.getDefault(
186 "DISCOVERY_START", false);
187 if (reallyDiscoverServices)
189 ServiceURLList = getDiscoveryURLS();
193 jalview.bin.Cache.log.debug("Setting default services");
194 services = new Hashtable();
195 // Muscle, Clustal and JPred.
196 ServiceHandle[] defServices = {
199 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment "
200 + "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
201 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
203 .getString("label.muscle_multiple_protein_sequence_alignment")),
206 "Katoh, K., K. Kuma, K., Toh, H., and Miyata, T. (2005) "
207 + "\"MAFFT version 5: improvement in accuracy of multiple sequence alignment.\""
208 + " Nucleic Acids Research, 33 511-518",
209 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MafftWS",
211 .getString("label.mafft_multiple_sequence_alignment")),
214 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple"
215 + " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice."
216 + " Nucleic Acids Research, 22 4673-4680",
217 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
219 .getString("label.clustalw_multiple_sequence_alignment")),
222 "Drozdetskiy A, Cole C, Procter J & Barton GJ. (2015)\nJPred4: a protein secondary structure prediction server"
223 + "\nNucleic Acids Research, Web Server issue (first published 15th April 2015)"
224 + "\ndoi://10.1093/nar/gkv332",
225 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
226 "JNet Secondary Structure Prediction") };
227 services = new Hashtable();
228 serviceList = new Vector();
229 buildServiceLists(defServices, serviceList, services);
232 } catch (Exception e)
235 .println("jalview.rootRegistry is not a proper url!\nWas set to "
236 + RootServiceURL + "\n" + e);
241 // TODO: JBPNote : make this discover more services based on list of
242 // discovery service urls, break cyclic references to the same url and
243 // duplicate service entries (same endpoint *and* same interface)
244 private ServiceHandle[] getServices(java.net.URL location)
246 ServiceHandles shs = null;
249 jalview.bin.Cache.log.debug("Discovering services using " + location);
250 shs = locateWebService(location).getServices();
251 } catch (org.apache.axis.AxisFault f)
253 // JBPNote - should do this a better way!
254 if (f.getFaultReason().indexOf("(407)") > -1)
256 if (jalview.gui.Desktop.desktop != null)
258 JOptionPane.showMessageDialog(jalview.gui.Desktop.desktop,
259 MessageManager.getString("label.set_proxy_settings"),
261 .getString("label.proxy_authorization_failed"),
262 JOptionPane.WARNING_MESSAGE);
267 jalview.bin.Cache.log.warn("No Discovery service at " + location);
268 jalview.bin.Cache.log.debug("Axis Fault", f);
270 } catch (Exception e)
272 jalview.bin.Cache.log.warn("No Discovery service at " + location);
273 jalview.bin.Cache.log.debug("Discovery Service General Exception", e);
275 if ((shs != null) && shs.getServices().length > 0)
277 return shs.getServices();
283 * Adds a list of services to the service catalog and categorised catalog
284 * returns true if ServiceURLList was modified with a new DiscoveryService URL
294 static private boolean buildServiceLists(ServiceHandle[] sh, Vector cat,
297 boolean seenNewDiscovery = false;
298 for (int i = 0, j = sh.length; i < j; i++)
300 if (!cat.contains(sh[i]))
302 jalview.bin.Cache.log.debug("A " + sh[i].getAbstractName()
303 + " service called " + sh[i].getName() + " exists at "
304 + sh[i].getEndpointURL() + "\n");
305 if (!sscat.containsKey(sh[i].getAbstractName()))
307 sscat.put(sh[i].getAbstractName(), cat = new Vector());
311 cat = (Vector) sscat.get(sh[i].getAbstractName());
314 if (sh[i].getAbstractName().equals("Registry"))
316 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
318 java.net.URL disc_serv = null;
321 disc_serv = new java.net.URL(sh[i].getEndpointURL());
322 if (!ServiceURLList.contains(disc_serv))
324 jalview.bin.Cache.log
325 .debug("Adding new discovery service at "
327 ServiceURLList.add(disc_serv);
328 seenNewDiscovery = true;
330 } catch (Exception e)
332 jalview.bin.Cache.log.debug(
333 "Ignoring bad discovery service URL "
334 + sh[i].getEndpointURL(), e);
340 return seenNewDiscovery;
343 public void discoverServices()
345 Hashtable sscat = new Hashtable();
346 Vector cat = new Vector();
347 ServiceHandle sh[] = null;
349 if (ServiceURLList == null)
351 jalview.bin.Cache.log
352 .debug("No service endpoints to use for service discovery.");
355 while (s_url < ServiceURLList.size())
357 if ((sh = getServices((java.net.URL) ServiceURLList.get(s_url))) != null)
360 buildServiceLists(sh, cat, sscat);
364 jalview.bin.Cache.log
365 .warn("No services at "
366 + (ServiceURLList.get(s_url))
367 + " - check DISCOVERY_URLS property in .jalview_properties");
371 // TODO: decide on correct semantics for services list - PropertyChange
372 // provides a way of passing the new object around
373 // so no need to access original discovery thread.
374 // Curent decision is to change properties then notify listeners with old
376 Hashtable oldServices = services;
377 // Vector oldServicelist = serviceList;
380 changeSupport.firePropertyChange("services", oldServices, services);
384 * creates a new thread to call discoverServices()
388 final Discoverer discoverer = this;
389 Thread discoverThread = new Thread()
393 discoverer.doDiscovery();
394 discoverer.discoverServices();
397 discoverThread.start();
401 * binding service abstract name to handler class
403 private static Hashtable serviceClientBindings;
405 public static WS1Client getServiceClient(ServiceHandle sh)
407 if (serviceClientBindings == null)
409 // get a list from Config or create below
410 serviceClientBindings = new Hashtable();
411 serviceClientBindings.put("MsaWS", new MsaWSClient());
412 serviceClientBindings.put("SecStrPred", new JPredClient());
413 serviceClientBindings.put("SeqSearch", new SeqSearchWSClient());
415 WS1Client instance = (WS1Client) serviceClientBindings.get(sh
417 if (instance == null)
420 .println("WARNING - POSSIBLE IMPLEMENTATION ERROR - cannot find WSClient implementation for "
421 + sh.getAbstractName());
425 instance.serviceHandle = sh;
430 * notes on discovery service 1. need to allow multiple discovery source urls.
431 * 2. user interface to add/control list of urls in preferences notes on
432 * wsclient discovery 1. need a classpath property with list of additional
433 * plugin directories 2. optional config to cite specific bindings between
434 * class name and Abstract service name. 3. precedence for automatic discovery
435 * by using getAbstractName for WSClient - user added plugins override default
436 * plugins ? notes on wsclient gui code for gui attachment now moved to
437 * wsclient implementation. Needs more abstraction but approach seems to work.
438 * is it possible to 'generalise' the data retrieval calls further ? current
439 * methods are very specific (gatherForMSA or gatherForSeqOrMsaSecStrPred),
440 * new methods for conservation (group or alignment), treecalc (aligned
441 * profile), seqannot (sequences selected from dataset, annotation back to