ae38d9f7771360f81f582b2f82409751a283aab7
[jabaws.git] / webservices / compbio / ws / client / Jws2Client.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.ws.client;\r
20 \r
21 import static compbio.ws.client.Constraints.inputkey;\r
22 import static compbio.ws.client.Constraints.outputkey;\r
23 import static compbio.ws.client.Constraints.paramFile;\r
24 \r
25 import java.io.Closeable;\r
26 import java.io.File;\r
27 import java.io.FileInputStream;\r
28 import java.io.IOException;\r
29 import java.io.PrintWriter;\r
30 import java.io.Writer;\r
31 import java.net.ConnectException;\r
32 import java.net.MalformedURLException;\r
33 import java.net.URL;\r
34 import java.util.Arrays;\r
35 import java.util.Collections;\r
36 import java.util.List;\r
37 import java.util.Set;\r
38 import java.util.logging.Level;\r
39 import java.util.logging.Logger;\r
40 \r
41 import javax.xml.namespace.QName;\r
42 import javax.xml.ws.Service;\r
43 import javax.xml.ws.WebServiceException;\r
44 \r
45 import compbio.data.msa.JABAService;\r
46 import compbio.data.msa.FoldWS;\r
47 import compbio.data.msa.Metadata;\r
48 import compbio.data.msa.MsaWS;\r
49 import compbio.data.msa.RegistryWS;\r
50 import compbio.data.msa.SequenceAnnotation;\r
51 import compbio.data.sequence.Alignment;\r
52 import compbio.data.sequence.FastaSequence;\r
53 import compbio.data.sequence.ScoreManager;\r
54 import compbio.data.sequence.ClustalAlignmentUtil;\r
55 import compbio.data.sequence.SequenceUtil;\r
56 import compbio.data.sequence.UnknownFileFormatException;\r
57 import compbio.metadata.JobSubmissionException;\r
58 import compbio.metadata.Option;\r
59 import compbio.metadata.Preset;\r
60 import compbio.metadata.ResultNotAvailableException;\r
61 import compbio.metadata.WrongParameterException;\r
62 import compbio.util.FileUtil;\r
63 \r
64 /**\r
65  * A command line client for JAva Bioinformatics Analysis Web Services\r
66  * \r
67  * @author pvtroshin\r
68  * @version 1.0\r
69  */\r
70 public class Jws2Client {\r
71 \r
72         /*\r
73          * Use java.util.Logger instead of log4j logger to reduce the size of the\r
74          * client package\r
75          */\r
76         private static final Logger log = Logger.getLogger(Jws2Client.class\r
77                         .getCanonicalName());\r
78 \r
79         /**\r
80          * Attempt to construct the URL object from the string\r
81          * \r
82          * @param urlstr\r
83          * @return true if it succeed false otherwise\r
84          */\r
85         public static boolean validURL(String urlstr) {\r
86                 try {\r
87                         if (urlstr == null || urlstr.trim().length() == 0) {\r
88                                 return false;\r
89                         }\r
90                         new URL(urlstr);\r
91                 } catch (MalformedURLException e) {\r
92                         return false;\r
93                 }\r
94                 return true;\r
95         }\r
96 \r
97         /**\r
98          * Connects to the service and do the job as requested, if something goes\r
99          * wrong reports or/and prints usage help.\r
100          * \r
101          * @param <T>\r
102          *            web service type\r
103          * @param cmd\r
104          *            command line options\r
105          * @throws IOException\r
106          */\r
107         <T> Jws2Client(String[] cmd) throws IOException {\r
108                 \r
109 \r
110                 String hostname = CmdHelper.getHost(cmd);\r
111                 if (hostname == null) {\r
112                         System.err.println("Host name is not provided!");\r
113                         printUsage(1);\r
114                 }\r
115 \r
116                 if (!validURL(hostname)) {\r
117                         System.err.println("Host name is not valid!");\r
118                         printUsage(1);\r
119                 }\r
120                 // Just list available services and quit\r
121                 boolean listServices = CmdHelper.listServices(cmd);\r
122                 if (listServices) {\r
123                         listServices(hostname);\r
124                         System.exit(0);\r
125                 }\r
126 \r
127                 String serviceName = CmdHelper.getServiceName(cmd);\r
128                 if (serviceName == null) {\r
129                         System.err.println("Service name is no provided!");\r
130                         printUsage(1);\r
131                 }\r
132                 Services service = Services.getService(serviceName);\r
133                 if (service == null) {\r
134                         System.err.println("Service " + serviceName\r
135                                         + " is no recognized! Valid values are: "\r
136                                         + Arrays.toString(Services.values()));\r
137                         printUsage(1);\r
138                 }\r
139                 // Test service and quit\r
140                 boolean testService = CmdHelper.testService(cmd);\r
141                 if (testService) {\r
142                         testService(hostname, service, new PrintWriter(System.out, true));\r
143                         System.exit(0);\r
144                 }\r
145 \r
146                 File inputFile = IOHelper.getFile(cmd, inputkey, true);\r
147                 File outFile = IOHelper.getFile(cmd, outputkey, false);\r
148                 File parametersFile = IOHelper.getFile(cmd, paramFile, true);\r
149                 String presetName = CmdHelper.getPresetName(cmd);\r
150 \r
151                 Metadata<T> msaws = (Metadata<T>) connect(hostname, service);\r
152                 Preset<T> preset = null;\r
153                 if (presetName != null) {\r
154                         preset = MetadataHelper.getPreset(msaws, presetName);\r
155                 }\r
156                 List<Option<T>> customOptions = null;\r
157                 if (parametersFile != null) {\r
158                         List<String> prms = IOHelper.loadParameters(parametersFile);\r
159                         customOptions = MetadataHelper.processParameters(prms,\r
160                                         msaws.getRunnerOptions());\r
161                 }\r
162 //              System.out.println("The Options read from the command line: " + customOptions);\r
163                 \r
164                 Alignment alignment = null;\r
165                 if (inputFile != null) {\r
166                         Writer writer = null;\r
167                         if (outFile != null) {\r
168                                 writer = IOHelper.getWriter(outFile);\r
169                         } else {\r
170                                 // this stream is going to be closed later which is fine as\r
171                                 // std.out will not be\r
172                                 writer = new PrintWriter(System.out, true);\r
173                         }\r
174                         if (service.getServiceType() == SequenceAnnotation.class) {\r
175                                 ScoreManager result = analize(inputFile,\r
176                                                 ((SequenceAnnotation<T>) msaws), preset, customOptions);\r
177 \r
178                                 // A System.out.println just for testing!\r
179                                 System.out.println(result.toString());\r
180                                 \r
181                                 IOHelper.writeOut(writer, result);\r
182                         } else if (service.getServiceType() == MsaWS.class) {\r
183                                 alignment = align(inputFile, (MsaWS<T>) msaws, preset,\r
184                                                 customOptions);\r
185                                 IOHelper.writeOut(writer, alignment);\r
186                         }\r
187                         writer.close();\r
188                 }\r
189 \r
190                 boolean listParameters = CmdHelper.listParameters(cmd);\r
191                 if (listParameters) {\r
192                         System.out.println(MetadataHelper.getParametersList(msaws));\r
193                 }\r
194                 boolean listPreset = CmdHelper.listPresets(cmd);\r
195                 if (listPreset) {\r
196                         System.out.println(MetadataHelper.getPresetList(msaws));\r
197                 }\r
198                 boolean listLimits = CmdHelper.listLimits(cmd);\r
199                 if (listLimits) {\r
200                         System.out.println(MetadataHelper.getLimits(msaws));\r
201                 }\r
202                 log.fine("Disconnecting...");\r
203                 ((Closeable) msaws).close();\r
204                 log.fine("Disconnected successfully!");\r
205         }\r
206 \r
207         /**\r
208          * Asks registry to test the service on the host hostname\r
209          * \r
210          * @param hostname\r
211          * @param service\r
212          * @param writer\r
213          * @throws ConnectException\r
214          * @throws WebServiceException\r
215          */\r
216         public static void testService(String hostname, Services service,\r
217                         PrintWriter writer) throws ConnectException, WebServiceException {\r
218                 RegistryWS registry = connectToRegistry(hostname);\r
219                 if (registry != null) {\r
220                         String message = registry.testService(service);\r
221                         writer.println("Service " + service + " testing results: ");\r
222                         writer.println(message);\r
223                         FileUtil.closeSilently(((Closeable) registry));\r
224                 }\r
225                 writer.flush();\r
226         }\r
227 \r
228         public static Set<Services> getServices(String hostname)\r
229                         throws WebServiceException, ConnectException {\r
230                 RegistryWS registry = connectToRegistry(hostname);\r
231                 Set<Services> services = Collections.EMPTY_SET;\r
232                 if (registry != null) {\r
233                         services = registry.getSupportedServices();\r
234                         FileUtil.closeSilently(((Closeable) registry));\r
235                 }\r
236                 return services;\r
237         }\r
238 \r
239         private static void listServices(String hostname)\r
240                         throws WebServiceException, IOException {\r
241                 Set<Services> services = Jws2Client.getServices(hostname);\r
242                 if (!services.isEmpty()) {\r
243                         System.out.println("Supported services are: "\r
244                                         + Services.toString(services));\r
245                 } else {\r
246                         System.out.println("Failed to connect to the registry! ");\r
247                 }\r
248         }\r
249 \r
250         /**\r
251          * Calculate conservation for sequences loaded from the file\r
252          * \r
253          * @param wsproxy\r
254          *            a web service proxy\r
255          * @param file\r
256          *            the file to read the results from\r
257          * @param preset\r
258          *            Preset to use optional\r
259          * @param customOptions\r
260          *            the list of options\r
261          * @return Set<Score> the conservation scores\r
262          * @throws UnknownFileFormatException\r
263          */\r
264         static <T> ScoreManager analize(List<FastaSequence> fastalist,\r
265                         SequenceAnnotation<T> wsproxy, Preset<T> preset,\r
266                         List<Option<T>> customOptions) {\r
267 \r
268                 ScoreManager scores = null;\r
269                 try {\r
270                         String jobId = null;\r
271                         if (customOptions != null && preset != null) {\r
272                                 System.out\r
273                                                 .println("WARN: Parameters (-f) are defined together with a preset (-r) ignoring preset!");\r
274                         }\r
275                         if (customOptions != null) {\r
276                                 jobId = wsproxy.customAnalize(fastalist, customOptions);\r
277                         } else if (preset != null) {\r
278                                 jobId = wsproxy.presetAnalize(fastalist, preset);\r
279                         } else {\r
280                                 jobId = wsproxy.analize(fastalist);\r
281                         }\r
282                         System.out.println("\n\ncalling analise.........");\r
283                         Thread.sleep(1000);\r
284                         scores = wsproxy.getAnnotation(jobId);\r
285 \r
286                 } catch (JobSubmissionException e) {\r
287                         System.err\r
288                                         .println("Exception while submitting job to a web server. "\r
289                                                         + "Exception details are below:");\r
290                         e.printStackTrace();\r
291                 } catch (ResultNotAvailableException e) {\r
292                         System.err.println("Exception while waiting for results. "\r
293                                         + "Exception details are below:");\r
294                         e.printStackTrace();\r
295                 } catch (InterruptedException e) {\r
296                         // ignore and propagate an interruption\r
297                         Thread.currentThread().interrupt();\r
298                         System.err.println("Exception while waiting for results. "\r
299                                         + "Exception details are below:");\r
300                         e.printStackTrace();\r
301                 } catch (WrongParameterException e) {\r
302                         System.err\r
303                                         .println("Exception while parsing the web method input parameters. "\r
304                                                         + "Exception details are below:");\r
305                         e.printStackTrace();\r
306                 }\r
307                 return scores;\r
308 \r
309         }\r
310 \r
311         /**\r
312          * Calculate conservation for sequences loaded from the file\r
313          * \r
314          * @param wsproxy\r
315          *            a web service proxy\r
316          * @param file\r
317          *            the file to read the results from\r
318          * @param preset\r
319          *            Preset to use optional\r
320          * @param customOptions\r
321          *            the list of options\r
322          * @return Set<Score> the conservation scores\r
323          * @throws IOException\r
324          * @throws UnknownFileFormatException\r
325          */\r
326         static <T> ScoreManager analize(File file, SequenceAnnotation<T> wsproxy,\r
327                         Preset<T> preset, List<Option<T>> customOptions) {\r
328                 List<FastaSequence> fastalist = null;\r
329                 try {\r
330                         fastalist = SequenceUtil.openInputStream(file.getAbsolutePath());\r
331                         assert !fastalist.isEmpty() : "Input is empty!";\r
332                 } catch (IOException e) {\r
333                         System.err\r
334                                         .println("Exception while reading the input file. "\r
335                                                         + "Check that the input file contains a list of fasta formatted sequences! "\r
336                                                         + "Exception details are below:");\r
337                         e.printStackTrace();\r
338                 } catch (UnknownFileFormatException e) {\r
339                         System.err\r
340                                         .println("Exception while attempting to read the input file "\r
341                                                         + "Exception details are below:");\r
342                         System.out.println(e.getMessage());\r
343                         e.printStackTrace();\r
344                 }\r
345                 return analize(fastalist, wsproxy, preset, customOptions);\r
346         }\r
347         /**\r
348          * Connects to a web service by the host and the service name web service\r
349          * type\r
350          * \r
351          * @param host\r
352          *            the fully qualified name of JABAWS server including JABAWS\r
353          *            context name e.g\r
354          *            http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
355          * @param service\r
356          *            the name of the JABAWS service to connect to\r
357          * @return JABAService<T>\r
358          * @throws WebServiceException\r
359          * @throws ConnectException\r
360          *             if fails to connect to the service on the host\r
361          */\r
362         public static JABAService connect(String host, Services service)\r
363                         throws WebServiceException, ConnectException {\r
364                 URL url = null;\r
365                 log.log(Level.FINE, "Attempting to connect...");\r
366                 try {\r
367                         url = new URL(host + "/" + service.toString() + "?wsdl");\r
368                 } catch (MalformedURLException e) {\r
369                         e.printStackTrace();\r
370                         // ignore as the host name is already verified\r
371                 }\r
372                 Service serv = null;\r
373                 try {\r
374                         serv = service.getService(url, JABAService.SERVICE_NAMESPACE);\r
375                 } catch (WebServiceException wse) {\r
376                         System.out.println("Connecting to JABAWS version 2 service");\r
377                         if (isV2service(wse)) {\r
378                                 serv = service\r
379                                                 .getService(url, JABAService.V2_SERVICE_NAMESPACE);\r
380                         }\r
381                 }\r
382                 if (serv == null) {\r
383                         throw new ConnectException("Could not connect to " + url\r
384                                         + " the server is down?");\r
385                 }\r
386                 JABAService serviceIF = service.getInterface(serv);\r
387                 log.log(Level.INFO, "Connected successfully!");\r
388 \r
389                 return serviceIF;\r
390         }\r
391 \r
392         static boolean isV2service(WebServiceException wse) {\r
393                 String message = wse.getMessage();\r
394                 int idx = message.indexOf("not a valid service");\r
395                 if (idx > 0) {\r
396                         if (message.substring(idx).contains(\r
397                                         JABAService.V2_SERVICE_NAMESPACE)) {\r
398                                 return true;\r
399                         }\r
400                 }\r
401                 return false;\r
402         }\r
403 \r
404         /**\r
405          * Get a connection of JABAWS registry\r
406          * \r
407          * @param host\r
408          *            the fully qualified name of JABAWS server including JABAWS\r
409          *            context name e.g\r
410          *            http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
411          * @return compbio.data.msa.RegistryWS - instance of a RegistryWS web\r
412          *         service\r
413          * @throws WebServiceException\r
414          * @throws ConnectException\r
415          */\r
416         public static compbio.data.msa.RegistryWS connectToRegistry(String host)\r
417                         throws WebServiceException, ConnectException {\r
418                 URL url = null;\r
419                 String service = "RegistryWS";\r
420                 log.log(Level.FINE, "Attempting to connect...");\r
421 \r
422                 try {\r
423                         url = new URL(host + "/" + service + "?wsdl");\r
424                 } catch (MalformedURLException e) {\r
425                         e.printStackTrace();\r
426                         // ignore as the host name is already verified\r
427                 }\r
428                 QName qname = new QName(JABAService.V2_SERVICE_NAMESPACE, service);\r
429                 Service serv = Service.create(url, qname);\r
430 \r
431                 if (serv == null) {\r
432                         throw new ConnectException("Could not connect to " + url\r
433                                         + " the server is down?");\r
434                 }\r
435 \r
436                 QName portName = new QName(serv.getServiceName().getNamespaceURI(),\r
437                                 service + "Port");\r
438                 compbio.data.msa.RegistryWS serviceIF = serv.getPort(portName,\r
439                                 compbio.data.msa.RegistryWS.class);\r
440 \r
441                 log.log(Level.INFO, "Connected to " + service + " successfully!");\r
442 \r
443                 return serviceIF;\r
444         }\r
445 \r
446         /**\r
447          * Align sequences from the file using MsaWS\r
448          * \r
449          * @param <T>\r
450          *            web service type e.g. Clustal\r
451          * @param file\r
452          *            to write the resulting alignment to\r
453          * @param msaws\r
454          *            MsaWS required\r
455          * @param preset\r
456          *            Preset to use optional\r
457          * @param customOptions\r
458          *            file which contains new line separated list of options\r
459          * @return Alignment\r
460          */\r
461         static <T> Alignment align(File file, MsaWS<T> msaws, Preset<T> preset,\r
462                         List<Option<T>> customOptions) {\r
463                 FileInputStream instream = null;\r
464                 List<FastaSequence> fastalist = null;\r
465                 Alignment alignment = null;\r
466                 try {\r
467                         instream = new FileInputStream(file);\r
468                         fastalist = SequenceUtil.readFasta(instream);\r
469                         instream.close();\r
470                         String jobId = null;\r
471                         if (customOptions != null && preset != null) {\r
472                                 System.out\r
473                                                 .println("WARN: Parameters (-f) are defined together with a preset (-r) ignoring preset!");\r
474                         }\r
475                         if (customOptions != null) {\r
476                                 jobId = msaws.customAlign(fastalist, customOptions);\r
477                         } else if (preset != null) {\r
478                                 jobId = msaws.presetAlign(fastalist, preset);\r
479                         } else {\r
480                                 jobId = msaws.align(fastalist);\r
481                         }\r
482                         System.out.println("\n\ncalling align.........");\r
483                         Thread.sleep(1000);\r
484                         alignment = msaws.getResult(jobId);\r
485 \r
486                 } catch (IOException e) {\r
487                         System.err\r
488                                         .println("Exception while reading the input file. "\r
489                                                         + "Check that the input file contains a list of fasta formatted sequences! "\r
490                                                         + "Exception details are below:");\r
491                         e.printStackTrace();\r
492                 } catch (JobSubmissionException e) {\r
493                         System.err\r
494                                         .println("Exception while submitting job to a web server. "\r
495                                                         + "Exception details are below:");\r
496                         e.printStackTrace();\r
497                 } catch (ResultNotAvailableException e) {\r
498                         System.err.println("Exception while waiting for results. "\r
499                                         + "Exception details are below:");\r
500                         e.printStackTrace();\r
501                 } catch (InterruptedException ignored) {\r
502                         // ignore and propagate an interruption\r
503                         Thread.currentThread().interrupt();\r
504                 } catch (WrongParameterException e) {\r
505                         e.printStackTrace();\r
506                 } finally {\r
507                         if (instream != null) {\r
508                                 try {\r
509                                         instream.close();\r
510                                 } catch (IOException ignored) {\r
511                                         // ignore\r
512                                 }\r
513                         }\r
514                 }\r
515                 return alignment;\r
516         }\r
517         \r
518         /**\r
519          * Return RNA secondary structure from a file using FoldWS\r
520          * \r
521          * @param <T>\r
522          *            web service type e.g. Clustal\r
523          * @param file\r
524          *            to read the results from\r
525          * @param foldws\r
526          *            FoldWS required\r
527          * @param preset\r
528          *            Preset to use optional\r
529          * @param customOptions\r
530          *            file which contains new line separated list of options\r
531          * @return String\r
532          */\r
533         \r
534 //      static <T> String fold(File file, FoldWS<T> foldws, Preset<T> preset,\r
535 //                      List<Option<T>> customOptions) {\r
536 //              FileInputStream instream = null;\r
537 //              Alignment alignment = null;\r
538 //              String rnastruct = null;\r
539 //              try {\r
540 //                      instream = new FileInputStream(file);\r
541 //                      alignment = ClustalAlignmentUtil.readClustalFile(instream);\r
542 //                      instream.close();\r
543 //                      String jobId = null;\r
544 //                      if (customOptions != null && preset != null) {\r
545 //                              System.out.println("WARN: Parameters (-f) are defined together"\r
546 //                                              + "with a preset (-r), ignoring preset! ");\r
547 //                      }\r
548 //                      if (customOptions != null) {\r
549 //                              jobId = foldws.customFold(alignment, customOptions);\r
550 //                      } else if (preset != null) {\r
551 //                              jobId = foldws.presetFold(alignment, preset);\r
552 //                      } else {\r
553 //                              jobId = foldws.fold(alignment);\r
554 //                      }\r
555 //                      System.out.println("\n\ncalling fold.........");\r
556 //                      Thread.sleep(1000);\r
557 //                      rnastruct = foldws.getResult(jobId);\r
558 //                              \r
559 //              } catch (IOException e) {\r
560 //                      System.err.println("Exception while reading the input file. Exception details: ");\r
561 //                      e.printStackTrace();\r
562 //              } catch (UnknownFileFormatException e) {\r
563 //                      System.err.println("Exception while reading input file. Doesnt look like a Clustal format file");\r
564 //                      e.printStackTrace();\r
565 //              } catch (JobSubmissionException e) {\r
566 //                      System.err.println("Exception while submitting job to the web server. ");\r
567 //                      e.printStackTrace();\r
568 //              } catch (ResultNotAvailableException e) {\r
569 //                      System.err.println("Exception while waiting for results. Exception details: ");\r
570 //                      e.printStackTrace();\r
571 //              } catch (InterruptedException ignored) {\r
572 //                      // ignore and propagate an interruption\r
573 //                      Thread.currentThread().interrupt();\r
574 //              } catch (WrongParameterException e) {\r
575 //                      e.printStackTrace();\r
576 //              } finally {\r
577 //                      if (instream != null) {\r
578 //                              try {\r
579 //                                      instream.close();\r
580 //                              } catch (IOException ignored) {\r
581 //                                      // ignore\r
582 //                              }\r
583 //                      }\r
584 //              }\r
585 //              return rnastruct;\r
586 //      }\r
587 //              \r
588         /**\r
589          * Prints Jws2Client usage information to standard out\r
590          * \r
591          * @param exitStatus\r
592          */\r
593         static void printUsage(int exitStatus) {\r
594                 System.out.println(Constraints.help_text);\r
595                 System.exit(exitStatus);\r
596         }\r
597 \r
598         /**\r
599          * Starts command line client, if no parameter are supported print help. Two\r
600          * parameters are required for successful call the JWS2 host name and a\r
601          * service name.\r
602          * \r
603          * @param args\r
604          *            Usage: <Class or Jar file name> -h=host_and_context\r
605          *            -s=serviceName ACTION [OPTIONS]\r
606          * \r
607          *            -h=<host_and_context> - a full URL to the JWS2 web server\r
608          *            including context path e.g. http://10.31.1.159:8080/ws\r
609          * \r
610          *            -s=<ServiceName> - one of [MafftWS, MuscleWS, ClustalWS,\r
611          *            TcoffeeWS, ProbconsWS] ACTIONS:\r
612          * \r
613          *            -i=<inputFile> - full path to fasta formatted sequence file,\r
614          *            from which to align sequences\r
615          * \r
616          *            -parameters - lists parameters supported by web service\r
617          * \r
618          *            -presets - lists presets supported by web service\r
619          * \r
620          *            -limits - lists web services limits Please note that if input\r
621          *            file is specified other actions are ignored\r
622          * \r
623          *            OPTIONS: (only for use with -i action):\r
624          * \r
625          *            -r=<presetName> - name of the preset to use\r
626          * \r
627          *            -o=<outputFile> - full path to the file where to write an\r
628          *            alignment -f=<parameterInputFile> - the name of the file with\r
629          *            the list of parameters to use. Please note that -r and -f\r
630          *            options cannot be used together. Alignment is done with either\r
631          *            preset or a parameters from the file, but not both!\r
632          * \r
633          */\r
634         public static void main(String[] args) {\r
635 \r
636                 if (args == null) {\r
637                         printUsage(1);\r
638                 }\r
639                 if (args.length < 2) {\r
640                         System.err.println("Host and service names are required!");\r
641                         printUsage(1);\r
642                 }\r
643 \r
644                 try {\r
645                         new Jws2Client(args);\r
646                 } catch (IOException e) {\r
647                         log.log(Level.SEVERE, "IOException in client! " + e.getMessage(),\r
648                                         e.getCause());\r
649                         System.err.println("Cannot write output file! Stack trace: ");\r
650                         e.printStackTrace();\r
651                 }\r
652         }\r
653 }\r