Java Reference
In-Depth Information
Spring Interceptors
With the two enhancements solved efficiently, it's time to focus on the last requirement.
You have guessed it right—filters can be deployed to solve this problem as well. But that
would mean the monitoring starts even before the servlet invocation. Though with this
solution, the time variation would be negligible; the actual intention was to monitor the
total execution time of a use case. So, the best place to apply this processing was around
a page controller invocation. This would also make more information available to us (the
actual controller class name, and so on) than filters could. Moreover, with servlet filters,
you need to code the preprocessing and postprocessing in the same doFilter method,
which can be cumbersome. Hence, for this solution, I will resort to the Spring page con-
troller interceptor support shown in Figure 3-13.
Figure 3-13. Spring Handler interceptor chain
While discussing the Application Controller pattern earlier in this chapter, I briefly
touched upon the handler interceptors. They implement the HandlerInterceptor inter-
face. As you have come to expect by now, Spring MVC provides some concrete
implementations of this interface as well as convenience abstract classes to build on
handler interceptor functions, as shown in Figure 3-14.
Search WWH ::

Custom Search