- /**\r
- * Connects to a web service by the host and the service name web service\r
- * 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...");\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, JABAService.SERVICE_NAMESPACE);\r
- } catch (WebServiceException wse) {\r
- System.out.println("Connecting to JABAWS version 2 service");\r
- if (isV2service(wse)) {\r
- serv = service\r
- .getService(url, JABAService.V2_SERVICE_NAMESPACE);\r
- }\r
- }\r
- if (serv == null) {\r
- throw new ConnectException("Could not connect to " + url\r
- + " the server is down?");\r
- }\r
- JABAService serviceIF = service.getInterface(serv);\r
- log.log(Level.INFO, "Connected successfully!");\r
-\r
- return serviceIF;\r
- }\r
-\r
- static boolean isV2service(WebServiceException wse) {\r
- String message = wse.getMessage();\r
- int idx = message.indexOf("not a valid service");\r
- if (idx > 0) {\r
- if (message.substring(idx).contains(\r
- JABAService.V2_SERVICE_NAMESPACE)) {\r
- return true;\r
- }\r
- }\r
- return false;\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\r
- + " the server is down?");\r
- }\r
-\r
- QName portName = new QName(serv.getServiceName().getNamespaceURI(),\r
- service + "Port");\r
- compbio.data.msa.RegistryWS serviceIF = serv.getPort(portName,\r
- compbio.data.msa.RegistryWS.class);\r
-\r
- log.log(Level.INFO, "Connected to " + service + " successfully!");\r
-\r
- return serviceIF;\r
- }\r