Interface ResponseMarshaler
- All Known Implementing Classes:
DefaultResponseMarshaler
The MarshaledResponse value returned from these methods is what is ultimately sent back to
clients as bytes over the wire.
Full documentation is available at https://www.soklet.com/docs/response-writing.
- Author:
- Mark Allen
-
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 yourCorsAuthorizerapproves a preflight request.forCorsPreflightRejected(Request request, CorsPreflight corsPreflight) Prepares a response for "CORS preflight rejected" scenario when yourCorsAuthorizerdenies 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 HTTPHEADrequest.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 HTTPOPTIONSrequest.forThrowable(Request request, Throwable throwable, ResourceMethod resourceMethod) Prepares a response for scenarios in which an uncaught exception is encountered.
-
Method Details
-
forHappyPath
@Nonnull MarshaledResponse forHappyPath(@Nonnull Request request, @Nonnull Response response, @Nonnull ResourceMethod resourceMethod) 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.
- 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
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.
- Parameters:
request- the HTTP request- Returns:
- the response to be sent over the wire
-
forMethodNotAllowed
@Nonnull MarshaledResponse forMethodNotAllowed(@Nonnull Request request, @Nonnull Set<HttpMethod> allowedHttpMethods) 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.
- Parameters:
request- the HTTP requestallowedHttpMethods- appropriate HTTP methods to write to theAllowresponse header- Returns:
- the response to be sent over the wire
-
forContentTooLarge
@Nonnull MarshaledResponse forContentTooLarge(@Nonnull Request request, @Nullable ResourceMethod resourceMethod) 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.
- 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 MarshaledResponse forOptions(@Nonnull Request request, @Nonnull Set<HttpMethod> allowedHttpMethods) Prepares a response for an HTTPOPTIONSrequest.Note that CORS preflight responses are handled specially by
forCorsPreflightAllowed(Request, CorsPreflight, CorsPreflightResponse)andforCorsPreflightRejected(Request, CorsPreflight)- not this method.Detailed documentation is available at https://www.soklet.com/docs/response-writing#http-options.
- Parameters:
request- the HTTP requestallowedHttpMethods- appropriate HTTP methods to write to theAllowresponse header- Returns:
- the response to be sent over the wire
-
forThrowable
@Nonnull MarshaledResponse forThrowable(@Nonnull Request request, @Nonnull Throwable throwable, @Nullable ResourceMethod resourceMethod) 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.
- 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
-
forHead
@Nonnull MarshaledResponse forHead(@Nonnull Request request, @Nonnull MarshaledResponse getMethodMarshaledResponse) Prepares a response for an HTTPHEADrequest.Detailed documentation is available at https://www.soklet.com/docs/response-writing#http-head.
- Parameters:
request- the HTTP requestgetMethodMarshaledResponse- the binary data that would have been sent over the wire for an equivalentGETrequest (necessary in order to write theContent-Lengthheader for aHEADresponse)- Returns:
- the response to be sent over the wire
-
forCorsPreflightAllowed
@Nonnull MarshaledResponse forCorsPreflightAllowed(@Nonnull Request request, @Nonnull CorsPreflight corsPreflight, @Nonnull CorsPreflightResponse corsPreflightResponse) Prepares a response for "CORS preflight allowed" scenario when yourCorsAuthorizerapproves a preflight request.Detailed documentation is available at https://www.soklet.com/docs/cors#writing-cors-responses.
- 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 MarshaledResponse forCorsPreflightRejected(@Nonnull Request request, @Nonnull CorsPreflight corsPreflight) Prepares a response for "CORS preflight rejected" scenario when yourCorsAuthorizerdenies a preflight request.Detailed documentation is available at https://www.soklet.com/docs/cors#writing-cors-responses.
- Parameters:
request- the HTTP requestcorsPreflight- the CORS preflight request data- Returns:
- the response to be sent over the wire
-
forCorsAllowed
@Nonnull MarshaledResponse forCorsAllowed(@Nonnull Request request, @Nonnull Cors cors, @Nonnull CorsResponse corsResponse, @Nonnull MarshaledResponse marshaledResponse) Applies "CORS is permitted for this request" data to a response.Invoked for any non-preflight CORS request that your
CorsAuthorizerapproves.This method will normally return a copy of the
marshaledResponsewith these headers applied based on the values ofcorsResponse:Access-Control-Allow-Origin(required)Access-Control-Allow-Credentials(optional)Access-Control-Expose-Headers(optional)
- Parameters:
request- the HTTP requestcors- the CORS request datacorsResponse- CORS response data to write as specified byCorsAuthorizermarshaledResponse- the existing response to which we should apply relevant CORS headers- Returns:
- the response to be sent over the wire
-