You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Miguel <mi...@almeida.at> on 2011/04/28 12:54:08 UTC

Overriding interceptor in stack

Today's question actually follows yesterday's suggestion by Dave of
using the preparable interface and is really an
architecture/convention-over-configuration question:

- what do you think about the possibility to override an interceptor by
reassigning it in the configuration? I don't think this is possible, but
the idea would be this:

1. You are using the <interceptor-ref name="defaultStack" />
2. If you define <interceptor name="prepare"	class="xxx" /> before this,
the defaultStack would use xxx instead of the default class.

The usefulness is to be able to use a different implementation of the
interceptor without having to copy-paste te entire stack just to change
this interceptor.


I thought of this while testing. My prepare method has a database call.
Now, I have a MyActionValidationIntegrationTest using
StrutsSpringTestCase where the main interest is to test validation. To
increase speed, I am not interested in the database call. With
<interceptor name="prepare" class="xxx" /> I could simply define a fake
xxx for my tests that didn't invoke the prepare() method.

I believe this also follows the convention-over-configuration pattern:
the default (interceptor) is used unless you redefine it (by writing an
interceptor with the same name)

Re: Overriding interceptor in stack

Posted by Dave Newton <da...@gmail.com>.
Seems like it'd be easier and cleaner to change the service impl the
interceptor uses rather than the interceptor itself.

Dave
 On Apr 28, 2011 6:54 AM, "Miguel" <mi...@almeida.at> wrote:
> Today's question actually follows yesterday's suggestion by Dave of
> using the preparable interface and is really an
> architecture/convention-over-configuration question:
>
> - what do you think about the possibility to override an interceptor by
> reassigning it in the configuration? I don't think this is possible, but
> the idea would be this:
>
> 1. You are using the <interceptor-ref name="defaultStack" />
> 2. If you define <interceptor name="prepare" class="xxx" /> before this,
> the defaultStack would use xxx instead of the default class.
>
> The usefulness is to be able to use a different implementation of the
> interceptor without having to copy-paste te entire stack just to change
> this interceptor.
>
>
> I thought of this while testing. My prepare method has a database call.
> Now, I have a MyActionValidationIntegrationTest using
> StrutsSpringTestCase where the main interest is to test validation. To
> increase speed, I am not interested in the database call. With
> <interceptor name="prepare" class="xxx" /> I could simply define a fake
> xxx for my tests that didn't invoke the prepare() method.
>
> I believe this also follows the convention-over-configuration pattern:
> the default (interceptor) is used unless you redefine it (by writing an
> interceptor with the same name)