I was working on a custom interceptor that would use the init() method to configure itself. After some analysis I realized that the init() method was being called multiple times per action invocation. So, I made a very simple interceptor to test to make sure I wasn¹t crazy about this.
package net.vitarara.quadran.core.web.menu; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; public class TestInterceptor implements Interceptor { public static int initCount = 0; public void destroy () { } public void init () { System.err.println ("BEGIN: TestInterceptor.init()"); TestInterceptor.initCount = TestInterceptor.initCount + 1; System.err.println ("TestInterceptor.initCount = " + TestInterceptor.initCount); System.err.println ("TestInterceptor = " + this.toString () ); System.err.println ("END: TestInterceptor.init()"); } public String intercept (ActionInvocation invocation) throws Exception { System.err.println ("BEGIN: TestInterceptor.intercept()"); String result = invocation.invoke (); System.err.println ("END: TestInterceptor.intercept()"); return result; } } Here is the struts.xml portion defining the interceptor and the stack: <interceptors> <interceptor name="qmenu" class="qMenuInterceptor" /> <interceptor name="testInterceptor" class="net.vitarara.quadran.core.web.menu.TestInterceptor" /> <interceptor-stack name="defaultStack"> <interceptor-ref name="servlet-config" /> <interceptor-ref name="params" /> <interceptor-ref name="prepare" /> <interceptor-ref name="chain" /> <interceptor-ref name="model-driven" /> <!-- <interceptor-ref name="component" /> --> <interceptor-ref name="fileUpload" /> <interceptor-ref name="static-params" /> <interceptor-ref name="params" /> <interceptor-ref name="conversionError" /> <interceptor-ref name="validation" /> <interceptor-ref name="workflow" /> <!-- <interceptor-ref name="qmenu" /> --> <interceptor-ref name="testInterceptor" /> </interceptor-stack> </interceptors> Here's the log output: 11:35:40,557 INFO [STDOUT] 11:35:40,557 INFO [XmlConfigurationProvider] Parsing configuration file [struts-default.xml] 11:35:40,664 INFO [STDOUT] 11:35:40,664 INFO [XmlConfigurationProvider] Parsing configuration file [struts-plugin.xml] 11:35:40,670 INFO [STDOUT] 11:35:40,670 INFO [XmlConfigurationProvider] Parsing configuration file [struts.xml] 11:35:40,721 ERROR [STDERR] BEGIN: TestInterceptor.init() 11:35:40,721 ERROR [STDERR] TestInterceptor.initCount = 9 11:35:40,721 ERROR [STDERR] TestInterceptor = [EMAIL PROTECTED] 11:35:40,721 ERROR [STDERR] END: TestInterceptor.init() 11:35:40,797 INFO [STDOUT] 11:35:40,797 INFO [XmlConfigurationProvider] Parsing configuration file [struts-default.xml] 11:35:40,940 INFO [STDOUT] 11:35:40,940 INFO [XmlConfigurationProvider] Parsing configuration file [struts-plugin.xml] 11:35:40,946 INFO [STDOUT] 11:35:40,946 INFO [XmlConfigurationProvider] Parsing configuration file [struts.xml] 11:35:40,985 ERROR [STDERR] BEGIN: TestInterceptor.init() 11:35:40,985 ERROR [STDERR] TestInterceptor.initCount = 10 11:35:40,986 ERROR [STDERR] TestInterceptor = [EMAIL PROTECTED] 11:35:40,986 ERROR [STDERR] END: TestInterceptor.init() 11:35:41,060 ERROR [STDERR] BEGIN: TestInterceptor.intercept() 11:35:41,060 ERROR [STDERR] !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!! 11:35:41,071 INFO [STDOUT] 11:35:41,071 INFO [XmlConfigurationProvider] Parsing configuration file [struts-default.xml] 11:35:41,191 INFO [STDOUT] 11:35:41,190 INFO [XmlConfigurationProvider] Parsing configuration file [struts-plugin.xml] 11:35:41,196 INFO [STDOUT] 11:35:41,196 INFO [XmlConfigurationProvider] Parsing configuration file [struts.xml] 11:35:41,244 ERROR [STDERR] BEGIN: TestInterceptor.init() 11:35:41,244 ERROR [STDERR] TestInterceptor.initCount = 11 11:35:41,244 ERROR [STDERR] TestInterceptor = [EMAIL PROTECTED] 11:35:41,244 ERROR [STDERR] END: TestInterceptor.init() 11:35:41,470 INFO [STDOUT] 11:35:41,470 INFO [XmlConfigurationProvider] Parsing configuration file [struts-default.xml] 11:35:41,630 INFO [STDOUT] 11:35:41,630 INFO [XmlConfigurationProvider] Parsing configuration file [struts-plugin.xml] 11:35:41,644 INFO [STDOUT] 11:35:41,644 INFO [XmlConfigurationProvider] Parsing configuration file [struts.xml] 11:35:41,720 ERROR [STDERR] BEGIN: TestInterceptor.init() 11:35:41,720 ERROR [STDERR] TestInterceptor.initCount = 12 11:35:41,721 ERROR [STDERR] TestInterceptor = [EMAIL PROTECTED] 11:35:41,721 ERROR [STDERR] END: TestInterceptor.init() 11:35:41,737 ERROR [STDERR] END: TestInterceptor.intercept() The ! marks are in the actions execute() method. Looking at this log output I have a few questions: 1. It looks to me that the TestInterceptor is being instantiated multiple times. Why? 2. Why is are the various struts xml files being parsed multiple times for a single action invocation? Thanks, Mark --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]