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 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.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:ResponseMarshalerPrepares 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:
forHappyPathin 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:ResponseMarshalerPrepares 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:
forNotFoundin 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:ResponseMarshalerPrepares 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:
forMethodNotAllowedin interfaceResponseMarshaler- Parameters:
request- the HTTP requestallowedHttpMethods- appropriate HTTP methods to write to theAllowresponse 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:ResponseMarshalerPrepares 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:
forContentTooLargein 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:ResponseMarshalerPrepares a response for an HTTPOPTIONSrequest.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:
forOptionsin interfaceResponseMarshaler- Parameters:
request- the HTTP requestallowedHttpMethods- appropriate HTTP methods to write to theAllowresponse 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:ResponseMarshalerPrepares a response for an HTTPHEADrequest.Detailed documentation is available at https://www.soklet.com/docs/response-writing#http-head.
- Specified by:
forHeadin interfaceResponseMarshaler- 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
-
forThrowable
@Nonnull public MarshaledResponse forThrowable(@Nonnull Request request, @Nonnull Throwable throwable, @Nullable ResourceMethod resourceMethod) Description copied from interface:ResponseMarshalerPrepares 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:
forThrowablein 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:ResponseMarshalerPrepares 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.
- Specified by:
forCorsPreflightAllowedin 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:ResponseMarshalerPrepares 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.
- Specified by:
forCorsPreflightRejectedin 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:ResponseMarshalerApplies "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)
- Specified by:
forCorsAllowedin interfaceResponseMarshaler- 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