Announcement Announcement Module
No announcement yet.
HandlerInterceptorAdapter Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • HandlerInterceptorAdapter

    Was wondering if anyone could explain why my log statements in the preHandle method are printing twice?

    Here is a code snippet from my subclass of HandlerInterceptorAdaptor

    private static final Logger log = Logger.getLogger(HandlerInterceptor.class);

    public boolean preHandle(
    HttpServletRequest request,
    HttpServletResponse response,
    Object handler) throws Exception {

    HttpSession sess = request.getSession();
    String username =(String)sess.getAttribute("ACEGI_SECURITY_LAST_US ERNAME");
    if (username != null) {
    Authentication auth = SecurityContextHolder.getContext().getAuthenticati on();
    if (log.isInfoEnabled()) {"USERNAME: " + sess.getAttribute("ACEGI_SECURITY_LAST_USERNAME") + " AUTHENTICATED: " + auth.isAuthenticated());
    return true;


    The above interceptor is a property of my SimpleUrlHandlerMapping, so therefore every request should mean that the interceptor gets called and logs the above statements.

    This is working apart from the log statements are printing twice, do I need to override the afterCompletion method instead?

    Any help in clarifying this would be appreciated.

  • #2
    Are you sure it's the same request? Try to log request.getUrl().



    • #3
      Thanks for the reply when I add the following log statement to my interceptor class, it also prints twice?

      Where request is the HttpServletRequest object."req uri := " + request.getRequestURI());

      I have included my SimpleUrlHandlerMapping for reference, thanks.

      class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
      <property name="mappings">
      <property name="interceptors">
      <ref bean="handleInterceptor"/>



      • #4
        Originally posted by JamesHoare View Post
        Thanks for the reply when I add the following log statement to my interceptor class, it also prints twice?
        I would not have expect something different. The question was only if it is really the same request, so if they have the same request URI. From what you wrote I guess they are. Unfortunately, I do not have any explanation for this behavior.



        • #5
          Did you try with Sysout in console?
          I remember, once due to a duplicate entry in my , i was getting the logs twice.