X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Frest%2FRestJobThread.java;fp=src%2Fjalview%2Fws%2Frest%2FRestJobThread.java;h=0895f0fff90431425ed8ef8bfca7817b69fa20d4;hb=d043ce47fc710d3eb2629ba926a8a7417bd67d8c;hp=eff38fbad494b01ee97d92cf421a11eac1b55dfa;hpb=04c8f7bff663aa469127e9eed4164e02933782f1;p=jalview.git
diff --git a/src/jalview/ws/rest/RestJobThread.java b/src/jalview/ws/rest/RestJobThread.java
index eff38fb..0895f0f 100644
--- a/src/jalview/ws/rest/RestJobThread.java
+++ b/src/jalview/ws/rest/RestJobThread.java
@@ -61,8 +61,6 @@ import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.protocol.BasicHttpContext;
-import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
public class RestJobThread extends AWSThread
@@ -218,9 +216,6 @@ public class RestJobThread extends AWSThread
protected void doHttpReq(Stage stg, RestJob rj, String postUrl)
throws Exception
{
- StringBuffer respText = new StringBuffer();
- // con.setContentHandlerFactory(new
- // jalview.ws.io.mime.HttpContentHandler());
HttpRequestBase request = null;
String messages = "";
if (stg == Stage.SUBMIT)
@@ -255,7 +250,6 @@ public class RestJobThread extends AWSThread
{
DefaultHttpClient httpclient = new DefaultHttpClient();
- HttpContext localContext = new BasicHttpContext();
HttpResponse response = null;
try
{
@@ -290,38 +284,18 @@ public class RestJobThread extends AWSThread
processResultSet(rj, response, request);
break;
case 202:
- rj.statMessage = "
Job submitted successfully. Results available at this URL:\n"
- + "" + rj.getJobId()
- + "
";
- rj.running = true;
+ markJobAsRunning(rj);
break;
+ case 201:
+ // Created - redirect may be present. Fallthrough to 302
case 302:
- Header[] loc;
- if (!rj.isSubmitted()
- && (loc = response
- .getHeaders(HTTPConstants.HEADER_LOCATION)) != null
- && loc.length > 0)
- {
- if (loc.length > 1)
- {
- Console.warn("Ignoring additional " + (loc.length - 1)
- + " location(s) provided in response header ( next one is '"
- + loc[1].getValue() + "' )");
- }
- rj.setJobId(loc[0].getValue());
- rj.setSubmitted(true);
- }
+ extractJobId(rj, response);
completeStatus(rj, response);
break;
case 500:
- // Failed.
- rj.setSubmitted(true);
- rj.setAllowedServerExceptions(0);
- rj.setSubjobComplete(true);
- rj.error = true;
- rj.running = false;
- completeStatus(rj, response,
- "" + getStage(stg) + "failed. Reason below:\n");
+ markAsFailed(rj, response);
+ completeStatus(rj, response, "" + getStage(stg)
+ + "failed. Reason below:\n");
break;
default:
// Some other response. Probably need to pop up the content in a window.
@@ -347,6 +321,62 @@ public class RestJobThread extends AWSThread
}
}
+ private void markAsFailed(RestJob rj, HttpResponse response)
+ {
+ // Failed.
+ rj.setSubmitted(true);
+ rj.setAllowedServerExceptions(0);
+ rj.setSubjobComplete(true);
+ rj.error = true;
+ rj.running = false;
+ }
+
+ /**
+ * set the jobRunning flag and post a link to the physical result page encoded
+ * in rj.getJobId()
+ *
+ * @param rj
+ */
+ private void markJobAsRunning(RestJob rj)
+ {
+ rj.statMessage = "
Job submitted successfully. Results available at this URL:\n"
+ + ""
+ + rj.getJobId()
+ + "
";
+ rj.running = true;
+ }
+
+ /**
+ * extract the job ID URL from the redirect page. Does nothing if job is
+ * already running.
+ *
+ * @param rj
+ * @param response
+ */
+ private void extractJobId(RestJob rj, HttpResponse response)
+ {
+ Header[] loc;
+ if (!rj.isSubmitted())
+ {
+
+ // redirect URL - typical for IBIVU type jobs.
+ if ((loc = response.getHeaders(HTTPConstants.HEADER_LOCATION)) != null
+ && loc.length > 0)
+ {
+ if (loc.length > 1)
+ {
+ Console.warn("Ignoring additional "
+ + (loc.length - 1)
+ + " location(s) provided in response header ( next one is '"
+ + loc[1].getValue() + "' )");
+ }
+ rj.setJobId(loc[0].getValue());
+ rj.setSubmitted(true);
+ }
+ }
+ }
/**
* job has completed. Something valid should be available from con
*
@@ -1038,8 +1068,9 @@ public class RestJobThread extends AWSThread
HiddenColumns destcs;
String alTitle = MessageManager
.formatMessage("label.webservice_job_title_on", new String[]
- { restClient.service.details.Action,
- restClient.service.details.Name, restClient.viewTitle });
+ { restClient.service.details.getAction(),
+ restClient.service.details.getName(),
+ restClient.viewTitle });
switch (action)
{
case newAlignment: