-/* Copyright (c) 2009 Peter Troshin\r
+/* Copyright (c) 2011 Peter Troshin\r
* \r
- * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0 \r
+ * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 \r
* \r
* This library is free software; you can redistribute it and/or modify it under the terms of the\r
* Apache License version 2 as published by the Apache Software Foundation\r
import java.io.Closeable;\r
import java.io.IOException;\r
import java.io.PrintWriter;\r
+import java.net.ConnectException;\r
import java.util.Arrays;\r
import java.util.List;\r
\r
+import javax.xml.ws.WebServiceException;\r
+\r
import org.apache.log4j.Logger;\r
\r
import compbio.data.msa.JABAService;\r
private final PrintWriter writer;\r
private final String hostname;\r
\r
+ /**\r
+ * Construct an instance of JABAWS tester\r
+ * \r
+ * @param hostname\r
+ * - fully qualified host and context name of JABAWS e.g.\r
+ * http://nanna.cluster.lifesci.dundee.ac.uk:8080/jaba\r
+ * @param writer\r
+ * a PrintWriter instance to writer test log to.\r
+ */\r
public WSTester(String hostname, PrintWriter writer) {\r
if (Util.isEmpty(hostname)) {\r
throw new NullPointerException("Hostname must be provided!");\r
return succeed;\r
}\r
\r
- private <T> boolean testMsaWS(MsaWS<T> msaws)\r
- throws UnsupportedRuntimeException {\r
+ private <T> boolean testMsaWS(MsaWS<T> msaws) throws Exception {\r
assert msaws != null;\r
\r
boolean succeed = testDefaultAlignment(msaws);\r
* executable does not exists for a server platform\r
*/\r
@SuppressWarnings("unchecked")\r
- private <T> boolean checkService(JABAService wservice) {\r
+ private <T> boolean checkService(JABAService wservice, Services service) {\r
try {\r
if (wservice == null) {\r
throw new NullPointerException(\r
if (wservice instanceof MsaWS) {\r
return testMsaWS((MsaWS<T>) wservice);\r
} else if (wservice instanceof SequenceAnnotation) {\r
- return testSequenceAnnotationWS((SequenceAnnotation<T>) wservice);\r
+ return testSequenceAnnotationWS(\r
+ (SequenceAnnotation<T>) wservice, service);\r
} else {\r
throw new UnsupportedOperationException("The service: "\r
+ wservice.getClass() + " is not supported! ");\r
}\r
- } catch (UnsupportedRuntimeException e) {\r
+ } catch (Exception e) {\r
reportException(e);\r
return false;\r
}\r
}\r
\r
- private <T> boolean testSequenceAnnotationWS(SequenceAnnotation<T> wservice)\r
- throws UnsupportedRuntimeException {\r
+ private <T> boolean testSequenceAnnotationWS(\r
+ SequenceAnnotation<T> wservice, Services service) throws Exception {\r
writer.print("Calling analyse.........");\r
- boolean success = testDefaultAnalyse(loadAlignment(), wservice, null,\r
- null);\r
+\r
+ List<FastaSequence> input = loadSeqs();\r
+ if (service == Services.AAConWS) {\r
+ input = loadAlignment();\r
+ }\r
+ boolean success = testDefaultAnalyse(input, wservice, null, null);\r
\r
PresetManager<T> presetman = wservice.getPresets();\r
if (presetman != null) {\r
if (presets != null && !presets.isEmpty()) {\r
Preset<T> preset = presets.get(0);\r
writer.print("Calling analyse with Preset.........");\r
- success = testDefaultAnalyse(loadAlignment(), wservice, preset,\r
- null);\r
+ success = testDefaultAnalyse(input, wservice, preset, null);\r
}\r
}\r
testMetadata(wservice);\r
\r
private <T> boolean testDefaultAnalyse(List<FastaSequence> fastalist,\r
SequenceAnnotation<T> wsproxy, Preset<T> preset,\r
- List<Option<T>> customOptions) throws UnsupportedRuntimeException {\r
+ List<Option<T>> customOptions) throws Exception {\r
\r
ScoreManager scores = null;\r
- try {\r
- String jobId = null;\r
- if (customOptions != null) {\r
- jobId = wsproxy.customAnalize(fastalist, customOptions);\r
- } else if (preset != null) {\r
- jobId = wsproxy.presetAnalize(fastalist, preset);\r
- } else {\r
- jobId = wsproxy.analize(fastalist);\r
- }\r
- Thread.sleep(1000);\r
- scores = wsproxy.getAnnotation(jobId);\r
- if (scores != null) {\r
- writer.println(OK);\r
- }\r
- } catch (Exception e) {\r
- if (e instanceof UnsupportedRuntimeException) {\r
- throw (UnsupportedRuntimeException) e;\r
- } else {\r
- reportException(e);\r
- }\r
+\r
+ String jobId = null;\r
+ if (customOptions != null) {\r
+ jobId = wsproxy.customAnalize(fastalist, customOptions);\r
+ } else if (preset != null) {\r
+ jobId = wsproxy.presetAnalize(fastalist, preset);\r
+ } else {\r
+ jobId = wsproxy.analize(fastalist);\r
+ }\r
+ Thread.sleep(1000);\r
+ scores = wsproxy.getAnnotation(jobId);\r
+ if (scores != null) {\r
+ writer.println(OK);\r
}\r
+\r
return scores != null;\r
}\r
\r
LimitsManager<T> limits = msaws.getLimits();\r
if (limits != null && limits.getLimits().size() > 0) {\r
writer.println(OK);\r
+ // writer.println("Limits details: \n" + limits.toString());\r
} else {\r
writer.println(UNSUPPORTED);\r
}\r
* @param msaws\r
* @throws UnsupportedRuntimeException\r
*/\r
- private <T> boolean testDefaultAlignment(MsaWS<T> msaws)\r
- throws UnsupportedRuntimeException {\r
+ private <T> boolean testDefaultAlignment(MsaWS<T> msaws) throws Exception {\r
writer.print("Testing alignment with default parameters:");\r
Alignment al = null;\r
boolean succeed = false;\r
- try {\r
- String taskId = msaws.align(seqs);\r
- writer.print("\nQuerying job status...");\r
- JobStatus status = msaws.getJobStatus(taskId);\r
- while (status != JobStatus.FINISHED) {\r
- Thread.sleep(1000);\r
- status = msaws.getJobStatus(taskId);\r
- }\r
- writer.println(OK);\r
- writer.print("Retrieving results...");\r
- al = msaws.getResult(taskId);\r
- succeed = true;\r
- } catch (Exception e) {\r
- if (e instanceof UnsupportedRuntimeException) {\r
- throw (UnsupportedRuntimeException) e;\r
- } else {\r
- reportException(e);\r
- }\r
+\r
+ String taskId = msaws.align(seqs);\r
+ writer.print("\nQuerying job status...");\r
+ JobStatus status = msaws.getJobStatus(taskId);\r
+ while (status != JobStatus.FINISHED) {\r
+ Thread.sleep(1000);\r
+ status = msaws.getJobStatus(taskId);\r
}\r
+ writer.println(OK);\r
+ writer.print("Retrieving results...");\r
+ al = msaws.getResult(taskId);\r
+ succeed = true;\r
if (al != null) {\r
writer.println(OK);\r
}\r
\r
}\r
\r
- public boolean checkService(Services service) {\r
+ /**\r
+ * Test JABA web service\r
+ * \r
+ * @param service\r
+ * the service to test\r
+ * @return true if the service works as expected, false otherwise\r
+ * @throws WebServiceException\r
+ * @throws ConnectException\r
+ */\r
+ public boolean checkService(Services service) throws ConnectException,\r
+ WebServiceException {\r
JABAService ws = Jws2Client.connect(hostname, service);\r
if (ws == null) {\r
writer.println("Cannot estabilish the connection to host "\r
boolean succeed = false;\r
try {\r
writer.println("Checking service " + service.toString());\r
- succeed = checkService(ws);\r
+ succeed = checkService(ws, service);\r
} finally {\r
FileUtil.closeSilently(((Closeable) ws));\r
}\r
writer.println("Check is completed. The Service " + serv\r
+ " IS WORKING\n");\r
} else {\r
- writer.println("Check is completed. The Service " + serv\r
+ writer.println("Check is aborted. The Service " + serv\r
+ " HAS SOME PROBLEMS\n");\r
}\r
}\r