aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-08-08 03:05:42 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-08-08 03:05:42 +0000
commitfaa332a10783891b2d62c9453302be12e2d9f1c5 (patch)
tree3c9e13f45e9c8f9f1c9a3b298c032b115ed5f3d5
parent267abd33060a0185ec5dc64d573211da06576357 (diff)
parentf9ac079d5db6e70c2c0ead8cdb15cc1a0c8c43c2 (diff)
downloadsl4a-android10-c2f2-release.tar.gz
Change-Id: I48a721da4585518012bcdd85f646bb289137a856
-rw-r--r--Common/src/com/googlecode/android_scripting/facade/wifi/HttpFacade.java18
1 files changed, 13 insertions, 5 deletions
diff --git a/Common/src/com/googlecode/android_scripting/facade/wifi/HttpFacade.java b/Common/src/com/googlecode/android_scripting/facade/wifi/HttpFacade.java
index 6f173b52..0d3d8875 100644
--- a/Common/src/com/googlecode/android_scripting/facade/wifi/HttpFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/wifi/HttpFacade.java
@@ -96,13 +96,19 @@ public class HttpFacade extends RpcReceiver {
* Send an http request and get the response.
*
* @param url The url to send request to.
+ * @param timeout Time to load the page
* @return The HttpURLConnection object.
*/
- private HttpURLConnection httpRequest(String url) throws IOException {
+ private HttpURLConnection httpRequest(String url, Integer timeout) throws IOException {
+ if (timeout == null) {
+ timeout = 50000;
+ }
URL targetURL = new URL(url);
HttpURLConnection urlConnection;
try {
urlConnection = (HttpURLConnection) targetURL.openConnection();
+ urlConnection.setConnectTimeout(9000);
+ urlConnection.setReadTimeout(timeout);
urlConnection.connect();
int respCode = urlConnection.getResponseCode();
String respMsg = urlConnection.getResponseMessage();
@@ -132,7 +138,7 @@ public class HttpFacade extends RpcReceiver {
public void httpDownloadFile(@RpcParameter(name = "url") String url,
@RpcParameter(name="outPath") @RpcOptional String outPath) throws IOException {
// Create the input stream
- HttpURLConnection urlConnection = httpRequest(url);
+ HttpURLConnection urlConnection = httpRequest(url, null);
// Parse destination path and create the output stream. The function assumes that the path
// is specified relative to the system default Download dir.
File outFile = FileUtils.getExternalDownload();
@@ -179,10 +185,12 @@ public class HttpFacade extends RpcReceiver {
}
@Rpc(description = "Make an http request and return the response message.")
- public HttpURLConnection httpPing(@RpcParameter(name = "url") String url) throws IOException {
+ public HttpURLConnection httpPing(
+ @RpcParameter(name = "url") String url,
+ @RpcParameter(name = "timeout") @RpcOptional Integer timeout) throws IOException {
try {
HttpURLConnection urlConnection = null;
- urlConnection = httpRequest(url);
+ urlConnection = httpRequest(url, timeout);
urlConnection.disconnect();
return urlConnection;
} catch (UnknownHostException e) {
@@ -192,7 +200,7 @@ public class HttpFacade extends RpcReceiver {
@Rpc(description = "Make an http request and return the response content as a string.")
public String httpRequestString(@RpcParameter(name = "url") String url) throws IOException {
- HttpURLConnection urlConnection = httpRequest(url);
+ HttpURLConnection urlConnection = httpRequest(url, null);
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
String result = inputStreamToString(in);
Log.d("Fetched: " + result);