I created an Authentication Interceptor in struts2.
I have to check when when calling the interceptor method.
so I printed the names of the methods on the console.
Here is my code
public class AuthenticationInterceptor implements Interceptor { @Override public void destroy() { System.out.println("AuthenticationInterceptor destroy"); } @Override public void init() { System.out.println("AuthenticationInterceptor init"); } @Override public String intercept(ActionInvocation actionInvocation) throws Exception { System.out.println("AuthenticationInterceptor intercept"); return actionInvocation.invoke(); } }
Here is my package in struts.xml.
<package name="portfolioSecure" namespace="/secure" extends="portfolio"> <interceptors> <interceptor name="authenticationInterceptor" class="ask.portfolio.utility.AuthenticationInterceptor"></interceptor> <interceptor-stack name="secureStack"> <interceptor-ref name="authenticationInterceptor"></interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> </interceptor-stack> </interceptors> <default-interceptor-ref name="secureStack"></default-interceptor-ref> <action name="login" class="ask.portfolio.actions.Login"> <result name="success">/loginSuccess.jsp</result> <result name="error">/welcome.jsp</result> </action> </package>
when my application starts Authentication Interceptor init prints to the console
and similarly, Authentication Interceptor intercept also prints. But Authentication Interceptor destroy is not printed, even if I stop the server I want to know when the kill interceptor method is called, and what is postprocessing in the interceptor, this is due to the destroy () method.
Abhij source share