Announcement Announcement Module
No announcement yet.
Advice on how to use AOP on HTTPSession in SpringMVC Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Advice on how to use AOP on HTTPSession in SpringMVC


    I'm not sure what I'm trying to do is going to possible, so I was wondering if anyone out there had any thoughts...

    Using Spring MVC as the web framework, we're storing 2 objects in session - I'll call them LegacyObject and NewFangledObject

    What I'd like to do is intercept any call to HttpSession.setAttribute( ) and check to see if the web app is trying to set either the LegacyObject or the NewFangledObject into session.

    My question revolves around the fact that the HttpSession isn't explicitly spring-managed (e.g. there's no bean definition for it that I can proxy). Anyone have any direction on how to do this?

  • #2
    That is going to be tricky. You cannot use proxy based AOP so you will have to use either loadtime or compile time weaving. Now that also gets tricky because you will have to weave that class on the startup of your server (or you need to compile a new version of your server with compile time weaving).

    So it isn't as easy as you think...

    What is it that you want to do with it, the simple solution would be to create a wrapper for your HttpServletRequest (create a class that implements that interface and delegates all calls except the getSession stuff) and a wrapper for the HttpSession. Put a ServletFilter infront of everything and let that wrap the existing request with your decorated HttpServletRequest.

    Your HttpSession implementation can then do the checking/stuff you want to do within the setAttribute method.