Definitely singleton-ish, although i thought there was an
instance-per-package--I thought I had packages with the same interceptor
configured in different ways, but I can't check at the moment.

Dave



On Wed, Apr 24, 2013 at 9:28 AM, Maurizio Cucchiara
<mcucchi...@apache.org>wrote:

> @Dave, I also could be wrong, but I remember that interceptors are
> singletone (maybe there is a single instance per package).
> @Steven looks like you're using Spring, if yes, could you check if you
> experience the same behavior w/o it?
> Il giorno 24/apr/2013 14:04, "Dave Newton" <davelnew...@gmail.com> ha
> scritto:
>
> > I'm not sure I understand what you mean regarding using the "include"
> > element (i.e., precisely what you're doing) but I thought that each
> package
> > would have its own set of interceptors, meaning there would be two
> > instances, hence init would be called twice.
> >
> > This would be trivial to determine by checking to see if it's the same
> > instance.
> >
> > I could be misremembering.
> >
> > Dave
> >
> >
> >
> > On Wed, Apr 24, 2013 at 7:52 AM, Steven Yang <kenshin...@gmail.com>
> wrote:
> >
> > > I was using 2.1.8 and recently upgraded to 2.3.14.
> > > And I realized that my interceptor got initialized twice and it didnt
> > > happen before.
> > >
> > > This happens when I declare a default package in struts.xml and include
> > > other xml which have packages that extends my default package. But the
> > > thing is no matter how many more xml I include the interceptor will
> only
> > be
> > > initialize one extra time.
> > >
> > > the following is my sample struts.xml
> > >
> > >  <package name="default" namespace="/" extends="struts-default">
> > >
> > > <interceptors>
> > > <interceptor name="baseGeneral"
> class="GeneralInterceptor"></interceptor>
> > > <interceptor-stack name="biStack">
> > > <interceptor-ref name="baseGeneral"/>
> > > </interceptor-stack>
> > > </interceptors>
> > >         <default-action-ref name="index" />
> > >
> > >         <global-results>
> > >             <result name="error">/error.jsp</result>
> > >         </global-results>
> > >
> > >         <global-exception-mappings>
> > >             <exception-mapping exception="java.lang.Exception"
> > > result="error"/>
> > >         </global-exception-mappings>
> > >
> > >         <action name="index">
> > >             <result type="redirectAction">
> > >                 <param name="actionName">HelloWorld</param>
> > >                 <param name="namespace">/example</param>
> > >             </result>
> > >         </action>
> > >     </package>
> > >
> > >     <include file="example.xml"/>
> > >
> > > my example.xml
> > >
> > >   <package name="example" namespace="/example" extends="default">
> > >
> > >         <action name="HelloWorld" class="example.HelloWorld">
> > >             <result>/example/HelloWorld.jsp</result>
> > >         </action>
> > > </package>
> > >
> > > I traced the log and see the that my default package is been
> initialized
> > > twice and it seems that struts knows about it but it still called
> init()
> > on
> > > my interceptor.
> > > partial log:
> > >
> > > 2013-04-24 11:57:58,504 DEBUG
> > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
> > > (Slf4jLogger.java:69) - Using default implementation of FileManager
> > > provided under name [system]: DefaultFileManager
> > > 2013-04-24 11:57:58,505 DEBUG
> > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
> > > (Slf4jLogger.java:69) - Loaded [BUILDER] {PackageConfig Name:default
> > > namespace:/ parents:[{PackageConfig Name:struts-default namespace:
> > > parents:[]}]}
> > > GeneralInterceptor.init()
> > > 2013-04-24 11:57:58,509 DEBUG
> > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
> > > (Slf4jLogger.java:69) - Loaded //index in 'default'
> package:{ActionConfig
> > > index () - action -
> > > file:/D:/workspace_tsb/struts2-blank/build/classes/struts.xml:30:30}
> > > 2013-04-24 11:57:58,510 DEBUG
> > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
> > > (Slf4jLogger.java:69) - Loaded [BUILDER] {PackageConfig Name:example
> > > namespace:/example parents:[{PackageConfig Name:default namespace:/
> > > parents:[{PackageConfig Name:struts-default namespace: parents:[]}]}]}
> > > 2013-04-24 11:57:58,513 DEBUG
> > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
> > > (Slf4jLogger.java:69) - Loaded /example/HelloWorld in 'example'
> > > package:{ActionConfig HelloWorld (example.HelloWorld) - action -
> > > file:/D:/workspace_tsb/struts2-blank/build/classes/example.xml:10:62}
> > > 2013-04-24 11:57:58,514 DEBUG
> > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
> > > (Slf4jLogger.java:69) - Loaded /example/Login_* in 'example'
> > > package:{ActionConfig Login_* (example.Login.{1}()) - action -
> > > file:/D:/workspace_tsb/struts2-blank/build/classes/example.xml:14:67}
> > > 2013-04-24 11:57:58,514 DEBUG
> > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
> > > (Slf4jLogger.java:69) - Loaded /example/* in 'example'
> > > package:{ActionConfig * (example.ExampleSupport) - action -
> > > file:/D:/workspace_tsb/struts2-blank/build/classes/example.xml:19:57}
> > > 2013-04-24 11:57:58,515 DEBUG
> > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
> > > (Slf4jLogger.java:69) - Loaded [BUILDER] {PackageConfig Name:default
> > > namespace:/ parents:[{PackageConfig Name:struts-default namespace:
> > > parents:[]}]}
> > > GeneralInterceptor.init()
> > > 2013-04-24 11:57:58,516 DEBUG
> > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
> > > (Slf4jLogger.java:69) - Loaded //index in 'default'
> package:{ActionConfig
> > > index () - action -
> > > file:/D:/workspace_tsb/struts2-blank/build/classes/struts.xml:30:30}
> > > 2013-04-24 11:57:58,516 DEBUG
> > > com.opensymphony.xwork2.util.logging.slf4j.Slf4jLogger
> > > (Slf4jLogger.java:69) - The package name 'default' is already been
> loaded
> > > by the same location and could be removed: package -
> > > file:/D:/workspace_tsb/struts2-blank/build/classes/struts.xml:11:68
> > >
> > >
> > > as you can see struts knows that "default" has been loaded before
> however
> > > my interceptor still prints out init message.
> > >
> > > If I remove the include or move the "default" package declaration out
> to
> > > another file and use include to include it in struts.xml the problem
> goes
> > > away.
> > >
> > > Is this behavior correct? or I am using something in the wrong way?
> > >
> > > Thanks
> > >
> >
> >
> >
> > --
> > e: davelnew...@gmail.com
> > m: 908-380-8699
> > s: davelnewton_skype
> > t: @dave_newton <https://twitter.com/dave_newton>
> > b: Bucky Bits <http://buckybits.blogspot.com/>
> > g: davelnewton <https://github.com/davelnewton>
> > so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
> >
>



-- 
e: davelnew...@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton <https://twitter.com/dave_newton>
b: Bucky Bits <http://buckybits.blogspot.com/>
g: davelnewton <https://github.com/davelnewton>
so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>

Reply via email to