Announcement Announcement Module
Collapse
No announcement yet.
HandlerInterceptorAdapter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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()) {
    log.info("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().

    Joerg

    Comment


    • #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.

      log.info("req uri := " + request.getRequestURI());

      I have included my SimpleUrlHandlerMapping for reference, thanks.


      <bean
      class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
      <property name="mappings">
      <value>
      /pages/secured/customer/*=customerMainController
      </value>
      </property>
      <property name="interceptors">
      <list>
      <ref bean="handleInterceptor"/>
      </list>

      </property>
      </bean>

      Comment


      • #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.

        Joerg

        Comment


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

          Comment

          Working...
          X