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

  • Logging using AOP ...

    Hi friends,

    My requirement is to log all the users transactions initiated on my web-site.

    I want to log user-name in to the log file.

    See this code :

    import org.aopalliance.intercept.*;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.hibernate.Session;

    public class LoggingMethodInteceptor implements MethodInterceptor {

    private final Log logger = LogFactory.getLog(getClass());

    public Object invoke(MethodInvocation methodInvocation) throws Throwable
    {
    logger.error("method: "+methodInvocation.getMethod);
    }
    }


    Along with method executed, I want to log the user who initiated the method, the user name is stored in the instance of the class HttpSession and that I want in this method.

    for that if I can get HttpServletRequest instance in the above class then my problem will be solved.

    I have tried a lot but couldn't got the solution.
    if you can help me, it is greate for me .....

    I assure to help you subsequently if I can.

    Thank you in advance.

    Regards,
    Mukesh Bhojwani,

    BCA department,
    M.S. Unniversity,
    Baroda,Gujarat,India.

  • #2
    Couldn't you write a filter to bind the user information to a threadLocal? This would then be accessible in your interceptor.

    Comment


    • #3
      logging using AOP

      I think the alternative you have suggested, by that
      there would be conflict between multiple users......

      The user's just differ and have their identity in their
      session only, that's why I want session instance and
      for that I need HttpServletRequest intance..............

      can you please help ...

      Regards,
      Mukesh Bhojwani.

      Comment


      • #4
        I don't think there would be a problem at all. Acegi uses the threadLocal pattern to store the user credentials for the request. It's a pretty common thing to do.

        Comment

        Working...
        X