GoogleApiClientUtil

public class GoogleApiClientUtil
extends Object

java.lang.Object
   ↳ com.android.tradefed.util.GoogleApiClientUtil


Utils for create Google API client.

Summary

Fields

public static final String APP_NAME

Public constructors

GoogleApiClientUtil()

Public methods

static HttpRequestInitializer configureRetryStrategy(HttpRequestInitializer initializer)

Setup a retry strategy for the provided HttpRequestInitializer.

static HttpRequestInitializer configureRetryStrategyAndTimeout(HttpRequestInitializer initializer, int connectTimeout, int readTimeout)

Setup a retry strategy for the provided HttpRequestInitializer.

static Credential createCredential( scopes, File primaryKeyFile, String hostOptionKeyFileName, File... backupKeyFiles)

Try to create credential with different key files or from local host.

static Credential createCredential( scopes, boolean useCredentialFactory, File primaryKeyFile, String hostOptionKeyFileName, File... backupKeyFiles)

Try to create credential with different key files or from local host.

static Credential createCredentialFromJsonKeyFile(File file, scopes)

Create credential from json key file.

static Credential createCredentialFromP12File(String serviceAccount, File keyFile, scopes)

This method is deprecated. It's better to use json key file, since p12 is deprecated by Google App Engine. And json key file have more information.

static HttpRequestInitializer setHttpTimeout(HttpRequestInitializer requestInitializer, int connectTimeout, int readTimeout)

Fields

APP_NAME

public static final String APP_NAME

Public constructors

GoogleApiClientUtil

public GoogleApiClientUtil ()

Public methods

configureRetryStrategy

public static HttpRequestInitializer configureRetryStrategy (HttpRequestInitializer initializer)

Setup a retry strategy for the provided HttpRequestInitializer. In case of server errors requests will be automatically retried with an exponential backoff.

Parameters
initializer HttpRequestInitializer: - an initializer which will setup a retry strategy.

Returns
HttpRequestInitializer an initializer that will retry failed requests automatically.

configureRetryStrategyAndTimeout

public static HttpRequestInitializer configureRetryStrategyAndTimeout (HttpRequestInitializer initializer, 
                int connectTimeout, 
                int readTimeout)

Setup a retry strategy for the provided HttpRequestInitializer. In case of server errors requests will be automatically retried with an exponential backoff.

Parameters
initializer HttpRequestInitializer: - an initializer which will setup a retry strategy.

connectTimeout int

readTimeout int

Returns
HttpRequestInitializer an initializer that will retry failed requests automatically.

createCredential

public static Credential createCredential ( scopes, 
                File primaryKeyFile, 
                String hostOptionKeyFileName, 
                File... backupKeyFiles)

Try to create credential with different key files or from local host.

1. If primaryKeyFile is set, try to use it to create credential. 2. Try to get corresponding key files from HostOptions. 3. Try to use backup key files. 4. Use local default credential.

Parameters
scopes : scopes for the credential.

primaryKeyFile File: the primary json key file; it can be null.

hostOptionKeyFileName String: HostOptions'service-account-json-key-file option's key; it can be null.

backupKeyFiles File: backup key files.

Returns
Credential a Credential

Throws
IOException

createCredential

public static Credential createCredential ( scopes, 
                boolean useCredentialFactory, 
                File primaryKeyFile, 
                String hostOptionKeyFileName, 
                File... backupKeyFiles)

Try to create credential with different key files or from local host.

1. Use ICredentialFactory if useCredentialFactory is true and a ICredentialFactory is configured. If primaryKeyFile is set, try to use it to create credential. 2. Try to get corresponding key files from HostOptions. 3. Try to use backup key files. 4. Use local default credential.

Parameters
scopes : scopes for the credential.

useCredentialFactory boolean: use credential factory if it's configured.

primaryKeyFile File: the primary json key file; it can be null.

hostOptionKeyFileName String: HostOptions'service-account-json-key-file option's key; it can be null.

backupKeyFiles File: backup key files.

Returns
Credential a Credential

Throws
IOException

createCredentialFromJsonKeyFile

public static Credential createCredentialFromJsonKeyFile (File file, 
                 scopes)

Create credential from json key file.

Parameters
file File: is the p12 key file

scopes : is the API's scope.

Returns
Credential a Credential.

Throws
FileNotFoundException
IOException

createCredentialFromP12File

public static Credential createCredentialFromP12File (String serviceAccount, 
                File keyFile, 
                 scopes)

This method is deprecated.
It's better to use json key file, since p12 is deprecated by Google App Engine. And json key file have more information.

Create credential from p12 file for service account.

Parameters
serviceAccount String: is the service account

keyFile File: is the p12 key file

scopes : is the API's scope.

Returns
Credential a Credential.

Throws
GeneralSecurityException

setHttpTimeout

public static HttpRequestInitializer setHttpTimeout (HttpRequestInitializer requestInitializer, 
                int connectTimeout, 
                int readTimeout)

Parameters
requestInitializer HttpRequestInitializer: a HttpRequestInitializer, normally it's Credential.

connectTimeout int: connect timeout in milliseconds.

readTimeout int: read timeout in milliseconds.

Returns
HttpRequestInitializer a HttpRequestInitializer with timeout.