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