IHttpHelper

public interface IHttpHelper

com.android.tradefed.util.net.IHttpHelper


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

public static final int MAX_DATA_SIZE

Constant Value: 65536 (0x00010000)

Public methods

buildParameters

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.

buildUrl

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.

createConnection

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.

createJsonConnection

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

createXmlConnection

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

doGet

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

doGet

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:

doGetIgnore

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:

doGetIgnoreWithRetry

public abstract void doGetIgnoreWithRetry (String url)

Performs {doGetIgnore(String) retrying upon failure.

Parameters
url String: the URL

Throws
IOException if failed to retrieve data

doGetWithRetry

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

doPostWithRetry

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

doPostWithRetry

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

getInitialPollInterval

public abstract int getInitialPollInterval ()

Get the initial poll interval in ms.

Returns
int

getMaxPollInterval

public abstract int getMaxPollInterval ()

Get the max poll interval in ms.

Returns
int

getMaxTime

public abstract int getMaxTime ()

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

Returns
int

getOpTimeout

public abstract int getOpTimeout ()

Get the operation timeout in ms.

Returns
int

setInitialPollInterval

public abstract void setInitialPollInterval (int time)

Set the initial poll interval in ms.

Parameters
time int

setMaxPollInterval

public abstract void setMaxPollInterval (int time)

Set the initial poll interval in ms.

Parameters
time int

setMaxTime

public abstract void setMaxTime (int time)

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

Parameters
time int

setOpTimeout

public abstract void setOpTimeout (int time)

Set the operation timeout in ms.

Parameters
time int