From the course: Java EE: Contexts and Dependency Injection

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Create an interceptor

Solution: Create an interceptor

From the course: Java EE: Contexts and Dependency Injection

Start my 1-month free trial

Solution: Create an interceptor

(metal slicing) - So how did you get on? Well this is my solution. I've created a new interceptor called TimerInterceptor and I've created it with the priority of 10. Remember the priority of the other interceptor is a hundred, so this should be executed before the other interceptor. Within the interceptor method, all I've done is to take the current time in Millis. I forward the call onto the target method, and then I've taken the Milliseconds after the method has been executed. I then print this out to the console and return the value returned from the method. And what I've done is I've created a new interceptor binder called Timed, which is here. It contains the same structure as before. So we have the Inherited annotation, the Interceptor binder annotation, the Retention is set at RUNTIME, and the target is set at METHOD and TYPE. In the CustomerService method, what I've done here is I've added the Interceptor binder to the method rather than the entire class. What this means is…

Contents