Class KiwiHttpResponses

java.lang.Object
org.kiwiproject.net.KiwiHttpResponses

public final class KiwiHttpResponses extends Object
Static utilities related to HTTP responses, mainly for checking status codes.

The utilities here mainly make reading code more pleasant, since they use words instead of just HTTP status codes.

This has no dependencies on any specific web or REST libraries. If you are using Jakarta RESTful Web Services, you can also use KiwiResponses.

  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    accepted(int statusCode)
    Check if the given status code is 202 Accepted.
    static boolean
    badGateway(int statusCode)
    Check if the given status code is 502 Bad Gateway.
    static boolean
    badRequest(int statusCode)
    Check if the given status code is 400 Bad Request.
    static boolean
    clientError(int statusCode)
    Check if the given status code is in the client error family (4xx codes).
    static boolean
    conflict(int statusCode)
    Check if the given status code is 409 Conflict.
    static boolean
    contentTooLarge(int statusCode)
    Check if the given status code is 413 Content Too Large.
    static boolean
    created(int statusCode)
    Check if the given status code is 201 Created.
    static boolean
    expectationFailed(int statusCode)
    Check if the given status code is 417 Expectation Failed.
    static boolean
    forbidden(int statusCode)
    Check if the given status code is 403 Forbidden.
    static boolean
    found(int statusCode)
    Check if the given status code is 302 Found.
    static boolean
    gatewayTimeout(int statusCode)
    Check if the given status code is 504 Gateway Timeout.
    static boolean
    gone(int statusCode)
    Check if the given status code is 410 Gone.
    static boolean
    httpVersionNotSupported(int statusCode)
    Check if the given status code is 505 HTTP Version Not Supported.
    static boolean
    iAmATeapot(int statusCode)
    Check if the given status code is 418 I'm a teapot.
    static boolean
    informational(int statusCode)
    Check if the given status code is in the informational family (1xx codes).
    static boolean
    internalServerError(int statusCode)
    Check if the given status code is 500 Internal Server Error.
    static boolean
    lengthRequired(int statusCode)
    Check if the given status code is 411 Length Required.
    static boolean
    methodNotAllowed(int statusCode)
    Check if the given status code is 405 Method Not Allowed.
    static boolean
    movedPermanently(int statusCode)
    Check if the given status code is 301 Moved Permanently.
    static boolean
    Check if the given status code is 511 Network Authentication Required.
    static boolean
    noContent(int statusCode)
    Check if the given status code is 204 No Content.
    static boolean
    notAcceptable(int statusCode)
    Check if the given status code is 406 Not Acceptable.
    static boolean
    notFound(int statusCode)
    Check if the given status code is 404 Not Found.
    static boolean
    notImplemented(int statusCode)
    Check if the given status code is 501 Not Implemented.
    static boolean
    notModified(int statusCode)
    Check if the given status code is 304 Not Modified.
    static boolean
    notSuccessful(int statusCode)
    Check if the given status code is not in the successful family (2xx codes).
    static boolean
    ok(int statusCode)
    Check if the given status code is 200 OK.
    static boolean
    otherFamily(int statusCode)
    Check if the given status code is not in a known family.
    static boolean
    partialContent(int statusCode)
    Check if the given status code is 206 Partial Content.
    static boolean
    paymentRequired(int statusCode)
    Check if the given status code is 402 Payment Required.
    static boolean
    permanentRedirect(int statusCode)
    Check if the given status code is 308 Permanent Redirect.
    static boolean
    preconditionFailed(int statusCode)
    Check if the given status code is 412 Precondition Failed.
    static boolean
    preconditionRequired(int statusCode)
    Check if the given status code is 428 Precondition Required.
    static boolean
    Check if the given status code is 407 Proxy Authentication Required.
    static boolean
    rangeNotSatisfiable(int statusCode)
    Check if the given status code is 416 Range Not Satisfiable.
    static String
    reasonPhraseOf(int statusCode)
    Get the human-readable (though not necessarily understandable) "reason phrase" for the given status code.
    static boolean
    redirection(int statusCode)
    Check if the given status code is in the redirection family (3xx codes).
    static boolean
    Check if the given status code is 431 Request Header Fields Too Large.
    static boolean
    requestTimeout(int statusCode)
    Check if the given status code is 408 Request Timeout.
    static boolean
    resetContent(int statusCode)
    Check if the given status code is 205 Reset Content.
    static boolean
    seeOther(int statusCode)
    Check if the given status code is 303 See Other.
    static boolean
    serverError(int statusCode)
    Check if the given status code is in the server error family (5xx codes).
    static boolean
    serviceUnavailable(int statusCode)
    Check if the given status code is 503 Service Unavailable.
    static boolean
    successful(int statusCode)
    Check if the given status code is in the successful family (2xx codes).
    static boolean
    temporaryRedirect(int statusCode)
    Check if the given status code is 307 Temporary Redirect.
    static boolean
    tooManyRequests(int statusCode)
    Check if the given status code is 429 Too Many Requests.
    static boolean
    unauthorized(int statusCode)
    Check if the given status code is 401 Unauthorized.
    static boolean
    unprocessableContent(int statusCode)
    Check if the given status code is 422 Unprocessable Content.
    static boolean
    unsupportedMediaType(int statusCode)
    Check if the given status code is 415 Unsupported Media Type.
    static boolean
    upgradeRequired(int statusCode)
    Check if the given status code is 426 Upgrade Required.
    static boolean
    uriTooLong(int statusCode)
    Check if the given status code is 414 URI Too Long.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • informational

      public static boolean informational(int statusCode)
      Check if the given status code is in the informational family (1xx codes).
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 100-199, otherwise false
    • successful

      public static boolean successful(int statusCode)
      Check if the given status code is in the successful family (2xx codes).
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 200-299, otherwise false
    • notSuccessful

      public static boolean notSuccessful(int statusCode)
      Check if the given status code is not in the successful family (2xx codes).
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is outside the range 200-299, otherwise false
    • redirection

      public static boolean redirection(int statusCode)
      Check if the given status code is in the redirection family (3xx codes).
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 300-399, otherwise false
    • clientError

      public static boolean clientError(int statusCode)
      Check if the given status code is in the client error family (4xx codes).
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 400-499, otherwise false
    • serverError

      public static boolean serverError(int statusCode)
      Check if the given status code is in the server error family (5xx codes).
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 500-599, otherwise false
    • otherFamily

      public static boolean otherFamily(int statusCode)
      Check if the given status code is not in a known family.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is outside the range 100-599, otherwise false
    • ok

      public static boolean ok(int statusCode)
      Check if the given status code is 200 OK.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 200, otherwise false
    • created

      public static boolean created(int statusCode)
      Check if the given status code is 201 Created.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 201, otherwise false
    • accepted

      public static boolean accepted(int statusCode)
      Check if the given status code is 202 Accepted.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 202, otherwise false
    • noContent

      public static boolean noContent(int statusCode)
      Check if the given status code is 204 No Content.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 204, otherwise false
    • resetContent

      public static boolean resetContent(int statusCode)
      Check if the given status code is 205 Reset Content.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 205, otherwise false
    • partialContent

      public static boolean partialContent(int statusCode)
      Check if the given status code is 206 Partial Content.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 206, otherwise false
    • movedPermanently

      public static boolean movedPermanently(int statusCode)
      Check if the given status code is 301 Moved Permanently.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 301, otherwise false
    • found

      public static boolean found(int statusCode)
      Check if the given status code is 302 Found.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 302, otherwise false
    • seeOther

      public static boolean seeOther(int statusCode)
      Check if the given status code is 303 See Other.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 303, otherwise false
    • notModified

      public static boolean notModified(int statusCode)
      Check if the given status code is 304 Not Modified.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 304, otherwise false
    • temporaryRedirect

      public static boolean temporaryRedirect(int statusCode)
      Check if the given status code is 307 Temporary Redirect.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 307, otherwise false
    • permanentRedirect

      public static boolean permanentRedirect(int statusCode)
      Check if the given status code is 308 Permanent Redirect.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 308, otherwise false
    • badRequest

      public static boolean badRequest(int statusCode)
      Check if the given status code is 400 Bad Request.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 400, otherwise false
    • unauthorized

      public static boolean unauthorized(int statusCode)
      Check if the given status code is 401 Unauthorized.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 401, otherwise false
    • paymentRequired

      public static boolean paymentRequired(int statusCode)
      Check if the given status code is 402 Payment Required.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 402, otherwise false
    • forbidden

      public static boolean forbidden(int statusCode)
      Check if the given status code is 403 Forbidden.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 403, otherwise false
    • notFound

      public static boolean notFound(int statusCode)
      Check if the given status code is 404 Not Found.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 404, otherwise false
    • methodNotAllowed

      public static boolean methodNotAllowed(int statusCode)
      Check if the given status code is 405 Method Not Allowed.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 405, otherwise false
    • notAcceptable

      public static boolean notAcceptable(int statusCode)
      Check if the given status code is 406 Not Acceptable.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 406, otherwise false
    • proxyAuthenticationRequired

      public static boolean proxyAuthenticationRequired(int statusCode)
      Check if the given status code is 407 Proxy Authentication Required.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 407, otherwise false
    • requestTimeout

      public static boolean requestTimeout(int statusCode)
      Check if the given status code is 408 Request Timeout.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 408, otherwise false
    • conflict

      public static boolean conflict(int statusCode)
      Check if the given status code is 409 Conflict.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 409, otherwise false
    • gone

      public static boolean gone(int statusCode)
      Check if the given status code is 410 Gone.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 410, otherwise false
    • lengthRequired

      public static boolean lengthRequired(int statusCode)
      Check if the given status code is 411 Length Required.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 411, otherwise false
    • preconditionFailed

      public static boolean preconditionFailed(int statusCode)
      Check if the given status code is 412 Precondition Failed.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 412, otherwise false
    • contentTooLarge

      public static boolean contentTooLarge(int statusCode)
      Check if the given status code is 413 Content Too Large.

      According to the Mozilla documentation, this used to be known as Payload Too Large, and that terminology is still apparently widely used.

      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 413, otherwise false
    • uriTooLong

      public static boolean uriTooLong(int statusCode)
      Check if the given status code is 414 URI Too Long.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 414, otherwise false
    • unsupportedMediaType

      public static boolean unsupportedMediaType(int statusCode)
      Check if the given status code is 415 Unsupported Media Type.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 415, otherwise false
    • rangeNotSatisfiable

      public static boolean rangeNotSatisfiable(int statusCode)
      Check if the given status code is 416 Range Not Satisfiable.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 416, otherwise false
    • expectationFailed

      public static boolean expectationFailed(int statusCode)
      Check if the given status code is 417 Expectation Failed.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 417, otherwise false
    • iAmATeapot

      public static boolean iAmATeapot(int statusCode)
      Check if the given status code is 418 I'm a teapot.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 418, otherwise false
    • unprocessableContent

      public static boolean unprocessableContent(int statusCode)
      Check if the given status code is 422 Unprocessable Content.

      This is technically a WebDAV code, but is used by many web frameworks to indicate an input validation failure.

      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 422, otherwise false
    • upgradeRequired

      public static boolean upgradeRequired(int statusCode)
      Check if the given status code is 426 Upgrade Required.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 426, otherwise false
    • preconditionRequired

      public static boolean preconditionRequired(int statusCode)
      Check if the given status code is 428 Precondition Required.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 428, otherwise false
    • tooManyRequests

      public static boolean tooManyRequests(int statusCode)
      Check if the given status code is 429 Too Many Requests.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 429, otherwise false
    • requestHeaderFieldsTooLarge

      public static boolean requestHeaderFieldsTooLarge(int statusCode)
      Check if the given status code is 431 Request Header Fields Too Large.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 431, otherwise false
    • internalServerError

      public static boolean internalServerError(int statusCode)
      Check if the given status code is 500 Internal Server Error.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 500, otherwise false
    • notImplemented

      public static boolean notImplemented(int statusCode)
      Check if the given status code is 501 Not Implemented.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 501, otherwise false
    • badGateway

      public static boolean badGateway(int statusCode)
      Check if the given status code is 502 Bad Gateway.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 502, otherwise false
    • serviceUnavailable

      public static boolean serviceUnavailable(int statusCode)
      Check if the given status code is 503 Service Unavailable.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 503, otherwise false
    • gatewayTimeout

      public static boolean gatewayTimeout(int statusCode)
      Check if the given status code is 504 Gateway Timeout.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 504, otherwise false
    • httpVersionNotSupported

      public static boolean httpVersionNotSupported(int statusCode)
      Check if the given status code is 505 HTTP Version Not Supported.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 505, otherwise false
    • networkAuthenticationRequired

      public static boolean networkAuthenticationRequired(int statusCode)
      Check if the given status code is 511 Network Authentication Required.
      Parameters:
      statusCode - the status code to check
      Returns:
      true if the status code is 511, otherwise false
    • reasonPhraseOf

      public static String reasonPhraseOf(int statusCode)
      Get the human-readable (though not necessarily understandable) "reason phrase" for the given status code.
      Parameters:
      statusCode - the status code
      Returns:
      the reason phrase of the status code, or "Unknown" if the code is not known (it may or may not be a valid HTTP status code, or could be a custom code)