Esempio n. 1
0
 @Override
 public int hashCode() {
   int result = statusCode;
   result = 31 * result + (request != null ? request.hashCode() : 0);
   result = 31 * result + (response != null ? response.hashCode() : 0);
   result = 31 * result + (requestPath != null ? requestPath.hashCode() : 0);
   result = 31 * result + (nested ? 1 : 0);
   return result;
 }
Esempio n. 2
0
 public String getResponseHeader(final String name) {
   String value = null;
   if (response != null) {
     final List<String> header = response.getResponseHeaderFields().get(name);
     if (header.size() > 0) {
       value = header.get(0);
     }
   }
   return value;
 }
Esempio n. 3
0
 /**
  * Returns int value of "Retry-After" response header (Search API) or seconds_until_reset (REST
  * API). An application that exceeds the rate limitations of the Search API will receive HTTP 420
  * response codes to requests. It is a best practice to watch for this error condition and honor
  * the Retry-After header that instructs the application when it is safe to continue. The
  * Retry-After header's value is the number of seconds your application should wait before
  * submitting another query (for example: Retry-After: 67).<br>
  * Check if getStatusCode() == 503 before calling this method to ensure that you are actually
  * exceeding rate limitation with query apis.<br>
  *
  * @return instructs the application when it is safe to continue in seconds
  * @see <a href="https://dev.twitter.com/docs/rate-limiting">Rate Limiting | Twitter
  *     Developers</a>
  * @since Twitter4J 2.1.0
  */
 public int getRetryAfter() {
   int retryAfter = -1;
   if (statusCode == ENHANCE_YOUR_CLAIM) {
     try {
       final String retryAfterStr = response.getResponseHeader("Retry-After");
       if (retryAfterStr != null) {
         retryAfter = Integer.valueOf(retryAfterStr);
       }
     } catch (final NumberFormatException ignore) {
     }
   }
   return retryAfter;
 }
Esempio n. 4
0
  @Override
  public boolean equals(final Object o) {
    if (this == o) return true;
    if (!(o instanceof MoefouException)) return false;

    final MoefouException that = (MoefouException) o;

    if (nested != that.nested) return false;
    if (statusCode != that.statusCode) return false;
    if (requestPath != null ? !requestPath.equals(that.requestPath) : that.requestPath != null)
      return false;
    if (response != null ? !response.equals(that.response) : that.response != null) return false;
    if (request != null ? !request.equals(that.request) : that.request != null) return false;

    return true;
  }
Esempio n. 5
0
 public MoefouException(final String message, final HttpRequest req, final HttpResponse res) {
   this(message);
   request = req;
   response = res;
   statusCode = res != null ? res.getStatusCode() : -1;
 }