Implement timeout into HTTP calls to prevent freezes
This commit is contained in:
parent
77a1b40bef
commit
1b76de9e06
@ -8,6 +8,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
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.conn.scheme.SchemeRegistry;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
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 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 String ApiUrl = "http://api.dnsmadeeasy.com/V2.0/dns/managed/";
|
||||||
protected int DomainId = 962728;
|
protected int DomainId = 962728;
|
||||||
protected String Category = "/records/";
|
protected String Category = "/records/";
|
||||||
@ -44,7 +50,9 @@ public abstract class DnsMadeEasyApiCallBase
|
|||||||
connectionManager.setMaxTotal(200);
|
connectionManager.setMaxTotal(200);
|
||||||
connectionManager.setDefaultMaxPerRoute(20);
|
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;
|
InputStream in = null;
|
||||||
String response = "";
|
String response = "";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user