Implement timeout into HTTP calls to prevent freezes

This commit is contained in:
Kenny 2016-12-12 21:12:15 -05:00 committed by Shaun Bennett
parent 77a1b40bef
commit 1b76de9e06

View File

@ -8,6 +8,7 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
@ -21,9 +22,14 @@ import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
public abstract class DnsMadeEasyApiCallBase
{
public static final int TIMEOUT = (int) TimeUnit.SECONDS.toMillis(60);
protected String ApiUrl = "http://api.dnsmadeeasy.com/V2.0/dns/managed/";
protected int DomainId = 962728;
protected String Category = "/records/";
@ -44,7 +50,9 @@ public abstract class DnsMadeEasyApiCallBase
connectionManager.setMaxTotal(200);
connectionManager.setDefaultMaxPerRoute(20);
HttpClient httpClient = new DefaultHttpClient(connectionManager);
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);
HttpClient httpClient = new DefaultHttpClient(connectionManager, params);
InputStream in = null;
String response = "";