Java Code Examples for java.net.HttpURLConnection#HTTP_NOT_AUTHORITATIVE

The following examples show how to use java.net.HttpURLConnection#HTTP_NOT_AUTHORITATIVE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResponseHeaders.java    From reader with MIT License 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
Example 2
Source File: ResponseHeaders.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
Example 3
Source File: ResponseHeaders.java    From phonegap-plugin-loading-spinner with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
Example 4
Source File: ResponseHeaders.java    From wildfly-samples with MIT License 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
Example 5
Source File: ResponseHeaders.java    From cordova-android-chromeview with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
Example 6
Source File: ResponseHeaders.java    From CordovaYoutubeVideoPlayer with MIT License 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
Example 7
Source File: ResponseHeaders.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
Example 8
Source File: ResponseHeaders.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
Example 9
Source File: ResponseHeaders.java    From reader with MIT License 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
Example 10
Source File: ResponseHeaders.java    From bluemix-parking-meter with MIT License 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
Example 11
Source File: ResponseHeaders.java    From android-discourse with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
    // Always go to network for uncacheable response codes (RFC 2616, 13.4),
    // This implementation doesn't support caching partial content.
    int responseCode = headers.getResponseCode();
    if (responseCode != HttpURLConnection.HTTP_OK && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE && responseCode != HttpURLConnection.HTTP_MULT_CHOICE && responseCode != HttpURLConnection.HTTP_MOVED_PERM && responseCode != HttpURLConnection.HTTP_GONE) {
        return false;
    }

    // Responses to authorized requests aren't cacheable unless they include
    // a 'public', 'must-revalidate' or 's-maxage' directive.
    if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
        return false;
    }

    if (noStore) {
        return false;
    }

    return true;
}
 
Example 12
Source File: ResponseHeaders.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
Example 13
Source File: ResponseHeaders.java    From L.TileLayer.Cordova with MIT License 6 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
Example 14
Source File: SPARQLProtocolSession.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Convenience method to deal with HTTP level errors of tuple, graph and boolean queries in the same way. This
 * method aborts the HTTP connection.
 *
 * @param method
 * @throws RDF4JException
 */
protected HttpResponse executeOK(HttpUriRequest method) throws IOException, RDF4JException {
	boolean fail = true;
	HttpResponse response = execute(method);

	try {
		int httpCode = response.getStatusLine().getStatusCode();
		if (httpCode == HttpURLConnection.HTTP_OK || httpCode == HttpURLConnection.HTTP_NOT_AUTHORITATIVE) {
			fail = false;
			return response; // everything OK, control flow can continue
		} else {
			// trying to contact a non-SPARQL server?
			throw new RepositoryException("Request failed with status " + httpCode + ": "
					+ method.getURI().toString());
		}
	} finally {
		if (fail) {
			EntityUtils.consumeQuietly(response.getEntity());
		}
	}
}
 
Example 15
Source File: ResponseHeaders.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
    /*
     * Always go to network for uncacheable response codes (RFC 2616, 13.4),
     * This implementation doesn't support caching partial content.
     */
    int responseCode = headers.getResponseCode();
    if (responseCode != HttpURLConnection.HTTP_OK
            && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
            && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
            && responseCode != HttpURLConnection.HTTP_MOVED_PERM
            && responseCode != HttpURLConnection.HTTP_GONE) {
        return false;
    }

    /*
     * Responses to authorized requests aren't cacheable unless they include
     * a 'public', 'must-revalidate' or 's-maxage' directive.
     */
    if (request.hasAuthorization()
            && !isPublic
            && !mustRevalidate
            && sMaxAgeSeconds == -1) {
        return false;
    }

    if (noStore) {
        return false;
    }

    return true;
}
 
Example 16
Source File: DefaultSettingsSpiCallTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
public void testRequestWasSuccessful_successfulStatusCodes() {
  final int[] statusCodes = {
    HttpURLConnection.HTTP_OK,
    HttpURLConnection.HTTP_CREATED,
    HttpURLConnection.HTTP_ACCEPTED,
    HttpURLConnection.HTTP_NOT_AUTHORITATIVE
  };
  for (int statusCode : statusCodes) {
    assertTrue(defaultSettingsSpiCall.requestWasSuccessful(statusCode));
  }
}
 
