\r
package compbio.ws.client;\r
\r
-import static compbio.ws.client.Constraints.hostkey;\r
import static compbio.ws.client.Constraints.inputkey;\r
-import static compbio.ws.client.Constraints.limitList;\r
import static compbio.ws.client.Constraints.outputkey;\r
import static compbio.ws.client.Constraints.paramFile;\r
-import static compbio.ws.client.Constraints.paramList;\r
-import static compbio.ws.client.Constraints.presetList;\r
-import static compbio.ws.client.Constraints.presetkey;\r
-import static compbio.ws.client.Constraints.pseparator;\r
-import static compbio.ws.client.Constraints.servicekey;\r
\r
import java.io.Closeable;\r
import java.io.File;\r
import java.io.FileInputStream;\r
import java.io.IOException;\r
-import java.io.OutputStream;\r
+import java.io.PrintWriter;\r
+import java.io.Writer;\r
import java.net.MalformedURLException;\r
import java.net.URL;\r
import java.util.Arrays;\r
import java.util.List;\r
+import java.util.Set;\r
import java.util.logging.Level;\r
import java.util.logging.Logger;\r
\r
import compbio.data.msa.JABAService;\r
import compbio.data.msa.Metadata;\r
import compbio.data.msa.MsaWS;\r
+import compbio.data.msa.RegistryWS;\r
import compbio.data.msa.SequenceAnnotation;\r
import compbio.data.sequence.Alignment;\r
import compbio.data.sequence.FastaSequence;\r
public class Jws2Client {\r
\r
/*\r
- * TODO Use java.util.Logger instead of log4j logger to reduce the size of\r
- * the client package\r
+ * Use java.util.Logger instead of log4j logger to reduce the size of the\r
+ * client package\r
*/\r
private static final Logger log = Logger.getLogger(Jws2Client.class\r
.getCanonicalName());\r
\r
String hostname = CmdHelper.getHost(cmd);\r
if (hostname == null) {\r
- System.out.println("Host name is not provided!");\r
+ System.err.println("Host name is not provided!");\r
printUsage(1);\r
}\r
\r
if (!validURL(hostname)) {\r
- System.out.println("Host name is not valid!");\r
+ System.err.println("Host name is not valid!");\r
printUsage(1);\r
}\r
+ // Just list available services and quit\r
+ boolean listServices = CmdHelper.listServices(cmd);\r
+ if (listServices) {\r
+ listServices(hostname);\r
+ System.exit(0);\r
+ }\r
+\r
String serviceName = CmdHelper.getServiceName(cmd);\r
if (serviceName == null) {\r
- System.out.println("Service name is no provided!");\r
+ System.err.println("Service name is no provided!");\r
printUsage(1);\r
}\r
Services service = Services.getService(serviceName);\r
if (service == null) {\r
- System.out.println("Service " + serviceName\r
- + " is no supported! Valid values are: "\r
+ System.err.println("Service " + serviceName\r
+ + " is no recognized! Valid values are: "\r
+ Arrays.toString(Services.values()));\r
printUsage(1);\r
}\r
+ // Test service and quit\r
+ boolean testService = CmdHelper.testService(cmd);\r
+ if (testService) {\r
+ testService(hostname, service);\r
+ System.exit(0);\r
+ }\r
+\r
File inputFile = IOHelper.getFile(cmd, inputkey, true);\r
File outFile = IOHelper.getFile(cmd, outputkey, false);\r
File parametersFile = IOHelper.getFile(cmd, paramFile, true);\r
}\r
Alignment alignment = null;\r
if (inputFile != null) {\r
- OutputStream outStream = null;\r
+ Writer writer = null;\r
if (outFile != null) {\r
- outStream = IOHelper.getOutStream(outFile);\r
+ writer = IOHelper.getWriter(outFile);\r
} else {\r
// this stream is going to be closed later which is fine as\r
// std.out will not be\r
- outStream = System.out;\r
+ writer = new PrintWriter(System.out, true);\r
}\r
if (service.getServiceType() == SequenceAnnotation.class) {\r
ScoreManager result = analize(inputFile,\r
((SequenceAnnotation<T>) msaws), preset, customOptions);\r
\r
- IOHelper.writeOut(outStream, result);\r
+ IOHelper.writeOut(writer, result);\r
} else {\r
alignment = align(inputFile, (MsaWS<T>) msaws, preset,\r
customOptions);\r
- IOHelper.writeOut(outStream, alignment);\r
+ IOHelper.writeOut(writer, alignment);\r
}\r
- outStream.close();\r
+ writer.close();\r
}\r
\r
boolean listParameters = CmdHelper.listParameters(cmd);\r
((Closeable) msaws).close();\r
log.fine("Disconnected successfully!");\r
}\r
+\r
+ private void testService(String hostname, Services service)\r
+ throws IOException {\r
+ RegistryWS registry = connectToRegistry(hostname);\r
+ if (registry != null) {\r
+ String message = registry.testService(service);\r
+ System.out.println("Service " + service + " testing results: ");\r
+ System.out.println(message);\r
+ ((Closeable) registry).close();\r
+ }\r
+ }\r
+\r
+ private void listServices(String hostname) throws IOException {\r
+ RegistryWS registry = connectToRegistry(hostname);\r
+ if (registry != null) {\r
+ Set<Services> services = registry.getSupportedServices();\r
+ System.out.println("Supported services are: "\r
+ + Services.toString(services));\r
+ ((Closeable) registry).close();\r
+ } else {\r
+ System.out.println("Failed to connect to the registry! ");\r
+ }\r
+ }\r
+\r
/**\r
* Calculate conservation for sequences loaded from the file\r
* \r
* @param exitStatus\r
*/\r
static void printUsage(int exitStatus) {\r
- System.out.println();\r
- System.out.println("Usage: <Class or Jar file name> " + hostkey\r
- + pseparator + "host_and_context " + servicekey + pseparator\r
- + "serviceName ACTION [OPTIONS] ");\r
- System.out.println();\r
- System.out\r
- .println(hostkey\r
- + pseparator\r
- + "<host_and_context> - a full URL to the JWS2 web server including context path e.g. http://10.31.1.159:8080/ws");\r
- System.out.println(servicekey + pseparator + "<ServiceName> - one of "\r
- + Arrays.toString(Services.values()));\r
- System.out.println();\r
- System.out.println("ACTIONS: ");\r
- System.out\r
- .println(inputkey\r
- + pseparator\r
- + "<inputFile> - full path to fasta formatted sequence file, from which to align sequences");\r
- System.out.println(paramList\r
- + " - lists parameters supported by web service");\r
- System.out.println(presetList\r
- + " - lists presets supported by web service");\r
- System.out.println(limitList + " - lists web services limits");\r
- System.out\r
- .println("Please note that if input file is specified other actions are ignored");\r
-\r
- System.out.println();\r
- System.out.println("OPTIONS (only for use with -i action):");\r
-\r
- System.out.println(presetkey + pseparator\r
- + "<presetName> - name of the preset to use");\r
- System.out\r
- .println(outputkey\r
- + pseparator\r
- + "<outputFile> - full path to the file where to write an alignment");\r
- System.out\r
- .println("-f=<parameterInputFile> - the name of the file with the list of parameters to use.");\r
- System.out\r
- .println("Please note that -r and -f options cannot be used together. "\r
- + "Alignment is done with either preset or a parameters from the file, but not both!");\r
-\r
+ System.out.println(Constraints.help_text);\r
System.exit(exitStatus);\r
}\r
\r
printUsage(1);\r
}\r
if (args.length < 2) {\r
- System.out.println("Host and service names are required!");\r
+ System.err.println("Host and service names are required!");\r
printUsage(1);\r
}\r
\r