struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leah OConnor <leahocon...@sbcglobal.net>
Subject Re: interceptor is not being called for all action
Date Sun, 31 Jan 2010 19:24:58 GMT
Thank you for posting your solution.  I aso read
> http://struts.apache.org/2.x/docs/convention-plugin.html#ConventionPlugin-XWorkpackages
>
several times and do not see the connection.  I'm not sure I understand exactly what you

did solved the problem, but it is clerarer than the documention
 

--- On Sat, 1/30/10, Jake Vang <vangjake@googlemail.com> wrote:


From: Jake Vang <vangjake@googlemail.com>
Subject: Re: interceptor is not being called for all action
To: user@struts.apache.org
Date: Saturday, January 30, 2010, 5:38 PM


okay, to answer my own question, yes, if you configure everything correctly,
then you can get a customized stack to work for all Actions. the only thing
you really need to do is add this line to struts.xml

<constant name="struts.convention.default.parent.package" value="default"/>

with this defined, you can remove the @ParentPackage and @InterceptorRef
from the classes and methods.

wow, it was that easy.

On Sat, Jan 30, 2010 at 6:14 PM, Jake Vang <vangjake@googlemail.com> wrote:

> okay, after fiddling around for 2 hours, with the weak documentation out
> there, i think i have it figured out. at least empirically, it works now.
> just in case there are other users out there who are running into this
> problem, let me explain what in the world i did. i know A LOT of other
> people have run into this problem on how to get interceptors to work with
> the convention plugin (googling). the shame is that although i saw a lot of
> "thanks, i got it working", no one ever bothered to show how they got it to
> work.
>
> at any rate, if you read the original post by me, you will see how my
> interceptor stack was defined in struts.xml. you will also see how i
> implemented a dummy interceptor. i had to do two things to get my
> interceptor working (called on my action).
> 1. add @ParentPackage("default") to my Action class
> 2. add @interceptorRefs={@InterceptorRef("dummyStack") to my execute method
> (in my Action class).
>
> after i did this, my interceptor's intercept(ActionInvocation) method is
> called when my Action is called.
>
> here's how my dummy Action class looks like.
>
> @ParentPackage("default")
> public class DummyAction extends ActionSupport {
>  @Action(value="/dummy",
>   results={@Result(name="success",location="dummy-success.jsp")},
>   interceptorRefs={@InterceptorRef("dummyStack")}
>  )
>  public String execute() {
>   return SUCCESS;
>  }
> }
>
> alright, so, now i'd like to know how to get this interceptor stack
> (dummyStack) to work on all actions? in the link i posted, you can do so
> using one single line in struts.xml (i.e. <default-interceptor-ref
> name="dummyStack"/>). with the convention plugin + annotations, is such a
> simple approach possible? or do i have to continuously add @ParentPackage
> and @InterceptorRef annotations to the classes and methods i want to use the
> stack?
>
> i don't know why this is such a pain (but then again, i'm not a developer
> on the struts2 project, so there may be a lot of complexities to get this
> working elegantly that i'm unaware of).
>
> On Sat, Jan 30, 2010 at 4:10 PM, Jake Vang <vangjake@googlemail.com>wrote:
>
>> 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.
>>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message