Results 1 to 5 of 5

Thread: HandlerInterceptorAdapter

  1. #1

    Default 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. #2
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

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

    Joerg
    This post can contain insufficient information.

  3. #3

    Default

    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>

  4. #4
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Quote 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
    This post can contain insufficient information.

  5. #5
    Join Date
    Apr 2006
    Posts
    6

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •