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)
fromStatusCode(Integer) and fromRedirect(RedirectType, String).
For performance, header collections are shallow-copied and not defensively deep-copied. Treat returned collections as immutable.
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.booleanfromRedirect(@NonNull RedirectType redirectType, @NonNull String location) Creates a redirectResponsewith no additional customization.fromStatusCode(@NonNull Integer statusCode) Creates aResponsewith the given status code and no additional customization.getBody()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 @NonNull Response.BuilderwithRedirect(@NonNull RedirectType redirectType, @NonNull String location) Acquires a builder forResponseinstances that are intended to redirect the client.static @NonNull Response.BuilderwithStatusCode(@NonNull 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
-
fromStatusCode
-
withRedirect
public static @NonNull 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
-
fromRedirect
public static @NonNull Response fromRedirect(@NonNull RedirectType redirectType, @NonNull String location) Creates a redirectResponsewith no additional customization.- Parameters:
redirectType- the kind of redirect to perform, for exampleRedirectType.HTTP_307_TEMPORARY_REDIRECTlocation- the URL to redirect to- Returns:
- a
Responseinstance
-
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. Soklet writes one header line per value. If order matters, provide either a
SortedSetorLinkedHashSetto preserve the desired ordering; otherwise values are naturally sorted for consistency.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
-