Permalink
Browse files

Introduced a time out on connections

  • Loading branch information...
1 parent 06594fd commit 450871e4f23fceef0f70bc8c7942cb3ef3317c92 @egonw egonw committed Nov 13, 2010
@@ -32,6 +32,9 @@
public static final String PLUGIN_ID="net.bioclipse.opentox";
private static final Logger logger = Logger.getLogger(Activator.class);
+
+ /** HTTP time out in milliseconds. */
+ public static final Integer TIME_OUT = 5000;
// The shared instance
private static Activator plugin;
@@ -28,6 +28,7 @@
import net.bioclipse.cdk.business.CDKManager;
import net.bioclipse.core.domain.IMolecule;
+import net.bioclipse.opentox.Activator;
import net.bioclipse.rdf.business.IRDFStore;
import net.bioclipse.rdf.business.RDFManager;
import net.bioclipse.rdf.model.StringMatrix;
@@ -64,6 +65,7 @@
throws IOException {
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(service + "dataset");
+ method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT));
method.setRequestHeader("Accept", "text/uri-list");
client.executeMethod(method);
@@ -91,6 +93,7 @@ public static String normalizeURI(String datasetURI) {
HttpClient client = new HttpClient();
datasetURI = normalizeURI(datasetURI);
HttpMethod method = new GetMethod(datasetURI + "compounds");
+ method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT));
method.setRequestHeader("Accept", "text/uri-list");
client.executeMethod(method);
List<String> compounds = new ArrayList<String>();
@@ -116,6 +119,7 @@ public static StringMatrix listPredictedFeatures(String datasetURI)
String fullURI = baseURI + "feature_uris[]=" + featureURIs;
fullURI = URIUtil.encodeQuery(fullURI);
HttpMethod method = new GetMethod(fullURI);
+ method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT));
method.setRequestHeader("Accept", "application/rdf+xml");
client.executeMethod(method);
String result = method.getResponseBodyAsString(); // without this things will fail??
@@ -130,6 +134,7 @@ public static void deleteDataset(String datasetURI)
throws Exception {
HttpClient client = new HttpClient();
HttpMethod method = new DeleteMethod(datasetURI);
+ method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT));
client.executeMethod(method);
int status = method.getStatusCode();
method.releaseConnection();
@@ -166,6 +171,7 @@ public static void addMolecules(String datasetURI, String sdFile)
HttpClient client = new HttpClient();
datasetURI = normalizeURI(datasetURI);
PutMethod method = new PutMethod(datasetURI);
+ method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT));
method.setRequestHeader("Accept", "text/uri-list");
method.setRequestHeader("Content-type", "chemical/x-mdl-sdfile");
method.setRequestBody(sdFile);
@@ -226,6 +232,7 @@ public static String createNewDataset(String service, String sdFile)
throws Exception {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(service + "dataset");
+ method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT));
method.setRequestHeader("Accept", "text/uri-list");
method.setRequestHeader("Content-type", "chemical/x-mdl-sdfile");
method.setRequestBody(sdFile);
@@ -21,6 +21,8 @@
import java.io.IOException;
+import net.bioclipse.opentox.Activator;
+
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
@@ -35,6 +37,7 @@ public static String calculate(String service, String model, String dataSetURI)
HttpClient client = new HttpClient();
dataSetURI = Dataset.normalizeURI(dataSetURI);
PostMethod method = new PostMethod(model);
+ method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT));
method.setRequestHeader("Accept", "text/uri-list");
method.setParameter("dataset_uri", dataSetURI);
method.setParameter("dataset_service", service + "dataset");
@@ -21,6 +21,8 @@
import java.io.IOException;
+import net.bioclipse.opentox.Activator;
+
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
@@ -32,6 +34,7 @@ public static String calculate(String service, String descriptor, String dataSet
HttpClient client = new HttpClient();
dataSetURI = Dataset.normalizeURI(dataSetURI);
PostMethod method = new PostMethod(descriptor);
+ method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT));
method.setRequestHeader("Accept", "text/uri-list");
method.setParameter("dataset_uri", dataSetURI);
method.setParameter("dataset_service", service + "dataset");
@@ -21,6 +21,8 @@
import java.io.IOException;
+import net.bioclipse.opentox.Activator;
+
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
@@ -34,6 +36,7 @@ public static TaskState getState(String task)
throws IOException {
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(task);
+ method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT));
method.setRequestHeader("Accept", "text/uri-list");
client.executeMethod(method);
int status = method.getStatusCode();

0 comments on commit 450871e

Please sign in to comment.