Package org.kiwiproject.net
Class KiwiHttpResponses
java.lang.Object
org.kiwiproject.net.KiwiHttpResponses
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 TypeMethodDescriptionstatic booleanaccepted(int statusCode) Check if the given status code is 202 Accepted.static booleanbadGateway(int statusCode) Check if the given status code is 502 Bad Gateway.static booleanbadRequest(int statusCode) Check if the given status code is 400 Bad Request.static booleanclientError(int statusCode) Check if the given status code is in the client error family (4xx codes).static booleanconflict(int statusCode) Check if the given status code is 409 Conflict.static booleancontentTooLarge(int statusCode) Check if the given status code is 413 Content Too Large.static booleancreated(int statusCode) Check if the given status code is 201 Created.static booleanexpectationFailed(int statusCode) Check if the given status code is 417 Expectation Failed.static booleanforbidden(int statusCode) Check if the given status code is 403 Forbidden.static booleanfound(int statusCode) Check if the given status code is 302 Found.static booleangatewayTimeout(int statusCode) Check if the given status code is 504 Gateway Timeout.static booleangone(int statusCode) Check if the given status code is 410 Gone.static booleanhttpVersionNotSupported(int statusCode) Check if the given status code is 505 HTTP Version Not Supported.static booleaniAmATeapot(int statusCode) Check if the given status code is 418 I'm a teapot.static booleaninformational(int statusCode) Check if the given status code is in the informational family (1xx codes).static booleaninternalServerError(int statusCode) Check if the given status code is 500 Internal Server Error.static booleanlengthRequired(int statusCode) Check if the given status code is 411 Length Required.static booleanmethodNotAllowed(int statusCode) Check if the given status code is 405 Method Not Allowed.static booleanmovedPermanently(int statusCode) Check if the given status code is 301 Moved Permanently.static booleannetworkAuthenticationRequired(int statusCode) Check if the given status code is 511 Network Authentication Required.static booleannoContent(int statusCode) Check if the given status code is 204 No Content.static booleannotAcceptable(int statusCode) Check if the given status code is 406 Not Acceptable.static booleannotFound(int statusCode) Check if the given status code is 404 Not Found.static booleannotImplemented(int statusCode) Check if the given status code is 501 Not Implemented.static booleannotModified(int statusCode) Check if the given status code is 304 Not Modified.static booleannotSuccessful(int statusCode) Check if the given status code is not in the successful family (2xx codes).static booleanok(int statusCode) Check if the given status code is 200 OK.static booleanotherFamily(int statusCode) Check if the given status code is not in a known family.static booleanpartialContent(int statusCode) Check if the given status code is 206 Partial Content.static booleanpaymentRequired(int statusCode) Check if the given status code is 402 Payment Required.static booleanpermanentRedirect(int statusCode) Check if the given status code is 308 Permanent Redirect.static booleanpreconditionFailed(int statusCode) Check if the given status code is 412 Precondition Failed.static booleanpreconditionRequired(int statusCode) Check if the given status code is 428 Precondition Required.static booleanproxyAuthenticationRequired(int statusCode) Check if the given status code is 407 Proxy Authentication Required.static booleanrangeNotSatisfiable(int statusCode) Check if the given status code is 416 Range Not Satisfiable.static StringreasonPhraseOf(int statusCode) Get the human-readable (though not necessarily understandable) "reason phrase" for the given status code.static booleanredirection(int statusCode) Check if the given status code is in the redirection family (3xx codes).static booleanrequestHeaderFieldsTooLarge(int statusCode) Check if the given status code is 431 Request Header Fields Too Large.static booleanrequestTimeout(int statusCode) Check if the given status code is 408 Request Timeout.static booleanresetContent(int statusCode) Check if the given status code is 205 Reset Content.static booleanseeOther(int statusCode) Check if the given status code is 303 See Other.static booleanserverError(int statusCode) Check if the given status code is in the server error family (5xx codes).static booleanserviceUnavailable(int statusCode) Check if the given status code is 503 Service Unavailable.static booleansuccessful(int statusCode) Check if the given status code is in the successful family (2xx codes).static booleantemporaryRedirect(int statusCode) Check if the given status code is 307 Temporary Redirect.static booleantooManyRequests(int statusCode) Check if the given status code is 429 Too Many Requests.static booleanunauthorized(int statusCode) Check if the given status code is 401 Unauthorized.static booleanunprocessableContent(int statusCode) Check if the given status code is 422 Unprocessable Content.static booleanunsupportedMediaType(int statusCode) Check if the given status code is 415 Unsupported Media Type.static booleanupgradeRequired(int statusCode) Check if the given status code is 426 Upgrade Required.static booleanuriTooLong(int statusCode) Check if the given status code is 414 URI Too Long.
-
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
-
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
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)
-