/** * Look for an OAuth protocol problem. For cases where no access token is in play * @param response * @throws OAuthProtocolException */ private void checkForProtocolProblem(HttpResponse response) throws OAuthProtocolException { if (couldBeFullOAuthError(response)) { // OK, might be OAuth related. OAuthMessage message = parseAuthHeader(null, response); if (OAuthUtil.getParameter(message, OAuthProblemException.OAUTH_PROBLEM) != null) { // SP reported extended error information throw new OAuthProtocolException(response.getHttpStatusCode(), message); } // No extended information, guess based on HTTP response code. if (response.getHttpStatusCode() == HttpResponse.SC_UNAUTHORIZED) { throw new OAuthProtocolException(response.getHttpStatusCode()); } } }
/** * Fetch data, retrying in the event that that the service provider returns an error and we think * we can recover by restarting the protocol flow. */ private HttpResponseBuilder fetchWithRetry() throws OAuthRequestException { int attempts = 0; boolean retry; HttpResponseBuilder response = null; do { retry = false; ++attempts; try { response = attemptFetch(); } catch (OAuthProtocolException pe) { retry = handleProtocolException(pe, attempts); if (!retry) { if (pe.getProblemCode() != null) { throw new OAuthRequestException(pe.getProblemCode(), "Service provider rejected request", pe); } else { throw new OAuthRequestException(OAuthError.UNKNOWN_PROBLEM, "Service provider rejected request", pe); } } } } while (retry); return response; }
private boolean handleProtocolException(OAuthProtocolException pe, int attempts) throws OAuthRequestException { if (pe.canExtend()) { accessorInfo.setTokenExpireMillis(ACCESS_TOKEN_FORCE_EXPIRE); } else if (pe.startFromScratch()) { fetcherConfig.getTokenStore().removeToken(realRequest.getSecurityToken(), accessorInfo.getConsumer(), realRequest.getOAuthArguments(), responseParams); accessorInfo.getAccessor().accessToken = null; accessorInfo.getAccessor().requestToken = null; accessorInfo.getAccessor().tokenSecret = null; accessorInfo.setSessionHandle(null); accessorInfo.setTokenExpireMillis(ACCESS_TOKEN_EXPIRE_UNKNOWN); } return (attempts < MAX_ATTEMPTS && pe.canRetry()); }
private boolean handleProtocolException(OAuthProtocolException pe, int attempts) throws OAuthRequestException { if (pe.canExtend()) { accessorInfo.setTokenExpireMillis(ACCESS_TOKEN_FORCE_EXPIRE); } else if (pe.startFromScratch()) { fetcherConfig.getTokenStore().removeToken(realRequest.getSecurityToken(), accessorInfo.getConsumer(), realRequest.getOAuthArguments(), responseParams); accessorInfo.getAccessor().accessToken = null; accessorInfo.getAccessor().requestToken = null; accessorInfo.getAccessor().tokenSecret = null; accessorInfo.setSessionHandle(null); accessorInfo.setTokenExpireMillis(ACCESS_TOKEN_EXPIRE_UNKNOWN); } return (attempts < MAX_ATTEMPTS && pe.canRetry()); }
private boolean handleProtocolException(OAuthProtocolException pe, int attempts) throws OAuthRequestException { if (pe.canExtend()) { accessorInfo.setTokenExpireMillis(ACCESS_TOKEN_FORCE_EXPIRE); } else if (pe.startFromScratch()) { fetcherConfig.getTokenStore().removeToken(realRequest.getSecurityToken(), accessorInfo.getConsumer(), realRequest.getOAuthArguments(), responseParams); accessorInfo.getAccessor().accessToken = null; accessorInfo.getAccessor().requestToken = null; accessorInfo.getAccessor().tokenSecret = null; accessorInfo.setSessionHandle(null); accessorInfo.setTokenExpireMillis(ACCESS_TOKEN_EXPIRE_UNKNOWN); } return (attempts < MAX_ATTEMPTS && pe.canRetry()); }
/** * Look for an OAuth protocol problem. For cases where no access token is in play * @param response * @throws OAuthProtocolException */ private void checkForProtocolProblem(HttpResponse response) throws OAuthProtocolException { if (couldBeFullOAuthError(response)) { // OK, might be OAuth related. OAuthMessage message = parseAuthHeader(null, response); if (OAuthUtil.getParameter(message, OAuthProblemException.OAUTH_PROBLEM) != null) { // SP reported extended error information throw new OAuthProtocolException(response.getHttpStatusCode(), message); } // No extended information, guess based on HTTP response code. if (response.getHttpStatusCode() == HttpResponse.SC_UNAUTHORIZED) { throw new OAuthProtocolException(response.getHttpStatusCode()); } } }
/** * Fetch data, retrying in the event that that the service provider returns an error and we think * we can recover by restarting the protocol flow. */ private HttpResponseBuilder fetchWithRetry() throws OAuthRequestException { int attempts = 0; boolean retry; HttpResponseBuilder response = null; do { retry = false; ++attempts; try { response = attemptFetch(); } catch (OAuthProtocolException pe) { retry = handleProtocolException(pe, attempts); if (!retry) { if (pe.getProblemCode() != null) { throw new OAuthRequestException(pe.getProblemCode(), "Service provider rejected request", pe); } else { throw new OAuthRequestException(OAuthError.UNKNOWN_PROBLEM, "Service provider rejected request", pe); } } } } while (retry); return response; }
/** * Look for an OAuth protocol problem. For cases where no access token is in play * @param response * @throws OAuthProtocolException */ private void checkForProtocolProblem(HttpResponse response) throws OAuthProtocolException { if (couldBeFullOAuthError(response)) { // OK, might be OAuth related. OAuthMessage message = parseAuthHeader(null, response); if (OAuthUtil.getParameter(message, OAuthProblemException.OAUTH_PROBLEM) != null) { // SP reported extended error information throw new OAuthProtocolException(response.getHttpStatusCode(), message); } // No extended information, guess based on HTTP response code. if (response.getHttpStatusCode() == HttpResponse.SC_UNAUTHORIZED) { throw new OAuthProtocolException(response.getHttpStatusCode()); } } }
/** * Fetch data, retrying in the event that that the service provider returns an error and we think * we can recover by restarting the protocol flow. */ private HttpResponseBuilder fetchWithRetry() throws OAuthRequestException { int attempts = 0; boolean retry; HttpResponseBuilder response = null; do { retry = false; ++attempts; try { response = attemptFetch(); } catch (OAuthProtocolException pe) { retry = handleProtocolException(pe, attempts); if (!retry) { if (pe.getProblemCode() != null) { throw new OAuthRequestException(pe.getProblemCode(), "Service provider rejected request", pe); } else { throw new OAuthRequestException(OAuthError.UNKNOWN_PROBLEM, "Service provider rejected request", pe); } } } } while (retry); return response; }