I have created a Authentication Interceptor in struts2.
I have to check that when does the interceptor method get called.
so i have printed method names on 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 AuthenticationInterceptor init get printed on console
and similarly AuthenticationInterceptor intercept also prints.But AuthenticationInterceptor destroy does not get printed even if i stop server
i want to know when interceptors destroy method is called and what is postprocessing in interceptor is it related with destroy method().
The destroy method called only once, when the container or application is stopped or un-deployed. It called to let an interceptor clean up any resources it has allocated.