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 Responseempty()Creates an empty response.byte[]getBody()Gets the body of the response.Gets the MIME type of the response.intGets the HTTP status code of the response.booleanisEmpty()Checks if the response is empty.static Responseof(byte[] body) Creates a response with the given body.static ResponseCreates a response with the given body and MIME type.static ResponseCreates 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:
trueif the response is empty,falseotherwise
-
getBody
public byte[] getBody()Gets the body of the response.- Returns:
- the response body, or
nullif the response is empty
-
getMimeType
Gets the MIME type of the response.- Returns:
- the MIME type, or
nullif 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
-