Class DefaultResponseMarshaler
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionforContentTooLarge
(Request request, ResourceMethod resourceMethod) Prepares a response for a request that triggers an HTTP 413 Content Too Large.forCorsAllowed
(Request request, Cors cors, CorsResponse corsResponse, MarshaledResponse marshaledResponse) Applies "CORS is permitted for this request" data to a response.forCorsPreflightAllowed
(Request request, CorsPreflight corsPreflight, CorsPreflightResponse corsPreflightResponse) Prepares a response for "CORS preflight allowed" scenario when yourCorsAuthorizer
approves a preflight request.forCorsPreflightRejected
(Request request, CorsPreflight corsPreflight) Prepares a response for "CORS preflight rejected" scenario when yourCorsAuthorizer
denies a preflight request.forHappyPath
(Request request, Response response, ResourceMethod resourceMethod) Prepares a "happy path" response - the request was matched to a Resource Method and executed non-exceptionally.forHead
(Request request, MarshaledResponse getMethodMarshaledResponse) Prepares a response for an HTTPHEAD
request.forMethodNotAllowed
(Request request, Set<HttpMethod> allowedHttpMethods) Prepares a response for a request that triggers an HTTP 405 Method Not Allowed.forNotFound
(Request request) Prepares a response for a request that triggers an HTTP 404 Not Found.forOptions
(Request request, Set<HttpMethod> allowedHttpMethods) Prepares a response for an HTTPOPTIONS
request.forThrowable
(Request request, Throwable throwable, ResourceMethod resourceMethod) Prepares a response for scenarios in which an uncaught exception is encountered.static DefaultResponseMarshaler
-
Constructor Details
-
DefaultResponseMarshaler
public DefaultResponseMarshaler() -
DefaultResponseMarshaler
-
-
Method Details
-
forHappyPath
@Nonnull public MarshaledResponse forHappyPath(@Nonnull Request request, @Nonnull Response response, @Nonnull ResourceMethod resourceMethod) Description copied from interface:ResponseMarshaler
Prepares a "happy path" response - the request was matched to a Resource Method and executed non-exceptionally.Detailed documentation is available at https://www.soklet.com/docs/response-writing#happy-path.
- Specified by:
forHappyPath
in interfaceResponseMarshaler
- Parameters:
request
- the HTTP requestresponse
- the response provided by the Resource Method that handled the requestresourceMethod
- the Resource Method that handled the request- Returns:
- the response to be sent over the wire
-
forNotFound
Description copied from interface:ResponseMarshaler
Prepares a response for a request that triggers an HTTP 404 Not Found.Detailed documentation is available at https://www.soklet.com/docs/response-writing#404-not-found.
- Specified by:
forNotFound
in interfaceResponseMarshaler
- Parameters:
request
- the HTTP request- Returns:
- the response to be sent over the wire
-
forMethodNotAllowed
@Nonnull public MarshaledResponse forMethodNotAllowed(@Nonnull Request request, @Nonnull Set<HttpMethod> allowedHttpMethods) Description copied from interface:ResponseMarshaler
Prepares a response for a request that triggers an HTTP 405 Method Not Allowed.Detailed documentation is available at https://www.soklet.com/docs/response-writing#405-method-not-allowed.
- Specified by:
forMethodNotAllowed
in interfaceResponseMarshaler
- Parameters:
request
- the HTTP requestallowedHttpMethods
- appropriate HTTP methods to write to theAllow
response header- Returns:
- the response to be sent over the wire
-
forContentTooLarge
@Nonnull public MarshaledResponse forContentTooLarge(@Nonnull Request request, @Nullable ResourceMethod resourceMethod) Description copied from interface:ResponseMarshaler
Prepares a response for a request that triggers an HTTP 413 Content Too Large.Detailed documentation is available at https://www.soklet.com/docs/response-writing#413-content-too-large.
- Specified by:
forContentTooLarge
in interfaceResponseMarshaler
- Parameters:
request
- the HTTP requestresourceMethod
- the Resource Method that would have handled the request, if available- Returns:
- the response to be sent over the wire
-
forOptions
@Nonnull public MarshaledResponse forOptions(@Nonnull Request request, @Nonnull Set<HttpMethod> allowedHttpMethods) Description copied from interface:ResponseMarshaler
Prepares a response for an HTTPOPTIONS
request.Note that CORS preflight responses are handled specially by
ResponseMarshaler.forCorsPreflightAllowed(Request, CorsPreflight, CorsPreflightResponse)
andResponseMarshaler.forCorsPreflightRejected(Request, CorsPreflight)
- not this method.Detailed documentation is available at https://www.soklet.com/docs/response-writing#http-options.
- Specified by:
forOptions
in interfaceResponseMarshaler
- Parameters:
request
- the HTTP requestallowedHttpMethods
- appropriate HTTP methods to write to theAllow
response header- Returns:
- the response to be sent over the wire
-
forHead
@Nonnull public MarshaledResponse forHead(@Nonnull Request request, @Nonnull MarshaledResponse getMethodMarshaledResponse) Description copied from interface:ResponseMarshaler
Prepares a response for an HTTPHEAD
request.Detailed documentation is available at https://www.soklet.com/docs/response-writing#http-head.
- Specified by:
forHead
in interfaceResponseMarshaler
- Parameters:
request
- the HTTP requestgetMethodMarshaledResponse
- the binary data that would have been sent over the wire for an equivalentGET
request (necessary in order to write theContent-Length
header for aHEAD
response)- Returns:
- the response to be sent over the wire
-
forThrowable
@Nonnull public MarshaledResponse forThrowable(@Nonnull Request request, @Nonnull Throwable throwable, @Nullable ResourceMethod resourceMethod) Description copied from interface:ResponseMarshaler
Prepares a response for scenarios in which an uncaught exception is encountered.Detailed documentation is available at https://www.soklet.com/docs/response-writing#uncaught-exceptions.
- Specified by:
forThrowable
in interfaceResponseMarshaler
- Parameters:
request
- the HTTP requestthrowable
- the exception that was thrownresourceMethod
- the Resource Method that would have handled the request, if available- Returns:
- the response to be sent over the wire
-
forCorsPreflightAllowed
@Nonnull public MarshaledResponse forCorsPreflightAllowed(@Nonnull Request request, @Nonnull CorsPreflight corsPreflight, @Nonnull CorsPreflightResponse corsPreflightResponse) Description copied from interface:ResponseMarshaler
Prepares a response for "CORS preflight allowed" scenario when yourCorsAuthorizer
approves a preflight request.Detailed documentation is available at https://www.soklet.com/docs/cors#writing-cors-responses.
- Specified by:
forCorsPreflightAllowed
in interfaceResponseMarshaler
- Parameters:
request
- the HTTP requestcorsPreflight
- the CORS preflight request datacorsPreflightResponse
- the data that should be included in this CORS preflight response- Returns:
- the response to be sent over the wire
-
forCorsPreflightRejected
@Nonnull public MarshaledResponse forCorsPreflightRejected(@Nonnull Request request, @Nonnull CorsPreflight corsPreflight) Description copied from interface:ResponseMarshaler
Prepares a response for "CORS preflight rejected" scenario when yourCorsAuthorizer
denies a preflight request.Detailed documentation is available at https://www.soklet.com/docs/cors#writing-cors-responses.
- Specified by:
forCorsPreflightRejected
in interfaceResponseMarshaler
- Parameters:
request
- the HTTP requestcorsPreflight
- the CORS preflight request data- Returns:
- the response to be sent over the wire
-
forCorsAllowed
@Nonnull public MarshaledResponse forCorsAllowed(@Nonnull Request request, @Nonnull Cors cors, @Nonnull CorsResponse corsResponse, @Nonnull MarshaledResponse marshaledResponse) Description copied from interface:ResponseMarshaler
Applies "CORS is permitted for this request" data to a response.Invoked for any non-preflight CORS request that your
CorsAuthorizer
approves.This method will normally return a copy of the
marshaledResponse
with these headers applied based on the values ofcorsResponse
:Access-Control-Allow-Origin
(required)Access-Control-Allow-Credentials
(optional)Access-Control-Expose-Headers
(optional)
- Specified by:
forCorsAllowed
in interfaceResponseMarshaler
- Parameters:
request
- the HTTP requestcors
- the CORS request datacorsResponse
- CORS response data to write as specified byCorsAuthorizer
marshaledResponse
- the existing response to which we should apply relevant CORS headers- Returns:
- the response to be sent over the wire