X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=webservices%2Fcompbio%2Fws%2Fclient%2FWSTester.java;h=2f33cb1dd4a3d4166128722ec99eaa949141cdac;hb=652864eebc0ecdeb6f8bfef1700e3b365a0d7227;hp=4db6778e63fa255419e98a0d39e24800527683da;hpb=42a09319d534bfc2e97fc0ddd256aefe4185841b;p=jabaws.git diff --git a/webservices/compbio/ws/client/WSTester.java b/webservices/compbio/ws/client/WSTester.java index 4db6778..2f33cb1 100644 --- a/webservices/compbio/ws/client/WSTester.java +++ b/webservices/compbio/ws/client/WSTester.java @@ -1,6 +1,6 @@ -/* Copyright (c) 2009 Peter Troshin +/* Copyright (c) 2011 Peter Troshin * - * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0 + * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 * * This library is free software; you can redistribute it and/or modify it under the terms of the * Apache License version 2 as published by the Apache Software Foundation @@ -26,10 +26,11 @@ import java.io.ByteArrayInputStream; import java.io.Closeable; import java.io.IOException; import java.io.PrintWriter; +import java.net.ConnectException; import java.util.Arrays; import java.util.List; -import org.apache.log4j.Logger; +import javax.xml.ws.WebServiceException; import compbio.data.msa.JABAService; import compbio.data.msa.Metadata; @@ -59,22 +60,24 @@ import compbio.util.Util; */ public class WSTester { - private static Logger log = Logger.getLogger(WSTester.class); /** * Sequences to be used as input for all WS */ - static final String fastaInput = ">Foo\n" + public static final String fastaInput2records = ">Foo\n" + "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV" + "\n>Bar\n" - + "ASDAAPEHPGIALWLHALEDAGQAEAAAAYTRAHQLLPEEPYITAQLLNAVA"; + + "ASDAAPEHPGIALWLHALEDAGQAEAAAAYTRAHQLLPEEPYITAQLLNAVA\n"; + public static final String fastaInput1record = ">Foo\n" + + "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV" + + "\n"; - static final String fastaAlignment = ">Foo\r\n" - + "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV--------\r\n" - + ">Bar\r\n" - + "ASDAAPEH------------PGIALWLHALE-DAGQAEAAA---AYTRAHQLLPEEPYITAQLLNAVA\r\n" + public static final String fastaAlignment = ">Foo\n" + + "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV--------\n" + + ">Bar\n" + + "ASDAAPEH------------PGIALWLHALE-DAGQAEAAA---AYTRAHQLLPEEPYITAQLLNAVA\n" + ""; - static final List seqs = loadSeqs(); + static final List seqs = loadSeqs(2); private static final String FAILED = "FAILED"; private static final String OK = "OK"; @@ -86,10 +89,12 @@ public class WSTester { * * @return List of FastaSequence records */ - private static List loadSeqs() { + private static List loadSeqs(int nLines) { try { - return SequenceUtil.readFasta(new ByteArrayInputStream(fastaInput - .getBytes())); + if (nLines == 1) { + return SequenceUtil.readFasta(new ByteArrayInputStream(fastaInput1record.getBytes())); + } + return SequenceUtil.readFasta(new ByteArrayInputStream(fastaInput2records.getBytes())); } catch (IOException ignored) { // Should not happen as a source is not a external stream ignored.printStackTrace(); @@ -116,6 +121,15 @@ public class WSTester { private final PrintWriter writer; private final String hostname; + /** + * Construct an instance of JABAWS tester + * + * @param hostname + * - fully qualified host and context name of JABAWS e.g. + * http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba + * @param writer + * a PrintWriter instance to writer test log to. + */ public WSTester(String hostname, PrintWriter writer) { if (Util.isEmpty(hostname)) { throw new NullPointerException("Hostname must be provided!"); @@ -132,12 +146,10 @@ public class WSTester { + pseparator + "host_and_context " + "<" + servicekey + pseparator + "serviceName>"); System.out.println(); - System.out - .println(hostkey + System.out.println(hostkey + pseparator + " - a full URL to the JABAWS web server including context path e.g. http://10.31.1.159:8080/ws"); - System.out - .println(servicekey + System.out.println(servicekey + pseparator + " - optional if unspecified all services are tested otherwise one of " + Arrays.toString(Services.values())); @@ -182,8 +194,7 @@ public class WSTester { return succeed; } - private boolean testMsaWS(MsaWS msaws) - throws UnsupportedRuntimeException { + private boolean testMsaWS(MsaWS msaws) throws Exception { assert msaws != null; boolean succeed = testDefaultAlignment(msaws); @@ -210,32 +221,38 @@ public class WSTester { * executable does not exists for a server platform */ @SuppressWarnings("unchecked") - private boolean checkService(JABAService wservice) { + private boolean checkService(JABAService wservice, Services service) { try { if (wservice == null) { - throw new NullPointerException( - "JABAService instance must be provided!"); + throw new NullPointerException("JABAService instance must be provided!"); } if (wservice instanceof MsaWS) { return testMsaWS((MsaWS) wservice); } else if (wservice instanceof SequenceAnnotation) { - return testSequenceAnnotationWS((SequenceAnnotation) wservice); + return testSequenceAnnotationWS( + (SequenceAnnotation) wservice, service); } else { - throw new UnsupportedOperationException("The service: " - + wservice.getClass() + " is not supported! "); + throw new UnsupportedOperationException("The service: " + wservice.getClass() + " is not supported! "); } - } catch (UnsupportedRuntimeException e) { + } catch (Exception e) { reportException(e); return false; } } - private boolean testSequenceAnnotationWS(SequenceAnnotation wservice) - throws UnsupportedRuntimeException { + private boolean testSequenceAnnotationWS( + SequenceAnnotation wservice, Services service) throws Exception { writer.print("Calling analyse........."); - boolean success = testDefaultAnalyse(loadAlignment(), wservice, null, - null); + + List input = loadSeqs(2); + if (service == Services.AAConWS) { + input = loadAlignment(); + } + if (service == Services.JpredWS) { + input = loadSeqs(1); + } + boolean success = testDefaultAnalyse(input, wservice, null, null); PresetManager presetman = wservice.getPresets(); if (presetman != null) { @@ -243,8 +260,7 @@ public class WSTester { if (presets != null && !presets.isEmpty()) { Preset preset = presets.get(0); writer.print("Calling analyse with Preset........."); - success = testDefaultAnalyse(loadAlignment(), wservice, preset, - null); + success = testDefaultAnalyse(input, wservice, preset, null); } } testMetadata(wservice); @@ -253,30 +269,24 @@ public class WSTester { private boolean testDefaultAnalyse(List fastalist, SequenceAnnotation wsproxy, Preset preset, - List> customOptions) throws UnsupportedRuntimeException { + List> customOptions) throws Exception { ScoreManager scores = null; - try { - String jobId = null; - if (customOptions != null) { - jobId = wsproxy.customAnalize(fastalist, customOptions); - } else if (preset != null) { - jobId = wsproxy.presetAnalize(fastalist, preset); - } else { - jobId = wsproxy.analize(fastalist); - } - Thread.sleep(1000); - scores = wsproxy.getAnnotation(jobId); - if (scores != null) { - writer.println(OK); - } - } catch (Exception e) { - if (e instanceof UnsupportedRuntimeException) { - throw (UnsupportedRuntimeException) e; - } else { - reportException(e); - } + + String jobId = null; + if (customOptions != null) { + jobId = wsproxy.customAnalize(fastalist, customOptions); + } else if (preset != null) { + jobId = wsproxy.presetAnalize(fastalist, preset); + } else { + jobId = wsproxy.analize(fastalist); + } + Thread.sleep(1000); + scores = wsproxy.getAnnotation(jobId); + if (scores != null) { + writer.println(OK); } + return scores != null; } @@ -311,6 +321,7 @@ public class WSTester { LimitsManager limits = msaws.getLimits(); if (limits != null && limits.getLimits().size() > 0) { writer.println(OK); + // writer.println("Limits details: \n" + limits.toString()); } else { writer.println(UNSUPPORTED); } @@ -332,30 +343,22 @@ public class WSTester { * @param msaws * @throws UnsupportedRuntimeException */ - private boolean testDefaultAlignment(MsaWS msaws) - throws UnsupportedRuntimeException { + private boolean testDefaultAlignment(MsaWS msaws) throws Exception { writer.print("Testing alignment with default parameters:"); Alignment al = null; boolean succeed = false; - try { - String taskId = msaws.align(seqs); - writer.print("\nQuerying job status..."); - JobStatus status = msaws.getJobStatus(taskId); - while (status != JobStatus.FINISHED) { - Thread.sleep(1000); - status = msaws.getJobStatus(taskId); - } - writer.println(OK); - writer.print("Retrieving results..."); - al = msaws.getResult(taskId); - succeed = true; - } catch (Exception e) { - if (e instanceof UnsupportedRuntimeException) { - throw (UnsupportedRuntimeException) e; - } else { - reportException(e); - } + + String taskId = msaws.align(seqs); + writer.print("\nQuerying job status..."); + JobStatus status = msaws.getJobStatus(taskId); + while (status != JobStatus.FINISHED) { + Thread.sleep(1000); + status = msaws.getJobStatus(taskId); } + writer.println(OK); + writer.print("Retrieving results..."); + al = msaws.getResult(taskId); + succeed = true; if (al != null) { writer.println(OK); } @@ -383,8 +386,7 @@ public class WSTester { String host = CmdHelper.getHost(args); String serviceName = CmdHelper.getServiceName(args); if (!Jws2Client.validURL(host)) { - System.err - .println(" parameter is not provided or is incorrect!"); + System.err.println(" parameter is not provided or is incorrect!"); System.exit(1); } WSTester tester = new WSTester(host, new PrintWriter(System.out, true)); @@ -392,8 +394,7 @@ public class WSTester { if (serviceName != null) { Services service = Services.getService(serviceName); if (service == null) { - tester.writer.println("Service '" + serviceName - + "' is not supported. Valid values are: " + tester.writer.println("Service '" + serviceName + "' is not supported. Valid values are: " + Arrays.toString(Services.values())); tester.writer.println(); printUsage(); @@ -403,8 +404,7 @@ public class WSTester { System.exit(0); } - tester.writer - .println(" is not provided checking all known services..."); + tester.writer.println(" is not provided checking all known services..."); for (Services serv : Services.values()) { tester.writer.println(); @@ -413,17 +413,27 @@ public class WSTester { } - public boolean checkService(Services service) { + /** + * Test JABA web service + * + * @param service + * the service to test + * @return true if the service works as expected, false otherwise + * @throws WebServiceException + * @throws ConnectException + */ + public boolean checkService(Services service) throws ConnectException, + WebServiceException { JABAService ws = Jws2Client.connect(hostname, service); if (ws == null) { - writer.println("Cannot estabilish the connection to host " - + hostname + " with service " + service.toString()); + String line = "Cannot estabilish the connection to host " + hostname + " with service "; + writer.println(line + service.toString()); return false; } boolean succeed = false; try { writer.println("Checking service " + service.toString()); - succeed = checkService(ws); + succeed = checkService(ws, service); } finally { FileUtil.closeSilently(((Closeable) ws)); } @@ -433,11 +443,9 @@ public class WSTester { private void reportResults(Services serv, boolean succeed) { if (succeed) { - writer.println("Check is completed. The Service " + serv - + " IS WORKING\n"); + writer.println("Check is completed. The Service " + serv + " IS WORKING\n"); } else { - writer.println("Check is completed. The Service " + serv - + " HAS SOME PROBLEMS\n"); + writer.println("Check is aborted. The Service " + serv + " HAS SOME PROBLEMS\n"); } } }