Java Reference
In-Depth Information
START_EXECUTION_TIME_KEY);
long executionEndTime = System.currentTimeMillis();
StringBuffer logTxt = new StringBuffer
("Execution completed for request - ");
logTxt.append(request.getRequestURI());
logTxt.append(", handler -");
logTxt.append(handler);
logTxt.append(", total execution time(ms) -");
logTxt.append((executionEndTime - executionStartTime));
log.info(logTxt.toString());
}
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
request.setAttribute(START_EXECUTION_TIME_KEY, System.currentTimeMillis());
return true;
}
}
The advantage of using the convenience abstract class is evident in Listing 3-44.
I just had to override those methods that are required. Alternatively, using the
HandlerInterceptor , I would need to implement three methods, and the callback
afterCompletion would be redundant. To use this interceptor, it must be associated with
a handler mapping. This is shown in the Spring configuration file (Listing 3-45). Note
that I have used the inner bean style of configuration because this bean is relevant only
in the context of a handler mapping bean.
Listing 3-45. insurance-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
>
<! - - Other beans - ->
Search WWH ::




Custom Search