IHttpHelper

public interface IHttpHelper

com.android.tradefed.util.net.IHttpHelper
Known Indirect Subclasses
HttpHelper Contains helper methods for making http requests  


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

MAX_DATA_SIZE

int MAX_DATA_SIZE

Constant Value: 65536 (0x00010000)

Public methods

buildParameters

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.

buildUrl

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.

createConnection

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.

createJsonConnection

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

createXmlConnection

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

doGet

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

doGet

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:

doGetIgnore

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:

doGetIgnoreWithRetry

void doGetIgnoreWithRetry (String url)

Performs {doGetIgnore(String) retrying upon failure.

Parameters
url String: the URL

Throws
IOException if failed to retrieve data

doGetWithRetry

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

doPostWithRetry

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

doPostWithRetry

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

getInitialPollInterval

int getInitialPollInterval ()

Get the initial poll interval in ms.

Returns
int

getMaxPollInterval

int getMaxPollInterval ()

Get the max poll interval in ms.

Returns
int

getMaxTime

int getMaxTime ()

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

Returns
int

getOpTimeout

int getOpTimeout ()

Get the operation timeout in ms.

Returns
int

setInitialPollInterval

void setInitialPollInterval (int time)

Set the initial poll interval in ms.

Parameters
time int

setMaxPollInterval

void setMaxPollInterval (int time)

Set the initial poll interval in ms.

Parameters
time int

setMaxTime

void setMaxTime (int time)

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

Parameters
time int

setOpTimeout

void setOpTimeout (int time)

Set the operation timeout in ms.

Parameters
time int