Enum Class HttpStatusFamily

java.lang.Object
java.lang.Enum<HttpStatusFamily>
de.cuioss.http.client.handler.HttpStatusFamily
All Implemented Interfaces:
Serializable, Comparable<HttpStatusFamily>, Constable

HTTP status code classification enum based on RFC 7231 status code families.

This enum provides a type-safe way to classify HTTP status codes into their standard families as defined by RFC 7231. It includes utility methods for checking status code categories and determining appropriate response handling strategies.

Design Principles

  • RFC Compliance - Follows RFC 7231 HTTP status code definitions
  • Type Safety - Enum-based classification prevents invalid categories
  • Utility Methods - Convenient static methods for common checks
  • Range Validation - Validates status codes against standard ranges

Status Code Families

  • 1xx Informational - Request received, continuing process (100-199)
  • 2xx Success - Action successfully received, understood, and accepted (200-299)
  • 3xx Redirection - Further action must be taken to complete request (300-399)
  • 4xx Client Error - Request contains bad syntax or cannot be fulfilled (400-499)
  • 5xx Server Error - Server failed to fulfill apparently valid request (500-599)
  • Unknown - Status codes outside standard ranges or error conditions

Usage Examples

 // Classify status codes
 HttpStatusFamily family = HttpStatusFamily.fromStatusCode(200);
 assert family == HttpStatusFamily.SUCCESS;

 // Check for success
 if (HttpStatusFamily.isSuccess(response.statusCode())) {
     // Handle successful response
 }

 // Check for errors
 if (HttpStatusFamily.isClientError(response.statusCode())) {
     // Handle client error (4xx)
 } else if (HttpStatusFamily.isServerError(response.statusCode())) {
     // Handle server error (5xx)
 }

 // Validate status code range
 if (HttpStatusFamily.isValid(statusCode)) {
     // Process valid HTTP status code
 }

 // Family-specific checks
 HttpStatusFamily family = HttpStatusFamily.REDIRECTION;
 if (family.contains(302)) {
     // Handle redirection logic
 }
 

Common Status Codes by Family

  • 2xx Success: 200 OK, 201 Created, 204 No Content
  • 3xx Redirection: 301 Moved Permanently, 302 Found, 304 Not Modified
  • 4xx Client Error: 400 Bad Request, 401 Unauthorized, 404 Not Found
  • 5xx Server Error: 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable
Since:
1.0
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    4xx: Client Error - The request contains bad syntax or cannot be fulfilled.
    1xx: Informational - Request received, a continuing process.
    3xx: Redirection - Further action needs to be taken to complete the request.
    5xx: Server Error - The server failed to fulfill an apparently valid request.
    2xx: Success - The action was successfully received, understood, and accepted.
    Unknown - Used for status codes outside the standard ranges or for error conditions.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(int statusCode)
    Checks if the given status code belongs to this family.
    fromStatusCode(int statusCode)
    Gets the HTTP status code family for the given status code.
    static boolean
    isClientError(int statusCode)
    Checks if the given status code indicates a client error (4xx).
    static boolean
    isInformational(int statusCode)
    Checks if the given status code indicates an informational response (1xx).
    static boolean
    isRedirection(int statusCode)
    Checks if the given status code indicates a redirection (3xx).
    static boolean
    isServerError(int statusCode)
    Checks if the given status code indicates a server error (5xx).
    static boolean
    isSuccess(int statusCode)
    Checks if the given status code indicates a successful response (2xx).
    static boolean
    isValid(int statusCode)
    Checks if the given status code is a valid HTTP status code (100-599).
     
    Returns the enum constant of this class with the specified name.
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • INFORMATIONAL

      public static final HttpStatusFamily INFORMATIONAL
      1xx: Informational - Request received, a continuing process.
    • SUCCESS

      public static final HttpStatusFamily SUCCESS
      2xx: Success - The action was successfully received, understood, and accepted.
    • REDIRECTION

      public static final HttpStatusFamily REDIRECTION
      3xx: Redirection - Further action needs to be taken to complete the request.
    • CLIENT_ERROR

      public static final HttpStatusFamily CLIENT_ERROR
      4xx: Client Error - The request contains bad syntax or cannot be fulfilled.
    • SERVER_ERROR

      public static final HttpStatusFamily SERVER_ERROR
      5xx: Server Error - The server failed to fulfill an apparently valid request.
    • UNKNOWN

      public static final HttpStatusFamily UNKNOWN
      Unknown - Used for status codes outside the standard ranges or for error conditions.
  • Method Details

    • values

      public static HttpStatusFamily[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static HttpStatusFamily valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • contains

      public boolean contains(int statusCode)
      Checks if the given status code belongs to this family.
      Parameters:
      statusCode - the HTTP status code to check
      Returns:
      true if the status code belongs to this family, false otherwise
    • fromStatusCode

      public static HttpStatusFamily fromStatusCode(int statusCode)
      Gets the HTTP status code family for the given status code.
      Parameters:
      statusCode - the HTTP status code
      Returns:
      the corresponding HttpStatusFamily family
    • isSuccess

      public static boolean isSuccess(int statusCode)
      Checks if the given status code indicates a successful response (2xx).
      Parameters:
      statusCode - the HTTP status code to check
      Returns:
      true if the status code indicates success, false otherwise
    • isClientError

      public static boolean isClientError(int statusCode)
      Checks if the given status code indicates a client error (4xx).
      Parameters:
      statusCode - the HTTP status code to check
      Returns:
      true if the status code indicates a client error, false otherwise
    • isServerError

      public static boolean isServerError(int statusCode)
      Checks if the given status code indicates a server error (5xx).
      Parameters:
      statusCode - the HTTP status code to check
      Returns:
      true if the status code indicates a server error, false otherwise
    • isRedirection

      public static boolean isRedirection(int statusCode)
      Checks if the given status code indicates a redirection (3xx).
      Parameters:
      statusCode - the HTTP status code to check
      Returns:
      true if the status code indicates a redirection, false otherwise
    • isInformational

      public static boolean isInformational(int statusCode)
      Checks if the given status code indicates an informational response (1xx).
      Parameters:
      statusCode - the HTTP status code to check
      Returns:
      true if the status code indicates an informational response, false otherwise
    • isValid

      public static boolean isValid(int statusCode)
      Checks if the given status code is a valid HTTP status code (100-599).
      Parameters:
      statusCode - the HTTP status code to check
      Returns:
      true if the status code is valid, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Enum<HttpStatusFamily>