Example 17
Source File: DefaultSettingsSpiCall.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
/** package private for testing */
boolean requestWasSuccessful(int httpStatusCode) {
  // We need to check against explicit 2xx status codes since status codes such as
  // 204s (HTTP_NO_CONTENT) and 205s (HTTP_RESET), are considered unsuccessful and do not
  // return a JSON response. Also, we should never get a 206 (HTTP_PARTIAL) since our request
  // does not include a Range header field.
  return httpStatusCode == HttpURLConnection.HTTP_OK
      || httpStatusCode == HttpURLConnection.HTTP_CREATED
      || httpStatusCode == HttpURLConnection.HTTP_ACCEPTED
      || httpStatusCode == HttpURLConnection.HTTP_NOT_AUTHORITATIVE;
}
 
Example 18
Source File: Sentry.java    From Sentry-Android with MIT License 4 votes vote down vote up
/**
 * Map from HTTP status code to reason description.
 * Sentry HTTP breadcrumbs expect a text description of the HTTP status-code.
 * This function implements a look-up table with a default value for unknown status-codes.
 * @param statusCode an integer HTTP status code, expected to be in the range [200,505].
 * @return a non-empty string in all cases.
 */
private static String httpReason(int statusCode) {
    switch (statusCode) {
        // 2xx
        case HttpURLConnection.HTTP_OK: return "OK";
        case HttpURLConnection.HTTP_CREATED: return "Created";
        case HttpURLConnection.HTTP_ACCEPTED: return "Accepted";
        case HttpURLConnection.HTTP_NOT_AUTHORITATIVE: return "Non-Authoritative Information";
        case HttpURLConnection.HTTP_NO_CONTENT: return "No Content";
        case HttpURLConnection.HTTP_RESET: return "Reset Content";
        case HttpURLConnection.HTTP_PARTIAL: return "Partial Content";

        // 3xx
        case HttpURLConnection.HTTP_MULT_CHOICE: return "Multiple Choices";
        case HttpURLConnection.HTTP_MOVED_PERM: return "Moved Permanently";
        case HttpURLConnection.HTTP_MOVED_TEMP: return "Temporary Redirect";
        case HttpURLConnection.HTTP_SEE_OTHER: return "See Other";
        case HttpURLConnection.HTTP_NOT_MODIFIED: return "Not Modified";
        case HttpURLConnection.HTTP_USE_PROXY: return "Use Proxy";

        // 4xx
        case HttpURLConnection.HTTP_BAD_REQUEST: return "Bad Request";
        case HttpURLConnection.HTTP_UNAUTHORIZED: return "Unauthorized";
        case HttpURLConnection.HTTP_PAYMENT_REQUIRED: return "Payment Required";
        case HttpURLConnection.HTTP_FORBIDDEN: return "Forbidden";
        case HttpURLConnection.HTTP_NOT_FOUND: return "Not Found";
        case HttpURLConnection.HTTP_BAD_METHOD: return "Method Not Allowed";
        case HttpURLConnection.HTTP_NOT_ACCEPTABLE: return "Not Acceptable";
        case HttpURLConnection.HTTP_PROXY_AUTH: return "Proxy Authentication Required";
        case HttpURLConnection.HTTP_CLIENT_TIMEOUT: return "Request Time-Out";
        case HttpURLConnection.HTTP_CONFLICT: return "Conflict";
        case HttpURLConnection.HTTP_GONE: return "Gone";
        case HttpURLConnection.HTTP_LENGTH_REQUIRED: return "Length Required";
        case HttpURLConnection.HTTP_PRECON_FAILED: return "Precondition Failed";
        case HttpURLConnection.HTTP_ENTITY_TOO_LARGE: return "Request Entity Too Large";
        case HttpURLConnection.HTTP_REQ_TOO_LONG: return "Request-URI Too Large";
        case HttpURLConnection.HTTP_UNSUPPORTED_TYPE: return "Unsupported Media Type";

        // 5xx
        case HttpURLConnection.HTTP_INTERNAL_ERROR: return "Internal Server Error";
        case HttpURLConnection.HTTP_NOT_IMPLEMENTED: return "Not Implemented";
        case HttpURLConnection.HTTP_BAD_GATEWAY: return "Bad Gateway";
        case HttpURLConnection.HTTP_UNAVAILABLE: return "Service Unavailable";
        case HttpURLConnection.HTTP_GATEWAY_TIMEOUT: return "Gateway Timeout";
        case HttpURLConnection.HTTP_VERSION: return "Version Not Supported";

        default: return "unknown";
    }
}