java.lang.Object
com.jpro.webapi.server.Response
Represents a server response.
If no mime type is set, then a default mimetype based on the file extension will be used.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Response
empty()
Creates an empty response.byte[]
getBody()
Gets the body of the response.Gets the MIME type of the response.int
Gets the HTTP status code of the response.boolean
isEmpty()
Checks if the response is empty.static Response
of
(byte[] body) Creates a response with the given body.static Response
Creates a response with the given body and MIME type.static Response
Creates a response with the given body, MIME type, and status code.
-
Constructor Details
-
Response
public Response(byte[] body) Creates a response with the given body. This constructor sets the response as non-empty.- Parameters:
body
- the response body
-
Response
public Response(byte[] body, int statusCode) Creates a response with the given body and status code. This constructor sets the response as non-empty.- Parameters:
body
- the response bodystatusCode
- the HTTP status code
-
-
Method Details
-
isEmpty
public boolean isEmpty()Checks if the response is empty.- Returns:
true
if the response is empty,false
otherwise
-
getBody
public byte[] getBody()Gets the body of the response.- Returns:
- the response body, or
null
if the response is empty
-
getMimeType
Gets the MIME type of the response.- Returns:
- the MIME type, or
null
if not specified
-
getStatusCode
public int getStatusCode()Gets the HTTP status code of the response.- Returns:
- the HTTP status code
-
empty
Creates an empty response.- Returns:
- an empty response
-
of
Creates a response with the given body.- Parameters:
body
- the response body- Returns:
- a response containing the specified body
-
of
Creates a response with the given body and MIME type.- Parameters:
body
- the response bodymimeType
- the MIME type of the response- Returns:
- a response containing the specified body and MIME type
-
of
Creates a response with the given body, MIME type, and status code.- Parameters:
body
- the response bodymimeType
- the MIME type of the responsestatusCode
- the HTTP status code- Returns:
- a response containing the specified body, MIME type, and status code
-