Announcement Announcement Module
Collapse
No announcement yet.
How to get Session into an Aspect Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get Session into an Aspect

    Hi community,

    I have one question with Spring AOP and MVC. I want to add a aop-proxy to a special class inside my mvc application, but this need not to be a controller class. Therefore, I can not simply search for the session-data in joinPoint.getArgs().
    Is there a simple way to get the session data from the spring framework?

    Example:
    class MyController.createView(..) calls class X.m(..) calls class Y.n(..)

    Y is encapsulated by a spring aop-proxy where I want to have access on the session data. What I want to avoid is to delegate the session data through the classes.

    EDIT: Maybe useful: I am using Spring 2.5

    Thx for any help.

    Regards,
    miwo
    Last edited by miwo; Oct 20th, 2009, 05:46 AM. Reason: Further infos

  • #2
    I will provide you our usage and example. We use aspectj.
    Our project has a session scoped bean, context. With an interceptor just before everything the request is put into the context. And that context is autowired to all controllers by a super class.
    For the validation parts in the controllers aspect based mechanism is used, just before everything in controllers validation aspect is run, in that class we have the controller. By casting to super controller class we can get the context and from context we can get the request. Session can be reached from the request.

    We are new at Spring, so my example may not be the best practice but it looks ok for us.

    Comment


    • #3
      Hi Camper,

      I am not really sure, what you exactly mean with context. I think, it's a central component which holds session data?

      So, this would maybe my following idea:

      Put another aspect into the system and save a Map<Thread,HttpSession>, so I could recover the session data during the thread activity and delete this assignment afterwards. This would be a solution, but I don't like it. I want to keep the size of aspects and used JoinPoints small. And it's not really a crosscutting-concern that needs aop for modularization.

      But if spring can not provide this information, I would prefer it before delegating the session data. At least, if the data is used only for crosscutting-concerns implemented in an aspect.l

      Thx, your idea didn't helped directly, but it has inspired me

      Anybody a better solution within spring mvc?

      Regards,
      miwo

      Comment

      Working...
      X