to top
public interface

IHttpHelper

com.android.tradefed.util.net.IHttpHelper
Known Indirect Subclasses

Class Overview

Helper methods for performing http requests.

Summary

Nested Classes
class IHttpHelper.DataSizeException  
Constants
int MAX_DATA_SIZE
Public Methods
abstract String buildParameters(MultiMap<String, String> paramMap)
Build the encoded parameter string.
abstract String buildUrl(String url, MultiMap<String, String> paramMap)
Build the full encoded URL request string.
abstract HttpURLConnection createConnection(URL url, String method, String contentType)
Create a to given url.
abstract HttpURLConnection createJsonConnection(URL url, String method)
Creates a connection to given URL for passing json data.
abstract HttpURLConnection createXmlConnection(URL url, String method)
Creates a connection to given URL for passing xml data.
abstract String doGet(String url)
Performs a GET HTTP request method for a given URL and returns it as a String.
abstract void doGet(String url, OutputStream outputStream)
Performs a GET HTTP request method for a given URL and streams result to a OutputStream.
abstract void doGetIgnore(String url)
Performs a GET for a given URL, with the given URL parameters ignoring the result.
abstract void doGetIgnoreWithRetry(String url)
Performs {doGetIgnore(String) retrying upon failure.
abstract String doGetWithRetry(String url)
Performs {doGet(String) retrying upon failure.
abstract 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.
abstract 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.
abstract int getInitialPollInterval()
Get the initial poll interval in ms.
abstract int getMaxPollInterval()
Get the max poll interval in ms.
abstract int getMaxTime()
Get the maximum time to keep trying the request in ms.
abstract int getOpTimeout()
Get the operation timeout in ms.
abstract void setInitialPollInterval(int time)
Set the initial poll interval in ms.
abstract void setMaxPollInterval(int time)
Set the initial poll interval in ms.
abstract void setMaxTime(int time)
Set the maximum time to keep trying the request in ms.
abstract void setOpTimeout(int time)
Set the operation timeout in ms.

Constants

public static final int MAX_DATA_SIZE

Constant Value: 65536 (0x00010000)

Public Methods

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

Build the encoded parameter string.

Parameters
paramMap MultiMap: the URL parameters
Returns
String the encoded parameter string
Throws
IllegalArgumentException if an exception occurs encoding the parameters.

public abstract String buildUrl (String url, MultiMap<String, String> paramMap)

Build the full encoded URL request string.

Parameters
url String: the base URL
paramMap MultiMap: the URL parameters
Returns
String the constructed URL
Throws
IllegalArgumentException if an exception occurs encoding the parameters.

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

Create a to given url.

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

public abstract HttpURLConnection createJsonConnection (URL url, String method)

Creates a connection to given URL for passing json data.

Parameters
url URL: the URL to connect to.
method String: the HTTP request method. For example, GET or POST.
Returns
HttpURLConnection the HttpURLConnection
Throws
IOException if failed to make connection

public abstract HttpURLConnection createXmlConnection (URL url, String method)

Creates a connection to given URL for passing xml data.

Parameters
url URL: the URL to connect to.
method String: the HTTP request method. For example, GET or POST.
Returns
HttpURLConnection the HttpURLConnection
Throws
IOException if failed to make connection

public abstract 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 String: the URL
Returns
String the String remote contents
Throws
IOException if failed to retrieve data
IHttpHelper.DataSizeException if retrieved data is > MAX_DATA_SIZE

public abstract void doGet (String url, OutputStream outputStream)

Performs a GET HTTP request method for a given URL and streams result to a OutputStream.

Parameters
url String: the URL
outputStream OutputStream: stream of the response data
Throws
IOException if failed to retrieve data

See also:

public abstract void doGetIgnore (String url)

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

Parameters
url String: the URL
Throws
IOException if failed to retrieve data

See also:

public abstract void doGetIgnoreWithRetry (String url)

Performs {doGetIgnore(String) retrying upon failure.

Parameters
url String: the URL
Throws
IOException if failed to retrieve data

public abstract String doGetWithRetry (String url)

Performs {doGet(String) retrying upon failure.

Parameters
url String: the URL
Returns
String the String remote contents
Throws
IOException if failed to retrieve data
IHttpHelper.DataSizeException if retrieved data is > MAX_DATA_SIZE

public abstract 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 String: the URL
postData String: the data to be posted once the connection is open
Returns
String the String remote contents
Throws
IOException if failed to retrieve data
IHttpHelper.DataSizeException if retrieved data is > MAX_DATA_SIZE

public abstract 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 String: the URL
postData String: the data to be posted once the connection is open
contentType String: the content type. For example, "text/html".
Returns
String the String remote contents
Throws
IOException if failed to retrieve data
IHttpHelper.DataSizeException if retrieved data is > MAX_DATA_SIZE

public abstract int getInitialPollInterval ()

public abstract int getMaxPollInterval ()

public abstract int getMaxTime ()

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

Returns
int

public abstract int getOpTimeout ()

public abstract void setInitialPollInterval (int time)

Set the initial poll interval in ms.

Parameters
time int

public abstract void setMaxPollInterval (int time)

Set the initial poll interval in ms.

Parameters
time int

public abstract void setMaxTime (int time)

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

Parameters
time int

public abstract void setOpTimeout (int time)