+ \r
+ /**\r
+ * 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
+ private JABAService connect(String host, Services service)\r
+ throws WebServiceException, ConnectException {\r
+ URL url = null;\r
+ System.out.println ("Attempting to connect with " + service.toString() + "...");\r
+ try {\r
+ url = new URL(host + "/" + service.toString() + "?wsdl");\r
+ System.out.println ("URL: " + url.toString());\r
+ } catch (MalformedURLException e) {\r
+ e.printStackTrace();\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 srv = service.getInterface(serv);\r
+ System.out.println ("Connected successfully!");\r
+ return srv;\r
+ }\r
+\r
+ /**\r
+ * Test JABA web service\r
+ * \r
+ * @param service\r
+ * the service to test\r
+ * @return true if the service works as expected, false otherwise\r
+ * @throws WebServiceException\r
+ * @throws ConnectException\r
+ */\r
+ public boolean checkService(Services service) throws ConnectException,\r
+ WebServiceException {\r
+ JABAService ws = connect(hostname, service);\r
+ if (ws == null) {\r
+ String line = "Cannot estabilish the connection to host " + hostname + " with service ";\r
+ writer.println(line + service.toString());\r
+ return false;\r
+ }\r
+ boolean succeed = false;\r
+ try {\r
+ writer.println("Checking service " + service.toString());\r
+ succeed = checkService(ws, service);\r
+ } finally {\r
+ FileUtil.closeSilently(((Closeable) ws));\r
+ }\r
+ reportResults(service, succeed);\r
+ return succeed;\r
+ }\r