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.
24 package jalview.ws.jws2;
26 import jalview.bin.Console;
27 import jalview.ws.jws2.jabaws2.Jws2Instance;
28 import jalview.ws.jws2.jabaws2.Jws2InstanceFactory;
30 import java.io.IOException;
31 import java.net.MalformedURLException;
33 import java.util.HashSet;
36 import compbio.data.msa.Category;
37 import compbio.data.msa.JABAService;
38 import compbio.ws.client.Jws2Client;
39 import compbio.ws.client.Services;
45 public class JabaWsServerQuery implements Runnable
48 Jws2Discoverer jws2Discoverer = null;
50 String jwsserver = null;
52 boolean quit = false, running = false;
57 public boolean isRunning()
66 public void setQuit(boolean quit)
71 public JabaWsServerQuery(Jws2Discoverer jws2Discoverer, String server)
73 this.jws2Discoverer = jws2Discoverer;
74 this.jwsserver = server;
77 Services[] JABAWS1SERVERS = new Services[] { Services.ClustalWS,
78 Services.MuscleWS, Services.MafftWS, Services.ProbconsWS,
81 Services[] JABAWS2SERVERS = new Services[] { Services.ClustalWS,
82 Services.MuscleWS, Services.MafftWS, Services.ProbconsWS,
83 Services.TcoffeeWS, Services.AAConWS, Services.DisemblWS,
84 Services.GlobPlotWS, Services.IUPredWS, Services.JronnWS,
85 Services.RNAalifoldWS };
90 * @see java.lang.Runnable#run()
98 // TODO this test doesn't seem to attempt a connection - should it?
99 // would save a lot of failed tries with UnknownHostException
100 if (isValidUrl(jwsserver))
102 compbio.data.msa.RegistryWS registry = null;
103 Set svccategories = null;
104 boolean noservices = true;
106 boolean jabasws2 = false;
107 // If we are dealing with a JABAWS2 service, then just go and ask the
108 // JABAWS 2 service registry
109 Set<Services> srv_set = new HashSet<Services>();
111 Set<Category> categories = Category.getCategories();
116 // JBPNote: why is RegistryWS in compbio.data.msa ?
117 registry = Jws2Client.connectToRegistry(jwsserver);
118 if (registry != null)
120 // jalview.bin.Console.errPrintln("Test Services Output\n"
121 // + registry.testAllServices());
122 // TODO: enumerate services and test those that haven't been tested
123 // in the last n-days/hours/etc.
126 srv_set = registry.getSupportedServices();
129 jalview.bin.Console.outPrintln(
130 "registry.getSupportedServices: " + srv_set.toString());
132 svccategories = registry.getServiceCategories();
135 // jalview.bin.Console.outPrintln("registry.getServiceCategories: "
137 // svccategories.toString());
140 } catch (Exception ex)
142 jalview.bin.Console.errPrintln(
143 "Exception whilst trying to get at registry:");
144 ex.printStackTrace();
145 // if that failed, then we are probably working with a JABAWS1 server.
146 // in that case, look for each service endpoint
147 jalview.bin.Console.errPrintln("JWS2 Discoverer: " + jwsserver
148 + " is a JABAWS1 server. Using hardwired list.");
149 for (Services srv : JABAWS1SERVERS)
155 for (Category cat : categories)
157 for (Services srv : cat.getServices())
164 if (!srv_set.contains(srv))
168 JABAService service = null;
171 service = Jws2Client.connect(jwsserver, srv);
172 } catch (Exception e)
174 jalview.bin.Console.errPrintln("Jws2 Discoverer: Problem on "
175 + jwsserver + " with service " + srv + ":\n"
177 if (!(e instanceof javax.xml.ws.WebServiceException))
181 // For moment, report service as a problem.
182 jws2Discoverer.addInvalidServiceUrl(jwsserver);
186 && !Jws2InstanceFactory.ignoreService(srv.toString()))
189 Jws2Instance svc = null;
190 if (registry != null)
193 String description = registry.getServiceDescription(srv);
195 svc = Jws2InstanceFactory.newJws2Instance(jwsserver,
196 srv.toString(), cat.name, description, service);
200 svc = Jws2InstanceFactory.newJws2Instance(jwsserver,
201 srv.toString(), cat.name,
202 "JABAWS 1 Alignment Service", service);
204 jws2Discoverer.addService(jwsserver, svc);
212 jws2Discoverer.addUrlwithnoservices(jwsserver);
217 jws2Discoverer.addInvalidServiceUrl(jwsserver);
218 Console.warn("Ignoring invalid Jws2 service url " + jwsserver);
220 } catch (Exception e)
223 Console.warn("Exception when discovering Jws2 services.", e);
224 jws2Discoverer.addInvalidServiceUrl(jwsserver);
227 Console.error("Exception when discovering Jws2 services.", e);
228 jws2Discoverer.addInvalidServiceUrl(jwsserver);
234 * Check if the URL is valid and responding.
238 private boolean isValidUrl(String server)
240 // return Jws2Client.validURL(jwsserver); // checks syntax only
241 boolean result = false;
246 URL url = new URL(server);
247 url.openStream().close();
249 } catch (MalformedURLException e)
251 jalview.bin.Console.errPrintln("Invalid server URL: " + server);
253 } catch (IOException e)
255 jalview.bin.Console.errPrintln("Error connecting to server: "
256 + server + ": " + e.toString());