Java Code Examples for java.net.HttpURLConnection#HTTP_NOT_ACCEPTABLE

The following examples show how to use java.net.HttpURLConnection#HTTP_NOT_ACCEPTABLE . 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: DefaultSettingsSpiCallTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
public void testRequestWasSuccessful_unsuccessfulStatusCodes() {
  // 204 and 205 are considered unsuccessful in this case, and 206 should never happen. Also
  // test with some of the other common status codes (these are ones that our backend has
  // been known to return).
  final int[] statusCodes = {
    HttpURLConnection.HTTP_NO_CONTENT,
    HttpURLConnection.HTTP_RESET,
    HttpURLConnection.HTTP_PARTIAL,
    HttpURLConnection.HTTP_BAD_REQUEST,
    HttpURLConnection.HTTP_UNAUTHORIZED,
    HttpURLConnection.HTTP_FORBIDDEN,
    HttpURLConnection.HTTP_NOT_FOUND,
    HttpURLConnection.HTTP_NOT_ACCEPTABLE,
    HttpURLConnection.HTTP_INTERNAL_ERROR,
    HttpURLConnection.HTTP_BAD_GATEWAY,
    HttpURLConnection.HTTP_UNAVAILABLE,
    HttpURLConnection.HTTP_GATEWAY_TIMEOUT
  };
  for (int statusCode : statusCodes) {
    assertFalse(defaultSettingsSpiCall.requestWasSuccessful(statusCode));
  }
}
 
Example 2
Source File: ProtocolTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Checks that a proper error (HTTP 406) is returned when accept header is set incorrectly on graph query.
 */
@Test
public void testContentTypeForGraphQuery2_GET() throws Exception {
	String query = "DESCRIBE <foo:bar>";
	String location = TestServer.REPOSITORY_URL;
	location += "?query=" + URLEncoder.encode(query, "UTF-8");

	URL url = new URL(location);

	HttpURLConnection conn = (HttpURLConnection) url.openConnection();

	// incorrect mime-type for graph query results
	conn.setRequestProperty("Accept", TupleQueryResultFormat.SPARQL.getDefaultMIMEType());

	conn.connect();

	try {
		int responseCode = conn.getResponseCode();
		if (responseCode == HttpURLConnection.HTTP_NOT_ACCEPTABLE) {
			// do nothing, expected
		} else {
			String response = "location " + location + " responded: " + conn.getResponseMessage() + " ("
					+ responseCode + ")";
			fail(response);
		}
	} finally {
		conn.disconnect();
	}
}
 
Example 3
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";
    }
}