SsoClientHttpHelper

public class SsoClientHttpHelper
extends HttpHelper

java.lang.Object
   ↳ com.android.tradefed.util.net.HttpHelper
     ↳ com.google.android.tradefed.build.SsoClientHttpHelper


Contains helper methods for making http requests using the sso client binary

Summary

Public constructors

SsoClientHttpHelper()
SsoClientHttpHelper(String ssoClient, String certificate)

Public methods

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.

Protected methods

int parseHttpStatusCode(String httpStatusLine)

Parse the HTTP status code (eg.

String stripResponseHeader(String response)

Remove the header from an HTTP response from SSO client and return its body.

String validateAndAdjustResponse(String response)

Validate and adjust a HTTP response if necessary.

Public constructors

SsoClientHttpHelper

public SsoClientHttpHelper ()

SsoClientHttpHelper

public SsoClientHttpHelper (String ssoClient, 
                String certificate)

Parameters
ssoClient String

certificate String

Public methods

createConnection

public 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

createJsonConnection

public 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

createXmlConnection

public 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

doGet

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 String: the URL

Returns
String the String remote contents

Throws
IHttpHelper.DataSizeException
IOException

doGetIgnore

public 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

doGetIgnoreWithRetry

public void doGetIgnoreWithRetry (String url)

Performs {doGetIgnore(String) retrying upon failure.

Parameters
url String: the URL

Throws
IOException

doGetWithRetry

public String doGetWithRetry (String url)

Performs {doGet(String) retrying upon failure.

Parameters
url String: the URL

Returns
String the String remote contents

Throws
IHttpHelper.DataSizeException
IOException

doPostWithRetry

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 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
IHttpHelper.DataSizeException
IOException

Protected methods

parseHttpStatusCode

protected int parseHttpStatusCode (String httpStatusLine)

Parse the HTTP status code (eg. 200) from a HTTP status line (eg. HTTP/1.1 200 OK)

Parameters
httpStatusLine String

Returns
int

See also:

stripResponseHeader

protected String stripResponseHeader (String response)

Remove the header from an HTTP response from SSO client and return its body.

Parameters
response String

Returns
String

validateAndAdjustResponse

protected String validateAndAdjustResponse (String response)

Validate and adjust a HTTP response if necessary.

Parameters
response String

Returns
String