protected AccessToken _renewToken(AccessToken token) throws OAuthException {
readConsumerToken();
if (token == null) {
token = acquireToken();
if (token == null) {
throw new OAuthException(null, "No user token is available");
}
}
Context context = Context.get();
try {
getAccessTokenFromServer();
token = createToken(getAppId(), getServiceName(), this, token.getUserId());
setAccessTokenObject(token);
if (!Context.get().isCurrentUserAnonymous()) {
CredentialStore credStore = findCredentialStore();
if (credStore != null) {
try {
// if the token is already present, and was expired due to which we have fetched a new
// token, then we remove the token from the store first and then add this new token.
deleteToken();
credStore.store(getServiceName(), ACCESS_TOKEN_STORE_TYPE, getUserId(), token);
} catch (CredentialStoreException cse) {
throw new OAuthException(cse);
}
}
} else {
AnonymousCredentialStore.storeCredentials(Context.get(), token, getAppId(), getServiceName());
}
//
} catch (IOException e) {
throw new OAuthException(e);
} catch (URISyntaxException e) {
throw new OAuthException(e);
} catch (OAuthException e) {
// We cannot renew the token, so we ask for a brand new one...
Platform.getInstance().log(e);
acquireToken(true, true);
return null;
} catch (CredentialStoreException cse) {
throw new OAuthException(cse, "Error trying to renew Token.");
} catch (Exception e) {
throw new OAuthException(e);
}
return token;
}