Interface RequestInterceptor
A standard threadsafe implementation can be acquired via defaultInstance().
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull RequestInterceptorAcquires a threadsafeRequestInterceptorinstance with sensible defaults.default voidinterceptRequest(@NonNull ServerType serverType, @NonNull Request request, @Nullable ResourceMethod resourceMethod, @NonNull Function<Request, MarshaledResponse> responseGenerator, @NonNull Consumer<MarshaledResponse> responseWriter) Intercepts request processing, allowing the request to be replaced and/or the response to be transformed.default voidwrapRequest(@NonNull ServerType serverType, @NonNull Request request, @NonNull Consumer<Request> requestProcessor) Called before Soklet begins request processing, allowing the request to be wrapped or replaced.
-
Method Details
-
wrapRequest
default void wrapRequest(@NonNull ServerType serverType, @NonNull Request request, @NonNull Consumer<Request> requestProcessor) Called before Soklet begins request processing, allowing the request to be wrapped or replaced.Routing happens after this callback, so changes to the HTTP method or path affect which Resource Method is selected.
You must call
requestProcessor.accept(...)exactly once before returning to advance processing. If you do not, Soklet logs the error and returns a 500 response.This method is not fail-fast. If an exception occurs when Soklet invokes this method, Soklet will catch it and surface separately via
LifecycleObserver.didReceiveLogEvent(LogEvent)with typeLogEventType.REQUEST_INTERCEPTOR_WRAP_REQUEST_FAILED.- Parameters:
serverType- the server type that received the requestrequest- the request that was receivedrequestProcessor- receives the request to use for subsequent processing
-
interceptRequest
default void interceptRequest(@NonNull ServerType serverType, @NonNull Request request, @Nullable ResourceMethod resourceMethod, @NonNull Function<Request, MarshaledResponse> responseGenerator, @NonNull Consumer<MarshaledResponse> responseWriter) Intercepts request processing, allowing the request to be replaced and/or the response to be transformed.This method is not fail-fast. If an exception occurs when Soklet invokes this method, Soklet will catch it and surface separately via
LifecycleObserver.didReceiveLogEvent(LogEvent)with typeLogEventType.REQUEST_INTERCEPTOR_INTERCEPT_REQUEST_FAILED.You must call
responseWriter.accept(...)exactly once before returning to send a response. If you do not, Soklet logs the error and returns a 500 response.- Parameters:
serverType- the server type that received the requestrequest- the request that was receivedresourceMethod- the Resource Method that will handle the requestresponseGenerator- function that performs standard request handling and returns a responseresponseWriter- receives the response to send to the client
-
defaultInstance
Acquires a threadsafeRequestInterceptorinstance with sensible defaults.The returned instance is guaranteed to be a JVM-wide singleton.
- Returns:
- a
RequestInterceptorwith default settings
-