to top
public class

HttpHelper

extends Object
implements IHttpHelper
java.lang.Object
   ↳ com.android.tradefed.util.net.HttpHelper

Class Overview

Contains helper methods for making http requests

Summary

[Expand]
Inherited Constants
From interface com.android.tradefed.util.net.IHttpHelper
Public Constructors
HttpHelper()
Public Methods
String buildParameters(MultiMap<String, String> paramMap)
Build the encoded parameter string.
String buildUrl(String baseUrl, MultiMap<String, String> paramMap)
Build the full encoded URL request string.
HttpURLConnection createConnection(URL url, String method, String contentType)
Create a to given url.
HttpURLConnection createJsonConnection(URL url, String method)
Creates a connection to given URL for passing json data.
HttpURLConnection createXmlConnection(URL url, String method)
Creates a connection to given URL for passing xml data.
String doGet(String url)
Performs a GET HTTP request method for a given URL and returns it as a String.
void doGetIgnore(String url)
Performs a GET for a given URL, with the given URL parameters ignoring the result.
void doGetIgnoreWithRetry(String url)
Performs {doGetIgnore(String) retrying upon failure.
String doGetWithRetry(String url)
Performs {doGet(String) retrying upon failure.
String doPostWithRetry(String url, String postData, String contentType)
Performs a POST HTTP request method for a given URL and returns it as a String, retrying upon failure.
String doPostWithRetry(String url, String postData)
Performs a POST HTTP request method for a given URL and returns it as a String, retrying upon failure.
int getInitialPollInterval()
Get the initial poll interval in ms.
int getMaxPollInterval()
Get the max poll interval in ms.
int getMaxTime()
Get the maximum time to keep trying the request in ms.
int getOpTimeout()
Get the operation timeout in ms.
void setInitialPollInterval(int time)
Set the initial poll interval in ms.
void setMaxPollInterval(int time)
Set the initial poll interval in ms.
void setMaxTime(int time)
Set the maximum time to keep trying the request in ms.
void setOpTimeout(int time)
Set the operation timeout in ms.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.android.tradefed.util.net.IHttpHelper

Public Constructors

public HttpHelper ()

Public Methods

public String buildParameters (MultiMap<String, String> paramMap)

Build the encoded parameter string.

Parameters
paramMap the URL parameters
Returns
  • the encoded parameter string

public String buildUrl (String baseUrl, MultiMap<String, String> paramMap)

Build the full encoded URL request string.

Parameters
baseUrl the base URL
paramMap the URL parameters
Returns
  • the constructed URL

public HttpURLConnection createConnection (URL url, String method, String contentType)

Create a to given url.

Parameters
url the URL to connect to.
method the HTTP request method. For example, GET or POST.
contentType the content type. For example, "text/html".
Returns
  • The HttpURLConnection
Throws
IOException

public HttpURLConnection createJsonConnection (URL url, String method)

Creates a connection to given URL for passing json data.

Parameters
url the URL to connect to.
method the HTTP request method. For example, GET or POST.
Returns
Throws
IOException

public HttpURLConnection createXmlConnection (URL url, String method)

Creates a connection to given URL for passing xml data.

Parameters
url the URL to connect to.
method the HTTP request method. For example, GET or POST.
Returns
Throws
IOException

public String doGet (String url)

Performs a GET HTTP request method for a given URL and returns it as a String.

Because remote contents are loaded into memory, this method should only be used for relatively small data sizes.

References:

Parameters
url the URL
Returns
Throws
IOException
IHttpHelper.DataSizeException

public void doGetIgnore (String url)

Performs a GET for a given URL, with the given URL parameters ignoring the result.

Parameters
url the URL
Throws
IOException

public void doGetIgnoreWithRetry (String url)

Performs {doGetIgnore(String) retrying upon failure.

Parameters
url the URL
Throws
IOException

public String doGetWithRetry (String url)

Performs {doGet(String) retrying upon failure.

Parameters
url the URL
Returns
Throws
IOException
IHttpHelper.DataSizeException

public String doPostWithRetry (String url, String postData, String contentType)

Performs a POST HTTP request method for a given URL and returns it as a String, retrying upon failure.

Because remote contents are loaded into memory, this method should only be used for relatively small data sizes.

Parameters
url the URL
postData the data to be posted once the connection is open
contentType the content type. For example, "text/html".
Returns
Throws
IOException
IHttpHelper.DataSizeException

public String doPostWithRetry (String url, String postData)

Performs a POST HTTP request method for a given URL and returns it as a String, retrying upon failure.

Because remote contents are loaded into memory, this method should only be used for relatively small data sizes.

Parameters
url the URL
postData the data to be posted once the connection is open
Returns
Throws
IOException
IHttpHelper.DataSizeException

public int getInitialPollInterval ()

Get the initial poll interval in ms.

public int getMaxPollInterval ()

Get the max poll interval in ms.

public int getMaxTime ()

Get the maximum time to keep trying the request in ms.

public int getOpTimeout ()

Get the operation timeout in ms.

public void setInitialPollInterval (int time)

Set the initial poll interval in ms.

public void setMaxPollInterval (int time)

Set the initial poll interval in ms.

public void setMaxTime (int time)

Set the maximum time to keep trying the request in ms.

public void setOpTimeout (int time)

Set the operation timeout in ms.