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.bin.Cache;
24 import jalview.bin.Console;
25 import jalview.gui.JvOptionPane;
26 import jalview.util.MessageManager;
29 import java.util.Hashtable;
30 import java.util.StringTokenizer;
31 import java.util.Vector;
33 import ext.vamsas.IRegistry;
34 import ext.vamsas.IRegistryServiceLocator;
35 import ext.vamsas.RegistryServiceSoapBindingStub;
36 import ext.vamsas.ServiceHandle;
37 import ext.vamsas.ServiceHandles;
39 public class Discoverer implements Runnable
41 ext.vamsas.IRegistry registry; // the root registry service.
43 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
47 * change listeners are notified of "services" property changes
50 * to be added that consumes new services Hashtable object.
52 public void addPropertyChangeListener(
53 java.beans.PropertyChangeListener listener)
55 changeSupport.addPropertyChangeListener(listener);
64 public void removePropertyChangeListener(
65 java.beans.PropertyChangeListener listener)
67 changeSupport.removePropertyChangeListener(listener);
71 * Property change listener firing routine
80 public void firePropertyChange(String prop, Object oldvalue,
83 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
87 * Initializes the server field with a valid service implementation.
89 * @return true if service was located.
91 private IRegistry locateWebService(java.net.URL WsURL)
93 IRegistryServiceLocator loc = new IRegistryServiceLocator(); // Default
94 IRegistry server = null;
97 server = loc.getRegistryService(WsURL);
98 ((RegistryServiceSoapBindingStub) server).setTimeout(60000); // One
101 } catch (Exception ex)
104 "Serious! Service location failed\nfor URL :" + WsURL + "\n",
110 loc.getEngine().setOption("axis", "1");
115 static private java.net.URL RootServiceURL = null;
117 static public Vector<URL> ServiceURLList = null;
119 static private boolean reallyDiscoverServices = true;
121 public static java.util.Hashtable<String, Vector<ServiceHandle>> services = null;
123 // abstractServiceType
126 public static java.util.Vector<ServiceHandle> serviceList = null;
128 static private Vector<URL> getDiscoveryURLS()
130 Vector<URL> urls = new Vector<>();
131 String RootServiceURLs = Cache.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 Console.info("Ignoring duplicate url in DISCOVERY_URLS list");
151 } catch (Exception ex)
153 Console.warn("Problem whilst trying to make a URL from '"
154 + ((url != null) ? url : "<null>") + "'");
156 "This was probably due to a malformed comma separated list"
157 + " in the DISCOVERY_URLS entry of $(HOME)/.jalview_properties)");
158 Console.debug("Exception was ", ex);
161 } catch (Exception ex)
164 "Error parsing comma separated list of urls in DISCOVERY_URLS.",
175 * fetch new services or reset to hardwired defaults depending on preferences.
177 static public void doDiscovery()
179 Console.debug("(Re)-Initialising the discovery URL list.");
182 reallyDiscoverServices = Cache.getDefault("DISCOVERY_START", false);
183 if (reallyDiscoverServices)
185 ServiceURLList = getDiscoveryURLS();
189 Console.debug("Setting default services");
190 services = new Hashtable<>();
191 // Muscle, Clustal and JPred.
192 ServiceHandle[] defServices = { new ServiceHandle("MsaWS",
193 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment "
194 + "with high accuracy and high throughput, Nucleic Acids Research 32(5), 1792-97.",
195 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MuscleWS",
196 MessageManager.getString(
197 "label.muscle_multiple_protein_sequence_alignment")),
198 new ServiceHandle("MsaWS",
199 "Katoh, K., K. Kuma, K., Toh, H., and Miyata, T. (2005) "
200 + "\"MAFFT version 5: improvement in accuracy of multiple sequence alignment.\""
201 + " Nucleic Acids Research, 33 511-518",
202 "http://www.compbio.dundee.ac.uk/JalviewWS/services/MafftWS",
203 MessageManager.getString(
204 "label.mafft_multiple_sequence_alignment")),
205 new ServiceHandle("MsaWS",
206 "Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple"
207 + " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice."
208 + " Nucleic Acids Research, 22 4673-4680",
209 "http://www.compbio.dundee.ac.uk/JalviewWS/services/ClustalWS",
210 MessageManager.getString(
211 "label.clustalw_multiple_sequence_alignment")),
212 new ServiceHandle("SecStrPred",
213 "Drozdetskiy A, Cole C, Procter J & Barton GJ. (2015)\nJPred4: a protein secondary structure prediction server"
214 + "\nNucleic Acids Research, Web Server issue (first published 15th April 2015)"
215 + "\ndoi://10.1093/nar/gkv332",
216 "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
217 "JPred Secondary Structure Prediction") };
218 services = new Hashtable<>();
219 serviceList = new Vector<>();
220 buildServiceLists(defServices, serviceList, services);
223 } catch (Exception e)
226 "jalview.rootRegistry is not a proper url!\nWas set to "
227 + RootServiceURL + "\n" + e);
232 // TODO: JBPNote : make this discover more services based on list of
233 // discovery service urls, break cyclic references to the same url and
234 // duplicate service entries (same endpoint *and* same interface)
235 private ServiceHandle[] getServices(java.net.URL location)
237 ServiceHandles shs = null;
240 Console.debug("Discovering services using " + location);
241 shs = locateWebService(location).getServices();
242 } catch (org.apache.axis.AxisFault f)
244 // JBPNote - should do this a better way!
245 if (f.getFaultReason().indexOf("(407)") > -1)
247 if (jalview.gui.Desktop.desktop != null)
249 JvOptionPane.showMessageDialog(jalview.gui.Desktop.desktop,
250 MessageManager.getString("label.set_proxy_settings"),
252 .getString("label.proxy_authorization_failed"),
253 JvOptionPane.WARNING_MESSAGE);
258 Console.warn("No Discovery service at " + location);
259 Console.debug("Axis Fault", f);
261 } catch (Exception e)
263 Console.warn("No Discovery service at " + location);
264 Console.debug("Discovery Service General Exception", e);
266 if ((shs != null) && shs.getServices().length > 0)
268 return shs.getServices();
274 * Adds a list of services to the service catalog and categorised catalog
275 * returns true if ServiceURLList was modified with a new DiscoveryService URL
285 static private boolean buildServiceLists(ServiceHandle[] sh,
286 Vector<ServiceHandle> cat,
287 Hashtable<String, Vector<ServiceHandle>> sscat)
289 boolean seenNewDiscovery = false;
290 for (int i = 0, j = sh.length; i < j; i++)
292 if (!cat.contains(sh[i]))
294 Console.debug("A " + sh[i].getAbstractName() + " service called "
295 + sh[i].getName() + " exists at " + sh[i].getEndpointURL()
297 if (!sscat.containsKey(sh[i].getAbstractName()))
299 sscat.put(sh[i].getAbstractName(), cat = new Vector<>());
303 cat = sscat.get(sh[i].getAbstractName());
306 if (sh[i].getAbstractName().equals("Registry"))
308 for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
310 java.net.URL disc_serv = null;
313 disc_serv = new java.net.URL(sh[i].getEndpointURL());
314 if (!ServiceURLList.contains(disc_serv))
317 "Adding new discovery service at " + disc_serv);
318 ServiceURLList.add(disc_serv);
319 seenNewDiscovery = true;
321 } catch (Exception e)
323 Console.debug("Ignoring bad discovery service URL "
324 + sh[i].getEndpointURL(), e);
330 return seenNewDiscovery;
333 public void discoverServices()
335 Hashtable<String, Vector<ServiceHandle>> sscat = new Hashtable<>();
336 Vector<ServiceHandle> cat = new Vector<>();
337 ServiceHandle sh[] = null;
339 if (ServiceURLList == null)
341 Console.debug("No service endpoints to use for service discovery.");
344 while (s_url < ServiceURLList.size())
346 if ((sh = getServices(ServiceURLList.get(s_url))) != null)
349 buildServiceLists(sh, cat, sscat);
353 Console.warn("No services at " + (ServiceURLList.get(s_url))
354 + " - check DISCOVERY_URLS property in .jalview_properties");
358 // TODO: decide on correct semantics for services list - PropertyChange
359 // provides a way of passing the new object around
360 // so no need to access original discovery thread.
361 // Curent decision is to change properties then notify listeners with old
363 Hashtable<String, Vector<ServiceHandle>> oldServices = services;
364 // Vector oldServicelist = serviceList;
367 changeSupport.firePropertyChange("services", oldServices, services);
371 * creates a new thread to call discoverServices()
376 final Discoverer discoverer = this;
377 Thread discoverThread = new Thread()
382 Discoverer.doDiscovery();
383 discoverer.discoverServices();
386 discoverThread.start();
390 * binding service abstract name to handler class
392 private static Hashtable<String, WS1Client> serviceClientBindings;
394 public static WS1Client getServiceClient(ServiceHandle sh)
396 if (serviceClientBindings == null)
398 // get a list from Config or create below
399 serviceClientBindings = new Hashtable<>();
400 serviceClientBindings.put("MsaWS", new MsaWSClient());
401 serviceClientBindings.put("SecStrPred", new JPredClient());
402 serviceClientBindings.put("SeqSearch", new SeqSearchWSClient());
404 WS1Client instance = serviceClientBindings.get(sh.getAbstractName());
405 if (instance == null)
408 "WARNING - POSSIBLE IMPLEMENTATION ERROR - cannot find WSClient implementation for "
409 + sh.getAbstractName());
413 instance.serviceHandle = sh;
418 * notes on discovery service 1. need to allow multiple discovery source urls.
419 * 2. user interface to add/control list of urls in preferences notes on
420 * wsclient discovery 1. need a classpath property with list of additional
421 * plugin directories 2. optional config to cite specific bindings between
422 * class name and Abstract service name. 3. precedence for automatic discovery
423 * by using getAbstractName for WSClient - user added plugins override default
424 * plugins ? notes on wsclient gui code for gui attachment now moved to
425 * wsclient implementation. Needs more abstraction but approach seems to work.
426 * is it possible to 'generalise' the data retrieval calls further ? current
427 * methods are very specific (gatherForMSA or gatherForSeqOrMsaSecStrPred),
428 * new methods for conservation (group or alignment), treecalc (aligned
429 * profile), seqannot (sequences selected from dataset, annotation back to