i have written an interceptor implementation, however, it seems i cannot get
it to work. i have followed the instructions at
http://struts.apache.org/2.x/docs/interceptors.html. i have also followed
the instructions at
http://struts.apache.org/2.x/docs/how-do-we-configure-an-interceptor-to-be-used-with-every-action.htmlto
use the interceptor with every action.
however, when any of my actions run, i never see the pre and post processing
logging messages (logging messages inside the intercept method). i do see
the logging messages from the init and destroy methods. this is not a
problem with logging (as for sanity checking, i also use System.out.println,
and have Tomcat running in console mode). i also have placed some break
points in the intercept(ActionInvocation) method, but these break points are
never reached.
this is my struts.xml.
<struts>
<package name="default" extends="struts-default">
<interceptors>
<interceptor name="dummyInterceptor"
class="mypackage.DummyInterceptor"/>
<interceptor-stack name="dummyStack">
<interceptor-ref name="dummyInterceptor"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="dummyStack"/>
</package>
</struts>
this is my DummyInterceptor class.
public class DummyInterceptor implements Interceptor {
private static final Log _log =
LogFactory.getLog(DummyInterceptor.class);
public void destroy() {
_log.debug("dummy interceptor destroyed called");
System.out.println("dummy interceptor destroyed
called".toUpperCase());
}
public void init() {
_log.debug("dummy interceptor init called");
System.out.println("dummy interceptor init called".toUpperCase());
}
public String intercept(ActionInvocation actionInvocation) throws
Exception {
_log.debug("dummy interceptor intercept pre processing");
System.out.println("dummy interceptor intercept pre
processing".toUpperCase());
String result = actionInvocation.invoke();
_log.debug("dummy interceptor intercept post processing");
System.out.println("dummy interceptor intercept post
processing".toUpperCase());
return result;
}
}
i am using annotations for my Action classes, so i do not define any
<action> elements in struts.xml (using the Struts2 Convention jar).
one very interesting thing i did was to get struts-default.xml out of the
struts2-core-2.1.8.1.jar. i then modified struts-default.xml by adding: 1) a
definition of my interceptor and 2) my interceptor onto the defaultStack.
when i did this, my interceptor does work as expected (i see logging output
from the intercept method, i can hit break points set inside this method)
for all my actions.
i wonder if there is some gotcha that i am missing here. is there something
extra that i have to do when mixing annotations with interceptors?
thanks.