Class Response
Your application's ResponseMarshaler is responsible for taking the Response returned by a Resource Method as input
and creating a finalized binary representation (MarshaledResponse), suitable for sending to clients over the wire.
Instances can be acquired via these builder factory methods:
withStatusCode(Integer)(builder primed with status code)withRedirect(RedirectType, String)(builder primed with redirect info)
Full documentation is available at https://www.soklet.com/docs/response-writing.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder used to construct instances ofResponseviawithStatusCode(Integer)orwithRedirect(RedirectType, String).static final class -
Method Summary
Modifier and TypeMethodDescriptioncopy()Vends a mutable copier seeded with this instance's data, suitable for building new instances.booleangetBody()The "logical" body content to be written to the response, if present.The cookies to be written to the client for this response.The headers to be written to the client for this response.The HTTP status code to be written to the client for this response.inthashCode()toString()static Response.BuilderwithRedirect(RedirectType redirectType, String location) Acquires a builder forResponseinstances that are intended to redirect the client.static Response.BuilderwithStatusCode(Integer statusCode) Acquires a builder forResponseinstances.
-
Method Details
-
withStatusCode
Acquires a builder forResponseinstances.- Parameters:
statusCode- the HTTP status code for this request (200, 201, etc.)- Returns:
- the builder
-
withRedirect
@Nonnull public static Response.Builder withRedirect(@Nonnull RedirectType redirectType, @Nonnull String location) Acquires a builder forResponseinstances that are intended to redirect the client.- Parameters:
redirectType- the kind of redirect to perform, for exampleRedirectType.HTTP_307_TEMPORARY_REDIRECTlocation- the URL to redirect to- Returns:
- the builder
-
toString
-
equals
-
hashCode
-
copy
Vends a mutable copier seeded with this instance's data, suitable for building new instances.- Returns:
- a copier for this instance
-
getStatusCode
The HTTP status code to be written to the client for this response.See
StatusCodefor an enumeration of all HTTP status codes.- Returns:
- the HTTP status code to write to the response
-
getCookies
The cookies to be written to the client for this response.It is possible to send multiple
ResponseCookievalues with the same name to the client.Note that
ResponseCookievalues, like all response headers, have case-insensitive names per the HTTP spec.- Returns:
- the cookies to write to the response
-
getHeaders
The headers to be written to the client for this response.The keys are the header names and the values are header values (it is possible to send the client multiple headers with the same name).
Note that response headers have case-insensitive names per the HTTP spec.
- Returns:
- the headers to write to the response
-
getBody
The "logical" body content to be written to the response, if present.It is the responsibility of the
ResponseMarshalerto take this object and convert it into bytes to send over the wire.- Returns:
- the object representing the response body, or
Optional.empty()if no response body should be written
-