I'm new to Struts2 (Struts 2) and trying to get my custom interceptor to work. I think I set it up correctly. It's init method is called so I know that the interceptor exists. The action's execute method is called, so I know that the action is right. But for some reason the intercept() method on the interceptor is not called.
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="my-default" extends="struts-default">
<interceptors>
<interceptor name="authenticationInterceptor" class="security.AuthenticationInterceptor" />
<interceptor-stack name="secureStack">
<interceptor-ref name="authenticationInterceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="secureStack" />
<global-results>
<result name="error">/utils/Error.jsp</result>
<result name="login" type="redirect">goLogin.action</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception"
result="error" />
</global-exception-mappings>
</package>
</struts>
Edit: So I kind of see what's going on. Basically the stack containing my new interceptor is package specific so it will only apply to actions in that package. However, I'm using annotations so I'm not specifying actions in packages. By adding the @ParentPackage to the method of the action I want to get intercepted, it is correctly intercepted. As expected, if I'm not logged in, the interceptor returns "login" and a redirect is made to GoLogin.action. However, for some reason, GoLogin.action also gets intercepted and it just becomes a cycle of never ending intercepts. I never added the @ParentPackage to my GoLogin class however so I don't want it to get intercepted.
GoPortfolio (Action I want to be intercepted):
package go;
@ParentPackage("my-default")
@Result( value="/security/AdminPortfolio.jsp" )
public class GoPortfolio extends ActionSupport implements UserAware
{
private User user;
@Override
public void setUser(User user)
{
this.user = user;
}
public String execute()
{
System.out.println("Executing");
return SUCCESS;
}
}
GoLogin (class that I don't want to be intercepted):
package go;
import com.opensymphony.xwork2.ActionSupport;
@Result(value="security/Login.jsp")
public class GoLogin extends ActionSupport
{
}