I resolved my problem using Spring AOP MethodBeforeAdvice
public void before(Method methodName, Object[] arguments, Object arg2)
throws Throwable {
}
In this the methodName
is the name of method which is called. arguments
is the list of arguments of that method and arg2
is the returned object. So as HTTPRequest object is one of the objects in my action methods I am able to use the arguments and capture the session.
(Basically I have integrated Spring into my project which is Struts 1.3 based)
In applicationContext.xml
<bean name="globalInterceptor"
class="com.xyz.common.filters.GlobalRequestInterceptor"></bean>
<bean name="autoProxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>globalInterceptor</value>
</list>
</property>
</bean>
So this basically intercepts all the method calls in all the service beans.