From a39e4da5d34f3385ad865ec6d5f7b01e8e5d30a3 Mon Sep 17 00:00:00 2001 From: jprocter Date: Tue, 27 Sep 2011 12:22:33 +0100 Subject: [PATCH] ensure server errors return a URL and response document (JAL-715,JAL-724) --- src/jalview/ws/rest/RestJobThread.java | 101 +++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 34 deletions(-) diff --git a/src/jalview/ws/rest/RestJobThread.java b/src/jalview/ws/rest/RestJobThread.java index 80e125a..bdd20c9 100644 --- a/src/jalview/ws/rest/RestJobThread.java +++ b/src/jalview/ws/rest/RestJobThread.java @@ -255,8 +255,10 @@ public class RestJobThread extends AWSThread response = httpclient.execute(request); } catch (ClientProtocolException he) { - rj.statMessage = "Web Protocol Exception when " - + getStage(stg) + "Job.
Problematic url was "+request.getURI()+"
See Console output for details."; + rj.statMessage = "Web Protocol Exception when " + getStage(stg) + + "Job.
Problematic url was " + request.getURI() + + "
See Console output for details."; rj.setAllowedServerExceptions(0);// unrecoverable; rj.error = true; Cache.log.fatal("Unexpected REST Job " + getStage(stg) @@ -264,8 +266,10 @@ public class RestJobThread extends AWSThread throw (he); } catch (IOException e) { - rj.statMessage = "IO Exception when " - + getStage(stg) + "Job.
Problematic url was "+request.getURI()+"
See Console output for details."; + rj.statMessage = "IO Exception when " + getStage(stg) + + "Job.
Problematic url was " + request.getURI() + + "
See Console output for details."; Cache.log.warn("IO Exception for REST Job " + getStage(stg) + "exception for URL " + rj.rsd.postUrl); @@ -322,9 +326,22 @@ public class RestJobThread extends AWSThread // TODO: deal with all other HTTP response codes from server. Cache.log.warn("Unhandled response status when " + getStage(stg) + "for " + postUrl + ": " + response.getStatusLine()); + rj.error = true; + rj.setAllowedServerExceptions(0); + rj.setSubjobComplete(true); + rj.setSubmitted(true); try { - response.getEntity().consumeContent(); + completeStatus( + rj, + response, + "" + + getStage(stg) + + " resulted in an unexpected server response.
Url concerned was " + + request.getURI() + + "
Filtered response content below:
"); } catch (IOException e) { Cache.log.debug("IOException when consuming unhandled response", @@ -394,7 +411,7 @@ public class RestJobThread extends AWSThread int body = f.indexOf(" -1) { - content.delete(0, f.indexOf(">", body)); + content.delete(0, f.indexOf(">", body) + 1); } if (body > -1 && sb.length() > 0) { @@ -422,16 +439,15 @@ public class RestJobThread extends AWSThread { System.err.println("Debug RestJob: Posting Job"); doPost((RestJob) job); - } - catch (NoValidInputDataException erex) + } catch (NoValidInputDataException erex) { job.setSubjobComplete(true); job.setSubmitted(true); - ((RestJob)job).statMessage="
It looks like there was a problem with the data sent to the service :
"+erex.getMessage()+"\n"; - ((RestJob)job).error=true; - - } - catch (Exception ex) + ((RestJob) job).statMessage = "
It looks like there was a problem with the data sent to the service :
" + + erex.getMessage() + "\n"; + ((RestJob) job).error = true; + + } catch (Exception ex) { job.setSubjobComplete(true); job.setAllowedServerExceptions(-1); @@ -471,10 +487,14 @@ public class RestJobThread extends AWSThread Cache.log.warn("Failed to finish parsing data for job " + rj.getJobId()); ex.printStackTrace(); - } - finally { - rj.error=true; - rj.statMessage = "Error whilst parsing data for this job.
URL for job response is :"+rj.resSet.getUrl()+"
"; + } finally + { + rj.error = true; + rj.statMessage = "Error whilst parsing data for this job.
URL for job response is :" + + rj.resSet.getUrl() + + "
"; } } } @@ -829,7 +849,9 @@ public class RestJobThread extends AWSThread visgrps.add(exsg); exsg.setStartRes(sg.getStartRes() + contigs[ncnt]); exsg.setEndRes(sg.getEndRes() + contigs[ncnt]); - } else { + } + else + { recovered = true; } // now replace any references from the result set with @@ -959,12 +981,14 @@ public class RestJobThread extends AWSThread visan.sequenceRef = sqass; visAlAn.add(visan); } - if (contigs[ncnt]+alan[nrj][an].annotations.length>visan.annotations.length) + if (contigs[ncnt] + alan[nrj][an].annotations.length > visan.annotations.length) { // increase width of annotation row - Annotation[] newannv = new Annotation[contigs[ncnt]+alan[nrj][an].annotations.length]; - System.arraycopy(visan.annotations, 0, newannv, 0, visan.annotations.length); - visan.annotations=newannv; + Annotation[] newannv = new Annotation[contigs[ncnt] + + alan[nrj][an].annotations.length]; + System.arraycopy(visan.annotations, 0, newannv, 0, + visan.annotations.length); + visan.annotations = newannv; } // now copy local annotation data into correct position System.arraycopy(alan[nrj][an].annotations, 0, @@ -1019,7 +1043,8 @@ public class RestJobThread extends AWSThread AlignmentI destal; ColumnSelection destcs; String alTitle = restClient.service.details.Action + " using " - + restClient.service.details.Name + " on "+restClient.viewTitle; + + restClient.service.details.Name + " on " + + restClient.viewTitle; switch (action) { case newAlignment: @@ -1027,7 +1052,8 @@ public class RestJobThread extends AWSThread destcs = destColsel.get(als); destaf = new AlignFrame(destal, destcs, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); - PaintRefresher.Refresh(destaf, destaf.getViewport().getSequenceSetId()); + PaintRefresher.Refresh(destaf, destaf.getViewport() + .getSequenceSetId()); // todo transfer any feature settings and colouring /* * destaf.getFeatureRenderer().transferSettings(this.featureSettings); @@ -1047,7 +1073,8 @@ public class RestJobThread extends AWSThread * i++) { af.addSortByOrderMenuItem( WebServiceName + ((String) * names.get(i)) + " Ordering", (AlignmentOrder) alorders.get(i)); } } } */ - // TODO: modify this and previous alignment's title if many alignments have been returned. + // TODO: modify this and previous alignment's title if many alignments + // have been returned. Desktop.addInternalFrame(destaf, alTitle, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); @@ -1227,8 +1254,8 @@ public class RestJobThread extends AWSThread */ public boolean isValid() { - ArrayList _warnings=new ArrayList(); - boolean validt=true; + ArrayList _warnings = new ArrayList(); + boolean validt = true; if (jobs != null) { for (RestJob rj : (RestJob[]) jobs) @@ -1237,42 +1264,48 @@ public class RestJobThread extends AWSThread { // invalid input for this job System.err.println("Job " + rj.getJobnum() - + " has invalid input. ( "+rj.getStatus()+")"); + + " has invalid input. ( " + rj.getStatus() + ")"); if (rj.hasStatus() && !_warnings.contains(rj.getStatus())) { _warnings.add(rj.getStatus()); } - validt=false; + validt = false; } } } if (!validt) { warnings = ""; - for (String st : _warnings) { - if (warnings.length()>0) { warnings+="\n"; + for (String st : _warnings) + { + if (warnings.length() > 0) + { + warnings += "\n"; } warnings += st; - + } } return validt; } protected String warnings; + public boolean hasWarnings() { // TODO Auto-generated method stub - return warnings!=null && warnings.length()>0; + return warnings != null && warnings.length() > 0; } /** * get any informative messages about why the job thread couldn't start. + * * @return */ public String getWarnings() { - return isValid() ? "Job can be started. No warnings." : hasWarnings() ? warnings : ""; + return isValid() ? "Job can be started. No warnings." + : hasWarnings() ? warnings : ""; } } -- 1.7.10.2