Annotation Interface QueryHandlerInterceptor
Annotation marking a method as a query-specific interceptor handler on an
AnnotatedQueryHandlingComponent.
An annotated interceptor is invoked before every @QueryHandler method on the same component
instance. Two styles are supported:
- Before-interceptor — a method with no
MessageHandlerInterceptorChainparameter that returns eithervoidorCompletableFuture<Void>. The method runs before the handler; the chain is automatically proceeded after the method returns (or the future completes) normally. If it throws (or the future completes exceptionally), the handler is not invoked. - Surround-interceptor — a method that declares a
MessageHandlerInterceptorChainparameter and returns aMessageStream. The method controls whether and when the chain is proceeded by callingchain.proceed(query, ctx); it can also short-circuit by returning without calling proceed.
Example before-interceptor:
@QueryHandlerInterceptor
void audit(QueryMessage query) {
auditLog.record(query.qualifiedName());
}
Example surround-interceptor with short-circuit:
@QueryHandlerInterceptor
MessageStream<?> filterByTenant(
QueryMessage query,
MessageHandlerInterceptorChain<QueryMessage> chain,
ProcessingContext ctx
) {
if (!tenantId.equals(query.metaData().get("tenantId"))) {
return MessageStream.failed(new AccessDeniedException("Wrong tenant"));
}
return chain.proceed(query, ctx);
}
- Since:
- 5.2.0
- Author:
- Allard Buijze
- See Also: