@Override
public void authorizeHttpRequest(HttpUriRequest httpMethod, HttpContext context)
throws ServiceException
{
if (getProviderCredentials() instanceof OAuth2Credentials) {
OAuth2Tokens tokens;
try {
tokens = ((OAuth2Credentials)getProviderCredentials()).getOAuth2Tokens();
}
catch(IOException e) {
throw new ServiceException("Failure retrieving OAuth2 tokens", e);
}
if (tokens == null) {
throw new ServiceException(
"Cannot authenticate using OAuth2 until initial tokens are provided"
+ ", i.e. via setOAuth2Tokens()");
}
log.debug("Authorizing service request with OAuth2 access token: "
+ tokens.getAccessToken());
httpMethod.setHeader("Authorization", "OAuth " + tokens.getAccessToken());
httpMethod.setHeader("x-goog-api-version", "2");
} else {
super.authorizeHttpRequest(httpMethod, context);
}
}