Activating the interceptor

We can now activate AuditInterceptor. One way of doing this is to specify the interceptor in the beans.xml files, as shown here:

<interceptors>
<class>
<AuditInterceptor>
</class>
</interceptors>

Alternatively, we can specify this with the @Priority annotation, which indicates the interceptor's priority. For example, we can annotate the AuditInterceptor class with the @Priority annotation APPLICATION level:

@Interceptor
@Auditable
@Priority(Interceptor.Priority.APPLICATION)
class AuditInterceptor {
@Inject
private lateinit var auditor: Auditor

@Inject
private lateinit var auditProcessor: AuditProcessor

@AroundInvoke
fun handle(context: InvocationContext) {
auditor.audit("message")
auditProcessor
.processMessage(context.method.getAnnotation(Auditable::class.java).value)
context.proceed()
}
}

The AuditInterceptor class's handle() function is invoked at the application level, which is usually the case for the interceptor. This means that each application request is intercepted by the AuditInterceptor class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset