Class ValidatingInterceptor
- All Implemented Interfaces:
HandlerDecorator, HandlerInterceptor
HandlerInterceptor that validates the payload of messages before they are handled. When the supplied
validator supports contextual method constraints, the current message context can be used to resolve constrained
method parameters.-
Nested Class Summary
Nested classes/interfaces inherited from interface HandlerDecorator
HandlerDecorator.MergedDecoratorNested classes/interfaces inherited from interface HandlerInterceptor
HandlerInterceptor.InterceptedHandler, HandlerInterceptor.PreparedHandlerFunction, HandlerInterceptor.PreparedHandlerInputFunction, HandlerInterceptor.PreparedHandlerInputInterceptor, HandlerInterceptor.PreparedHandlerInterceptor, HandlerInterceptor.PreparedInterceptedHandler -
Field Summary
Fields inherited from interface HandlerDecorator
noOpFields inherited from interface HandlerInterceptor
defaultInterceptors -
Constructor Summary
ConstructorsConstructorDescriptionCreates an interceptor backed by the default validator.ValidatingInterceptor(Validator validator) Creates an interceptor backed by the supplied validator.ValidatingInterceptor(Validator validator, boolean validatePayload) Creates an interceptor backed by the supplied validator. -
Method Summary
Modifier and TypeMethodDescriptioninterceptHandling(Function<DeserializingMessage, Object> function, HandlerInvoker invoker) Wraps handler invocation with payload validation before invocation.prepare(HandlerDescriptor handler) Prepares this interceptor for a specific handler method.prepareInput(HandlerDescriptor handler) Prepares this interceptor to run without first creating a complete message.prepareInput(HandlerDescriptor handler, HandlerInput<DeserializingMessage> preparedInput) Prepares this interceptor using both the selected handler method and a representative input.booleanIndicates whether this interceptor opts into the prepared, mergeable handler wrapper.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HandlerDecorator
andThenMethods inherited from interface HandlerInterceptor
wrap
-
Constructor Details
-
ValidatingInterceptor
public ValidatingInterceptor()Creates an interceptor backed by the default validator. -
ValidatingInterceptor
Creates an interceptor backed by the supplied validator.- Parameters:
validator- the validator to use for payload and return value validation
-
ValidatingInterceptor
Creates an interceptor backed by the supplied validator.- Parameters:
validator- the validator to use for validationvalidatePayload- whether incoming message payloads should be validated before handler invocation
-
-
Method Details
-
interceptHandling
public Function<DeserializingMessage, Object> interceptHandling(Function<DeserializingMessage, Object> function, HandlerInvoker invoker) Wraps handler invocation with payload validation before invocation. Non-passive request handlers with a method annotation also get return value validation when the handler method declares return constraints.- Specified by:
interceptHandlingin interfaceHandlerInterceptor- Parameters:
function- handler invocation functioninvoker- handler metadata and invocation context- Returns:
- a validating handler invocation function
-
prepare
Description copied from interface:HandlerInterceptorPrepares this interceptor for a specific handler method.The returned interceptor is cached and reused concurrently for invocations with the same stable handler metadata. Implementations may use this hook to resolve annotation- or signature-based policy once while keeping message-dependent decisions inside
HandlerInterceptor.PreparedHandlerInterceptor.interceptHandling(DeserializingMessage, HandlerDescriptor, BiFunction, HandlerInterceptor.PreparedHandlerFunction).The default adapter preserves the existing
HandlerInterceptor.interceptHandling(Function, HandlerInvoker)contract and deliberately disables the reusableHandlerMethodpath. Custom interceptors therefore retain their current behavior unless they explicitly opt into preparation.- Specified by:
preparein interfaceHandlerInterceptor- Parameters:
handler- stable metadata for the handler method- Returns:
- a thread-safe prepared interceptor
-
prepareInput
Description copied from interface:HandlerInterceptorPrepares this interceptor to run without first creating a complete message.Return
nullwhen the interceptor requires the regular message-based handling path. The default only supports an interceptor whose prepared behavior is the shared no-op policy, so existing interceptors retain their exact behavior unless they opt in explicitly.The returned policy may be cached and invoked concurrently.
- Specified by:
prepareInputin interfaceHandlerInterceptor- Parameters:
handler- stable information about the selected handler method- Returns:
- a thread-safe payload-first policy, or
nullto use regular message-based handling
-
prepareInput
public HandlerInterceptor.PreparedHandlerInputInterceptor prepareInput(HandlerDescriptor handler, HandlerInput<DeserializingMessage> preparedInput) Description copied from interface:HandlerInterceptorPrepares this interceptor using both the selected handler method and a representative input.Override this overload when the interceptor's ability to use payload-first handling depends on input characteristics. The default delegates to
HandlerInterceptor.prepareInput(HandlerDescriptor).- Specified by:
prepareInputin interfaceHandlerInterceptor- Parameters:
handler- stable information about the selected handler methodpreparedInput- a representative input for the prepared handler plan- Returns:
- a thread-safe payload-first policy, or
nullto use regular message-based handling
-
supportsPreparation
public boolean supportsPreparation()Description copied from interface:HandlerInterceptorIndicates whether this interceptor opts into the prepared, mergeable handler wrapper.The default is
false, preserving the exact wrapper behavior of existing custom interceptors. An interceptor should returntrueonly whenHandlerInterceptor.prepare(HandlerDescriptor)returns a thread-safe plan that fully represents its handling behavior. If a subclass overrides only the legacyHandlerInterceptor.interceptHandling(Function, HandlerInvoker)method, the legacy wrapper is retained automatically.- Specified by:
supportsPreparationin interfaceHandlerInterceptor- Returns:
truewhen this interceptor may be merged into a prepared wrapper
-