Adding registry web service and changes to WStester and JWS2Client code. Bugs in...
[jabaws.git] / webservices / compbio / ws / client / Jws2Client.java
index eda6533..ceb9501 100644 (file)
@@ -41,6 +41,7 @@ import java.util.List;
 import java.util.logging.Level;\r
 import java.util.logging.Logger;\r
 \r
+import javax.xml.namespace.QName;\r
 import javax.xml.ws.Service;\r
 import javax.xml.ws.WebServiceException;\r
 \r
@@ -68,8 +69,8 @@ import compbio.metadata.WrongParameterException;
 public class Jws2Client {\r
 \r
        /*\r
-        * Use java.util.Logger instead of log4j logger to reduce the size of the\r
-        * client package\r
+        * TODO Use java.util.Logger instead of log4j logger to reduce the size of\r
+        * the client package\r
         */\r
        private static final Logger log = Logger.getLogger(Jws2Client.class\r
                        .getCanonicalName());\r
@@ -201,15 +202,12 @@ public class Jws2Client {
         * @return Set<Score> the conservation scores\r
         * @throws UnknownFileFormatException\r
         */\r
-       <T> ScoreManager analize(File file, SequenceAnnotation<T> wsproxy,\r
-                       Preset<T> preset, List<Option<T>> customOptions) {\r
+       static <T> ScoreManager analize(List<FastaSequence> fastalist,\r
+                       SequenceAnnotation<T> wsproxy, Preset<T> preset,\r
+                       List<Option<T>> customOptions) {\r
 \r
-               List<FastaSequence> fastalist = null;\r
                ScoreManager scores = null;\r
                try {\r
-                       fastalist = SequenceUtil.openInputStream(file.getAbsolutePath());\r
-                       assert !fastalist.isEmpty() : "Input is empty!";\r
-\r
                        String jobId = null;\r
                        if (customOptions != null && preset != null) {\r
                                System.out\r
@@ -220,19 +218,12 @@ public class Jws2Client {
                        } else if (preset != null) {\r
                                jobId = wsproxy.presetAnalize(fastalist, preset);\r
                        } else {\r
-                               System.out.println("\n\ncalling analise.........");\r
                                jobId = wsproxy.analize(fastalist);\r
                        }\r
-                       Thread.sleep(2000);\r
-\r
+                       System.out.println("\n\ncalling analise.........");\r
+                       Thread.sleep(1000);\r
                        scores = wsproxy.getAnnotation(jobId);\r
 \r
-               } catch (IOException e) {\r
-                       System.err\r
-                                       .println("Exception while reading the input file. "\r
-                                                       + "Check that the input file contains a list of fasta formatted sequences! "\r
-                                                       + "Exception details are below:");\r
-                       e.printStackTrace();\r
                } catch (JobSubmissionException e) {\r
                        System.err\r
                                        .println("Exception while submitting job to a web server. "\r
@@ -242,14 +233,49 @@ public class Jws2Client {
                        System.err.println("Exception while waiting for results. "\r
                                        + "Exception details are below:");\r
                        e.printStackTrace();\r
-               } catch (InterruptedException ignored) {\r
+               } catch (InterruptedException e) {\r
                        // ignore and propagate an interruption\r
                        Thread.currentThread().interrupt();\r
+                       System.err.println("Exception while waiting for results. "\r
+                                       + "Exception details are below:");\r
+                       e.printStackTrace();\r
                } catch (WrongParameterException e) {\r
                        System.err\r
                                        .println("Exception while parsing the web method input parameters. "\r
                                                        + "Exception details are below:");\r
                        e.printStackTrace();\r
+               }\r
+               return scores;\r
+\r
+       }\r
+\r
+       /**\r
+        * Calculate conservation for sequences loaded from the file\r
+        * \r
+        * @param wsproxy\r
+        *            a web service proxy\r
+        * @param file\r
+        *            the file to read the results from\r
+        * @param preset\r
+        *            Preset to use optional\r
+        * @param customOptions\r
+        *            the list of options\r
+        * @return Set<Score> the conservation scores\r
+        * @throws IOException\r
+        * @throws UnknownFileFormatException\r
+        */\r
+       static <T> ScoreManager analize(File file, SequenceAnnotation<T> wsproxy,\r
+                       Preset<T> preset, List<Option<T>> customOptions) {\r
+               List<FastaSequence> fastalist = null;\r
+               try {\r
+                       fastalist = SequenceUtil.openInputStream(file.getAbsolutePath());\r
+                       assert !fastalist.isEmpty() : "Input is empty!";\r
+               } catch (IOException e) {\r
+                       System.err\r
+                                       .println("Exception while reading the input file. "\r
+                                                       + "Check that the input file contains a list of fasta formatted sequences! "\r
+                                                       + "Exception details are below:");\r
+                       e.printStackTrace();\r
                } catch (UnknownFileFormatException e) {\r
                        System.err\r
                                        .println("Exception while attempting to read the input file "\r
@@ -257,9 +283,8 @@ public class Jws2Client {
                        System.out.println(e.getMessage());\r
                        e.printStackTrace();\r
                }\r
-               return scores;\r
+               return analize(fastalist, wsproxy, preset, customOptions);\r
        }\r
-\r
        /**\r
         * Connects to a web service by the host and the service name\r
         * \r
@@ -284,7 +309,7 @@ public class Jws2Client {
                try {\r
                        serv = service.getService(url, QUALIFIED_SERVICE_NAME);\r
                } catch (WebServiceException wse) {\r
-                       System.out.println("Conecting to JABAWS version 2 service");\r
+                       System.out.println("Connecting to JABAWS version 2 service");\r
                        if (isV2service(wse)) {\r
                                serv = service.getService(url, V2_QUALIFIED_SERVICE_NAME);\r
                        }\r
@@ -311,6 +336,36 @@ public class Jws2Client {
                return false;\r
        }\r
 \r
+       public static compbio.data.msa.RegistryWS connectToRegistry(String host)\r
+                       throws WebServiceException {\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(V2_QUALIFIED_SERVICE_NAME, service);\r
+               Service serv = Service.create(url, qname);\r
+\r
+               if (serv == null) {\r
+                       System.err.println("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
+\r
        /**\r
         * Align sequences from the file using MsaWS\r
         * \r
@@ -347,6 +402,7 @@ public class Jws2Client {
                        } else {\r
                                jobId = msaws.align(fastalist);\r
                        }\r
+                       System.out.println("\n\ncalling align.........");\r
                        Thread.sleep(1000);\r
                        alignment = msaws.getResult(jobId);\r
 \r