X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=webservices%2Fcompbio%2Fws%2Fclient%2FJws2Client.java;h=c18f1002b0d56994d7327ff41f202f747f12f43a;hb=6c87b80647c1a0f0543ed8bbfe43483c9fdfa1b8;hp=ceb9501cea191653179d4f10a6d3bd351f3d1224;hpb=a2619dbd95b874abd03ae551c02524fe09e9f631;p=jabaws.git diff --git a/webservices/compbio/ws/client/Jws2Client.java b/webservices/compbio/ws/client/Jws2Client.java index ceb9501..c18f100 100644 --- a/webservices/compbio/ws/client/Jws2Client.java +++ b/webservices/compbio/ws/client/Jws2Client.java @@ -18,26 +18,21 @@ package compbio.ws.client; -import static compbio.ws.client.Constraints.hostkey; import static compbio.ws.client.Constraints.inputkey; -import static compbio.ws.client.Constraints.limitList; import static compbio.ws.client.Constraints.outputkey; import static compbio.ws.client.Constraints.paramFile; -import static compbio.ws.client.Constraints.paramList; -import static compbio.ws.client.Constraints.presetList; -import static compbio.ws.client.Constraints.presetkey; -import static compbio.ws.client.Constraints.pseparator; -import static compbio.ws.client.Constraints.servicekey; import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.Writer; import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; import java.util.List; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -48,6 +43,7 @@ import javax.xml.ws.WebServiceException; import compbio.data.msa.JABAService; import compbio.data.msa.Metadata; import compbio.data.msa.MsaWS; +import compbio.data.msa.RegistryWS; import compbio.data.msa.SequenceAnnotation; import compbio.data.sequence.Alignment; import compbio.data.sequence.FastaSequence; @@ -69,8 +65,8 @@ import compbio.metadata.WrongParameterException; public class Jws2Client { /* - * TODO Use java.util.Logger instead of log4j logger to reduce the size of - * the client package + * Use java.util.Logger instead of log4j logger to reduce the size of the + * client package */ private static final Logger log = Logger.getLogger(Jws2Client.class .getCanonicalName()); @@ -113,26 +109,40 @@ public class Jws2Client { String hostname = CmdHelper.getHost(cmd); if (hostname == null) { - System.out.println("Host name is not provided!"); + System.err.println("Host name is not provided!"); printUsage(1); } if (!validURL(hostname)) { - System.out.println("Host name is not valid!"); + System.err.println("Host name is not valid!"); printUsage(1); } + // Just list available services and quit + boolean listServices = CmdHelper.listServices(cmd); + if (listServices) { + listServices(hostname); + System.exit(0); + } + String serviceName = CmdHelper.getServiceName(cmd); if (serviceName == null) { - System.out.println("Service name is no provided!"); + System.err.println("Service name is no provided!"); printUsage(1); } Services service = Services.getService(serviceName); if (service == null) { - System.out.println("Service " + serviceName - + " is no supported! Valid values are: " + System.err.println("Service " + serviceName + + " is no recognized! Valid values are: " + Arrays.toString(Services.values())); printUsage(1); } + // Test service and quit + boolean testService = CmdHelper.testService(cmd); + if (testService) { + testService(hostname, service); + System.exit(0); + } + File inputFile = IOHelper.getFile(cmd, inputkey, true); File outFile = IOHelper.getFile(cmd, outputkey, false); File parametersFile = IOHelper.getFile(cmd, paramFile, true); @@ -151,25 +161,25 @@ public class Jws2Client { } Alignment alignment = null; if (inputFile != null) { - OutputStream outStream = null; + Writer writer = null; if (outFile != null) { - outStream = IOHelper.getOutStream(outFile); + writer = IOHelper.getWriter(outFile); } else { // this stream is going to be closed later which is fine as // std.out will not be - outStream = System.out; + writer = new PrintWriter(System.out, true); } if (service.getServiceType() == SequenceAnnotation.class) { ScoreManager result = analize(inputFile, ((SequenceAnnotation) msaws), preset, customOptions); - IOHelper.writeOut(outStream, result); + IOHelper.writeOut(writer, result); } else { alignment = align(inputFile, (MsaWS) msaws, preset, customOptions); - IOHelper.writeOut(outStream, alignment); + IOHelper.writeOut(writer, alignment); } - outStream.close(); + writer.close(); } boolean listParameters = CmdHelper.listParameters(cmd); @@ -188,6 +198,30 @@ public class Jws2Client { ((Closeable) msaws).close(); log.fine("Disconnected successfully!"); } + + private void testService(String hostname, Services service) + throws IOException { + RegistryWS registry = connectToRegistry(hostname); + if (registry != null) { + String message = registry.testService(service); + System.out.println("Service " + service + " testing results: "); + System.out.println(message); + ((Closeable) registry).close(); + } + } + + private void listServices(String hostname) throws IOException { + RegistryWS registry = connectToRegistry(hostname); + if (registry != null) { + Set services = registry.getSupportedServices(); + System.out.println("Supported services are: " + + Services.toString(services)); + ((Closeable) registry).close(); + } else { + System.out.println("Failed to connect to the registry! "); + } + } + /** * Calculate conservation for sequences loaded from the file * @@ -444,46 +478,7 @@ public class Jws2Client { * @param exitStatus */ static void printUsage(int exitStatus) { - System.out.println(); - System.out.println("Usage: " + hostkey - + pseparator + "host_and_context " + servicekey + pseparator - + "serviceName ACTION [OPTIONS] "); - System.out.println(); - System.out - .println(hostkey - + pseparator - + " - a full URL to the JWS2 web server including context path e.g. http://10.31.1.159:8080/ws"); - System.out.println(servicekey + pseparator + " - one of " - + Arrays.toString(Services.values())); - System.out.println(); - System.out.println("ACTIONS: "); - System.out - .println(inputkey - + pseparator - + " - full path to fasta formatted sequence file, from which to align sequences"); - System.out.println(paramList - + " - lists parameters supported by web service"); - System.out.println(presetList - + " - lists presets supported by web service"); - System.out.println(limitList + " - lists web services limits"); - System.out - .println("Please note that if input file is specified other actions are ignored"); - - System.out.println(); - System.out.println("OPTIONS (only for use with -i action):"); - - System.out.println(presetkey + pseparator - + " - name of the preset to use"); - System.out - .println(outputkey - + pseparator - + " - full path to the file where to write an alignment"); - System.out - .println("-f= - the name of the file with the list of parameters to use."); - System.out - .println("Please note that -r and -f options cannot be used together. " - + "Alignment is done with either preset or a parameters from the file, but not both!"); - + System.out.println(Constraints.help_text); System.exit(exitStatus); } @@ -529,7 +524,7 @@ public class Jws2Client { printUsage(1); } if (args.length < 2) { - System.out.println("Host and service names are required!"); + System.err.println("Host and service names are required!"); printUsage(1); }