java.lang.Object
org.cybergarage.http.HTTPStatus
Represents an HTTP status line with version, status code, and reason phrase. This class provides methods to parse and manipulate HTTP status responses, including common status code constants and utility methods.
Field Summary
Modifier and TypeFieldDescriptionstatic final intHTTP 400 Bad Requeststatic final intHTTP 100 Continuestatic final intHTTP 500 Internal Server Errorstatic final intHTTP 416 Invalid Rangestatic final intHTTP 404 Not Foundstatic final intHTTP 200 OKstatic final intHTTP 206 Partial Contentstatic final intHTTP 412 Precondition Failedprivate StringText reason for the status code.private intNumeric status of the response.private String/////////////////////////////////////////////Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty HTTPStatus with default values.HTTPStatus(String lineStr) Creates a new HTTPStatus by parsing a status line string.HTTPStatus(String ver, int code, String reason) Creates a new HTTPStatus with the specified version, code, and reason.Method Summary
Modifier and TypeMethodDescriptionstatic final Stringcode2String(int code) Converts an HTTP status code to its corresponding reason phrase string.Gets the reason phrase.intGets the status code.Gets the HTTP version.booleanChecks if this status represents a successful response (2xx range).static final booleanisSuccessful(int statCode) Checks if the given status code represents a successful response (2xx range).voidParses a status line string and sets the version, code, and reason phrase.voidsetReasonPhrase(String value) Sets the reason phrase.voidsetStatusCode(int value) Sets the status code.voidsetVersion(String value) Sets the HTTP version.
Field Details
CONTINUE
OK
PARTIAL_CONTENT
BAD_REQUEST
NOT_FOUND
PRECONDITION_FAILED
public static final int PRECONDITION_FAILEDHTTP 412 Precondition Failed- See Also:
INVALID_RANGE
INTERNAL_SERVER_ERROR
public static final int INTERNAL_SERVER_ERRORHTTP 500 Internal Server Error- See Also:
version
/////////////////////////////////////////////statusCode
private int statusCodeNumeric status of the response.reasonPhrase
Text reason for the status code.
Constructor Details
HTTPStatus
public HTTPStatus()Creates a new empty HTTPStatus with default values.HTTPStatus
HTTPStatus
Creates a new HTTPStatus by parsing a status line string. The line should be in the format "HTTP/1.1 200 OK".- Parameters:
lineStr- the status line to parse
Method Details
code2String
Converts an HTTP status code to its corresponding reason phrase string.This method provides the standard HTTP reason phrases for common status codes. If the status code is not recognized, an empty string is returned.
- Parameters:
code- the HTTP status code to convert- Returns:
- the corresponding reason phrase, or empty string if code is not recognized
setVersion
Sets the HTTP version.- Parameters:
value- the HTTP version (e.g., "HTTP/1.1")
setStatusCode
public void setStatusCode(int value) Sets the status code.- Parameters:
value- the status code
setReasonPhrase
Sets the reason phrase.- Parameters:
value- the reason phrase
getVersion
getStatusCode
public int getStatusCode()Gets the status code.- Returns:
- the status code
getReasonPhrase
isSuccessful
public static final boolean isSuccessful(int statCode) Checks if the given status code represents a successful response (2xx range).- Parameters:
statCode- the status code to check- Returns:
- true if the status code is in the 200-299 range
isSuccessful
public boolean isSuccessful()Checks if this status represents a successful response (2xx range).- Returns:
- true if the status code is in the 200-299 range
set
Parses a status line string and sets the version, code, and reason phrase. The line should be in the format "HTTP/1.1 200 OK".- Parameters:
lineStr- the status line to parse