5 Replies Latest reply: Oct 18, 2012 10:28 AM by diego.toranzo RSS

    Add an interceptor to  defaultStack through a plugin?

    suneel

      Hi all,

      Is it possible to add my custom interceptor to the defaultStack through a plugin? I want this interceptor to intercept all calls to actions in struts-community.xml. If this can be done, can you please give me the steps?

       

      Thanks

      Suneel

        • Re: Add an interceptor to  defaultStack through a plugin?
          Mandar Tuljapurkar

          Hi Suneel,

               To my knowledge, it seems that this might not be possible. You could try redefining the entire defaultStack in your plugin. But I think that too might not help.

          I would also like to know what happens when you do this.

          Regards,

          Mandar

            • Re: Add an interceptor to  defaultStack through a plugin?
              Ryan Rutan

              I was going to something very similar.  I wouldn't recommend it, since plugins are loaded in a random order. If another plugin did this same practice...there would be no guarantee which one runs last.  That being said, it should word with limited success.  There may be a scope issue with having a child package of struts-default being the master default interceptor stack (but that's based off of a "just feels odd" guess, more so than fact).  If you do try it, please share your thoughts.

            • Re: Add an interceptor to  defaultStack through a plugin?
              suneel

              Ryan and Mandar, thanks for the replies.

              I could get the interceptor working in the plugin's struts.xml using the following approach:

              I had to redefine the package "community-default" as "my-default". And then make every package that extended 'community-default' extend 'my-default', by redefining them in struts.xml as shown below.

               

              <package name="my-default" extends="struts-default">...........

              <package name="my-community-actions-include" extends="my-default">...................

               

              This only worked as long as other plugins didn't override actions defined in this plugin. So to overcome this limitation I had to switch to overlay approach.

                • Re: Add an interceptor to  defaultStack through a plugin?
                  Mandar Tuljapurkar

                  Thanks for the update Suneel. I will remember this while I face such a scenario.

                  • Re: Add an interceptor to  defaultStack through a plugin?
                    diego.toranzo

                    Hi Suneel, I am trying to do the same as you did but I think I am missing something or doing something wrong and I will appreciate your help.

                     

                    After reading your post I tried something like this in my struts.xml:

                     

                    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

                            "http://struts.apache.org/dtds/struts-2.0.dtd">

                    <struts>

                     

                    <!-- This is my own package, where I define my interceptor and I set it up to apply to all the package -->

                    <package name="mydefault" extends="struts-default">

                            <interceptors>

                                <interceptor name="myInterceptor" class="my.package.MyInterceptor">

                                    <param name="excludeMethods">

                                        input,back,cancel,default,withRedirect,removeAttach,doCancel,delete,reply,skip

                                    </param>

                                </interceptor>

                            </interceptors>

                            <!-- Next line is to make my interceptor apply to all the package -->

                            <default-interceptor-ref name="myInterceptor"></default-interceptor-ref>

                    </package>

                     

                    <!-- This is the redefinition of the global package -->

                    <package name="community-default" extends="mydefault">

                    </package>

                     

                    </struts>

                     

                    Do you see something wrong in my code?

                     

                     

                    Many thanks,

                    Diego.