From 6bbb6ef6570f2e51cbca16a6b7b1bcb633b36854 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 18 Feb 2013 08:49:20 +0100 Subject: [PATCH] Set timeout for HTTP connections. --- src/main/java/net/pterodactylus/rhynodge/queries/HttpQuery.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/net/pterodactylus/rhynodge/queries/HttpQuery.java b/src/main/java/net/pterodactylus/rhynodge/queries/HttpQuery.java index 05f0830..d0e3545 100644 --- a/src/main/java/net/pterodactylus/rhynodge/queries/HttpQuery.java +++ b/src/main/java/net/pterodactylus/rhynodge/queries/HttpQuery.java @@ -19,6 +19,7 @@ package net.pterodactylus.rhynodge.queries; import java.io.IOException; import java.io.InputStreamReader; +import java.util.concurrent.TimeUnit; import net.pterodactylus.rhynodge.Query; import net.pterodactylus.rhynodge.State; @@ -31,6 +32,7 @@ import org.apache.http.HttpStatus; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.protocol.ResponseContentEncoding; import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.params.HttpConnectionParams; import org.apache.http.util.EntityUtils; import com.google.common.io.Closeables; @@ -73,6 +75,8 @@ public class HttpQuery implements Query { try { /* make request. */ get.addHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Ubuntu/12.04 Chromium/20.0.1132.47 Chrome/20.0.1132.47 Safari/536.11"); + HttpConnectionParams.setConnectionTimeout(get.getParams(), (int) TimeUnit.SECONDS.toMillis(300)); + HttpConnectionParams.setSoTimeout(get.getParams(), (int) TimeUnit.SECONDS.toMillis(300)); HttpResponse response = httpClient.execute(get); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { return new FailedState(); -- 2.7.4