+ * Connects to a web service by the host and the service name web service type\r
+ * \r
+ * @param host\r
+ * the fully qualified name of JABAWS server including JABAWS\r
+ * context name e.g\r
+ * http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
+ * @param service\r
+ * the name of the JABAWS service to connect to\r
+ * @return JABAService<T>\r
+ * @throws WebServiceException\r
+ * @throws ConnectException\r
+ * if fails to connect to the service on the host\r
+ */\r
+ public static JABAService connect(String host, Services service)\r
+ throws WebServiceException, ConnectException {\r
+ URL url = null;\r
+ log.log(Level.FINE, "Attempting to connect with " + service.toString() + "...");\r
+ System.out.println ("Attempting to connect with " + service.toString() + "...");\r
+ try {\r
+ url = new URL(host + "/" + service.toString() + "?wsdl");\r
+ } catch (MalformedURLException e) {\r
+ e.printStackTrace();\r
+ // ignore as the host name is already verified\r
+ }\r
+ Service serv = null;\r
+ try {\r
+ serv = service.getService(url, service.getServiceNamespace());\r
+ } catch (WebServiceException wse) {\r
+ wse.printStackTrace();\r
+ }\r
+ if (serv == null) {\r
+ throw new ConnectException("Could not connect to " + url + ". Is the server down?");\r
+ }\r
+ JABAService serviceIF = service.getInterface(serv);\r
+ log.log(Level.INFO, "Connected successfully!");\r
+\r
+ return serviceIF;\r
+ }\r
+\r
+ /**\r
+ * Get a connection of JABAWS registry\r
+ * \r
+ * @param host\r
+ * the fully qualified name of JABAWS server including JABAWS\r
+ * context name e.g\r
+ * http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
+ * @return compbio.data.msa.RegistryWS - instance of a RegistryWS web\r
+ * service\r
+ * @throws WebServiceException\r
+ * @throws ConnectException\r
+ */\r
+ public static compbio.data.msa.RegistryWS connectToRegistry(String host)\r
+ throws WebServiceException, ConnectException {\r
+ URL url = null;\r
+ String service = "RegistryWS";\r
+ log.log(Level.FINE, "Attempting to connect...");\r
+\r
+ try {\r
+ url = new URL(host + "/" + service + "?wsdl");\r
+ } catch (MalformedURLException e) {\r
+ e.printStackTrace();\r
+ // ignore as the host name is already verified\r
+ }\r
+ QName qname = new QName(JABAService.V2_SERVICE_NAMESPACE, service);\r
+ Service serv = Service.create(url, qname);\r
+\r
+ if (serv == null) {\r
+ throw new ConnectException("Could not connect to " + url + ". Is the server down?");\r
+ }\r
+\r
+ QName portName = new QName(serv.getServiceName().getNamespaceURI(), service + "Port");\r
+ compbio.data.msa.RegistryWS serviceIF = serv.getPort(portName, compbio.data.msa.RegistryWS.class);\r
+ log.log(Level.INFO, "Connected to " + service + " successfully!");\r
+\r
+ return serviceIF;\r
+ }\r
+\r
+ /**\r
+ * Asks registry to test the service on the host hostname\r
+ * \r
+ * @param hostname\r
+ * @param service\r
+ * @param writer\r
+ * @throws ConnectException\r
+ * @throws WebServiceException\r
+ */\r
+ public static void testService(String hostname, Services service, PrintWriter writer)\r
+ throws ConnectException, WebServiceException {\r
+ RegistryWS registry = connectToRegistry(hostname);\r
+ if (registry != null) {\r
+ String message = registry.testService(service);\r
+ writer.println("Service " + service + " testing results: ");\r
+ writer.println(message);\r
+ FileUtil.closeSilently(((Closeable) registry));\r
+ }\r
+ writer.flush();\r
+ }\r
+\r
+ private static void listAllServices(String hostname) throws WebServiceException, IOException {\r
+ RegistryWS registry = connectToRegistry(hostname);\r
+ Set<Services> func_services = Collections.EMPTY_SET;\r
+ Set<Services> nonfunc_services = Collections.EMPTY_SET;\r
+ if (registry != null) {\r
+ func_services = registry.getSupportedServices();\r
+ nonfunc_services = registry.getNonoperatedServices();\r
+ FileUtil.closeSilently(((Closeable) registry));\r
+ } else {\r
+ System.out.println("Failed to connect to the registry! ");\r
+ return;\r
+ }\r
+ if (!func_services.isEmpty()) {\r
+ System.out.println("There are " + func_services.size() + " services at " + hostname + ":");\r
+ String mess = "\n\rThe list:\n";\r
+ System.out.println(mess + Services.toString(func_services));\r
+ }\r
+ if (!nonfunc_services.isEmpty()) {\r
+ System.out.println("There are " + nonfunc_services.size() + " non-available services at " + hostname + ":");\r
+ String mess = "The list (internal tests failed): ";\r
+ System.out.println(mess + Services.toString(nonfunc_services));\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Calculate conservation for sequences loaded from a FASTA record list structure \r