/** * Perform a GET request against the given fully qualified uri. This is a shortcut to {@link * #request(String, String, Map)} with method "GET" and no parameters * * @param fullUri The full uri, including protocol://hostname/path * @return {@link TwilioRestResponse} the response from the query * @throws TwilioRestException the twilio rest exception */ public TwilioRestResponse get(final String fullUri) throws TwilioRestException { TwilioRestResponse response = null; for (int retry = 0; retry < numRetries; retry++) { response = request(fullUri, "GET", (Map) null); if (response.isClientError()) { throw TwilioRestException.parseResponse(response); } else if (response.isServerError()) { try { Thread.sleep(100 * retry); // Backoff on our sleep } catch (final InterruptedException e) { } continue; } return response; } int errorCode = response == null ? -1 : response.getHttpStatus(); throw new TwilioRestException("Cannot fetch: " + fullUri + " ", errorCode); }
/** * Make a request, handles retries + back-off for server/network errors * * @param path the URL (absolute w.r.t. the endpoint URL - i.e. /2010-04-01/Accounts) * @param method the HTTP method to use, defaults to GET * @param paramList for POST or PUT, a list of data to send, for GET will be appended to the URL * as querystring params * @return The response * @throws TwilioRestException if there's an client exception returned by the TwilioApi */ public TwilioRestResponse safeRequest( final String path, final String method, final List<NameValuePair> paramList) throws TwilioRestException { TwilioRestResponse response = null; for (int retry = 0; retry < numRetries; retry++) { response = request(path, method, paramList); if (response.isClientError()) { throw TwilioRestException.parseResponse(response); } else if (response.isServerError()) { try { Thread.sleep(100 * retry); // Backoff on our sleep } catch (final InterruptedException e) { } continue; } return response; } int errorCode = response == null ? -1 : response.getHttpStatus(); throw new TwilioRestException("Cannot fetch: " + method + " " + path, errorCode); }