Class HttpCredentialsAdapter (1.35.0) (original) (raw)

Class HttpCredentialsAdapter (1.35.0)

Stay organized with collections Save and categorize content based on your preferences.

public class HttpCredentialsAdapter implements HttpRequestInitializer, HttpUnsuccessfulResponseHandler

A wrapper for using Credentials with the Google API Client Libraries for Java with Http.

Implements

com.google.api.client.http.HttpRequestInitializer, com.google.api.client.http.HttpUnsuccessfulResponseHandler

Inherited Members

Constructors

HttpCredentialsAdapter(Credentials credentials)

public HttpCredentialsAdapter(Credentials credentials)
Parameter
Name Description
credentials CredentialsCredentials instance to adapt for HTTP

Methods

getCredentials()

public Credentials getCredentials()

A getter for the credentials instance being used

Returns
Type Description
Credentials

handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry)

public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry)

Checks if WWW-Authenticate exists and contains a "Bearer" value (see rfc6750 section 3.1 for more details). If so, it refreshes the token in case the error code contains invalid_token. If there is no "Bearer" in WWW-Authenticate and the status code is HttpStatusCodes#STATUS_CODE_UNAUTHORIZED it refreshes the token. If the token refresh throws an I/O exception, this implementation will log the exception and return false.

Parameters
Name Description
request com.google.api.client.http.HttpRequest
response com.google.api.client.http.HttpResponse
supportsRetry boolean
Returns
Type Description
boolean

initialize(HttpRequest request)

public void initialize(HttpRequest request)

Initialize the HTTP request prior to execution.

Parameter
Name Description
request com.google.api.client.http.HttpRequestHTTP request
Exceptions
Type Description
IOException

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-05-14 UTC.