Java Reference
In-Depth Information
Figure 3-14. Handler interceptor class diagram
The convenience abstract base class HandlerInterceptorAdapter implements all three
methods defined by the HandlerInterceptor interface. The preHandle method performs
preprocessing of a request before it is handled by the page controller. Similarly,
postHandle is responsible for postprocessing. The afterCompletion is a callback method
called finally when the view rendering is done. The UserRoleAuthorizationInterceptor is a
concrete implementation handling authorization checks on the current user based on
user role and using the HttpServletRequest object's isUserInRole method. Finally, the
ThemeChangeInterceptor is invoked when the current theme (combination of images, style
sheets, and so on) of the web site is changed.
I will now try to solve the problem at hand by extending the
HandlerInterceptorAdapter class. Once the request is intercepted, the current time will be
saved as a request attribute as part of preprocessing code. When the page controller
returns, the actual time taken will be logged along with any other information required to
be monitored. This is shown in Listing 3-44.
Listing 3-44. ExecutionMonitorInterceptor.java
public class ExecutiontimeMonitorInterceptor extends HandlerInterceptorAdapter {
private final Log log = LogFactory.getLog(
ExecutiontimeMonitorInterceptor.class);
private static final String START_EXECUTION_TIME_KEY = "executionStartTime";
public void postHandle(HttpServletRequest request, HttpServletResponse response,
Object handler, ModelAndView modelAndView) throws Exception {
long executionStartTime = (Long) request.getAttribute(
 
Search WWH ::




Custom Search