use of com.salesforce.androidsdk.auth.HttpAccess.NoNetworkException in project SalesforceMobileSDK-Android by forcedotcom.
the class SalesforceDroidGapActivity method refresh.
/**
* If an action causes a redirect to the login page, this method will be called.
* It causes the session to be refreshed and reloads url through the front door.
*
* @param url the page to load once the session has been refreshed.
*/
public void refresh(final String url) {
SalesforceHybridLogger.i(TAG, "refresh called");
/*
* If client is null at this point, authentication hasn't been performed yet.
* We need to trigger authentication, and recreate the webview in the
* callback, to load the page correctly. This handles some corner cases
* involving hitting the back button when authentication is in progress.
*/
if (client == null) {
clientManager.getRestClient(this, new RestClientCallback() {
@Override
public void authenticatedRestClient(RestClient client) {
recreate();
}
});
return;
}
client.sendAsync(RestRequest.getRequestForUserInfo(), new AsyncRequestCallback() {
@Override
public void onSuccess(RestRequest request, RestResponse response) {
SalesforceHybridLogger.i(TAG, "refresh callback - refresh succeeded");
runOnUiThread(new Runnable() {
@Override
public void run() {
/*
* The client instance being used here needs to be refreshed, to ensure we
* use the new access token. However, if the refresh token was revoked
* when the app was in the background, we need to catch that exception
* and trigger a proper logout to reset the state of this class.
*/
try {
SalesforceDroidGapActivity.this.client = SalesforceDroidGapActivity.this.clientManager.peekRestClient();
final String frontDoorUrl = getFrontDoorUrl(url, BootConfig.isAbsoluteUrl(url));
loadUrl(frontDoorUrl);
} catch (AccountInfoNotFoundException e) {
SalesforceHybridLogger.i(TAG, "User has been logged out.");
logout(null);
}
}
});
}
@Override
public void onError(Exception exception) {
SalesforceHybridLogger.w(TAG, "refresh callback - refresh failed", exception);
// Only logout if we are NOT offline
if (!(exception instanceof NoNetworkException)) {
logout(null);
}
}
});
}
Aggregations