remove project files and keep sources only
[jabaws.git] / webservices / compbio / ws / client / WSTester.java
index 226af80..5450a1d 100644 (file)
@@ -28,9 +28,13 @@ import java.io.Closeable;
 import java.io.IOException;\r
 import java.io.PrintWriter;\r
 import java.net.ConnectException;\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
 import java.util.Arrays;\r
 import java.util.List;\r
+import java.util.logging.Level;\r
 \r
+import javax.xml.ws.Service;\r
 import javax.xml.ws.WebServiceException;\r
 \r
 import compbio.data.msa.JABAService;\r
@@ -76,6 +80,12 @@ public class WSTester {
                        ">Foo\nC-UUGCGUUAAUGAGAACAGAAACG-UAAA--CUAUAA-CCUAG-G-GGUUUCUGUUGGAUGGUUG----GCAAC\n"\r
                +   ">Bar\nG-UGGCGCUUAUGACGCAGUUGUCU-UAAA-CUCGAAC--UCGA-GCGGGCAAUUGCUGAU-UACGAUUAACCAC\n";\r
 \r
+       public static final String clustalRNAAlignment = \r
+                       "CLUSTAL\n" +\r
+                       "Foo             C-UUGCGUUAAUGAGAACAGAAACG-UAAA--CUAUAA-CCUAG-G-GGUUUCUGUUGGA\n" +\r
+                       "Bar             G-UGGCGCUUAUGACGCAGUUGUCU-UAAA-CUCGAAC--UCGA-GCGGGCAAUUGCUGA\n" +\r
+                       "Foo             UGGUUG----GCAAC\n" +\r
+                       "Bar             U-UACGAUUAACCAC";\r
        /**\r
         * Status strings\r
         */\r
@@ -256,7 +266,7 @@ public class WSTester {
 \r
        private <T> boolean testSequenceAnnotationWS(\r
                        SequenceAnnotation<T> wservice, Services service) throws Exception {\r
-               writer.print("Calling analyse.........");\r
+               writer.print("Calling annotation test.........");\r
 \r
                List<FastaSequence> input = loadSeqs(2);\r
                if (service == Services.AAConWS ) {\r
@@ -304,8 +314,7 @@ public class WSTester {
 \r
        private void reportException(Exception e) {\r
                writer.println(FAILED);\r
-               writer.println("Exception while waiting for results. "\r
-                               + "Exception details are below:");\r
+               writer.println("Exception while waiting for results. Exception details are below:");\r
                writer.println(e.getLocalizedMessage());\r
                e.printStackTrace(writer);\r
        }\r
@@ -362,7 +371,7 @@ public class WSTester {
                String taskId;\r
 \r
                if (service == Services.JpredWS) {\r
-                       taskId = msaws.align(loadSeqs(1));\r
+                       taskId = msaws.align(loadAlignment());\r
                } else {\r
                        taskId = msaws.align(loadSeqs(2));\r
                }\r
@@ -429,6 +438,44 @@ public class WSTester {
                }\r
 \r
        }\r
+       \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
@@ -441,7 +488,7 @@ public class WSTester {
         */\r
        public boolean checkService(Services service) throws ConnectException,\r
                        WebServiceException {\r
-               JABAService ws = Jws2Client.connect(hostname, service);\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