Announcement Announcement Module
Collapse
No announcement yet.
passing HttpRequest info to aspect. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • passing HttpRequest info to aspect.

    Hi everybody,

    I use spring at business and data layers (JPA + hibernate) but not at web layer (not using Spring MVC). At web layer, Java Page Flow /JPF) is used instead.

    I have an AOP aspect to trace transactions at business and dao layers,
    it is configured to execute when a service or dao method executes.

    But it is required that user info must also be logged. But the problem is business and dao layers doesn't "know" HttpRequest/Session object that holds user information (request.getRemoteUser())

    Do you have any idea to pass this info to business layer ?

  • #2
    One option might be to inject a session- or request-scoped bean containing user information. See here for an example:

    http://static.springframework.org/sp...ther-injection
    Last edited by Mike Bingham; Oct 2nd, 2007, 07:34 PM.

    Comment


    • #3
      working!

      Thanks for your reply. It's definetely working...

      This is the solution:
      after adding this listener to web.xml :

      Code:
      <listener>
      <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
      </listener>
      it is possible to reach HttpRequest and HttpSession objects.

      I can reach the user by this statement:

      Code:
      ServletRequestAttributes requestAttributes = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes());
      String userName = requestAttributes.getRequest().getRemoteUser();
      as always Spring has a solution.

      Comment

      Working...
      X