Results 1 to 3 of 3

Thread: passing HttpRequest info to aspect.

Hybrid View

  1. #1
    Join Date
    May 2007
    Location
    Istanbul
    Posts
    42

    Default 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. #2
    Join Date
    Sep 2007
    Location
    Oceanside, CA
    Posts
    187

    Default

    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 at 07:34 PM.
    Mike Bingham

  3. #3
    Join Date
    May 2007
    Location
    Istanbul
    Posts
    42

    Default 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.

Posting Permissions

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