aspose file tools *
The moose likes Struts and the fly likes S2: Have custom interceptor execute before defaultStack Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "S2: Have custom interceptor execute before defaultStack" Watch "S2: Have custom interceptor execute before defaultStack" New topic
Author

S2: Have custom interceptor execute before defaultStack

Chris Boldon
Ranch Hand

Joined: Aug 10, 2006
Posts: 190
Hi all,

I'm trying to get a custom interceptor to execture before the default stack, but am having little luck.

I tried to define a custom stack with my custom being the first interceptor in the stack and the defaultStack being the second interceptor in the stack. The defaultStack still executed first.

Any ideas?

My goal is to have an interceptor executed before the framework even checks to see if the action being requested even exists.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Interceptors are executed in the order of definition--the framework (obviously) relies on that functionality.

I'm not sure about your stated goal, however; IIRC on startup the framework will instantiate actions defined in the config file to ensure they exist (at least for non-wildcarded class definitions), and it scans the classpath for annotated/conventional classes for actions defined outside of any config files when using Codebehind (deprecated) or Convention--not sure what version of S2 you're using though.

I'd suggest posting your config and interceptor code--it's more likely that one or the other aren't quite right, or that they're making a false assumption. The struts-user mailing list might be a better place to get other feedback for this type of question.
Chris Boldon
Ranch Hand

Joined: Aug 10, 2006
Posts: 190
Thanks for the prompt reply.

I'll better explain exactly what I am trying to do, maybe I am not understanding interceptor implementation.

I am trying to redirect anything not recognized as an action (ANYTHING) to a certain action.

ie
say my context is http://localhost/myapp/
and I have an action http://localhost/myapp/main.action
if a user types http://localhost/myapp/asdf I want to be able to direct that to another action.

In struts1 I was doing this with a filter, but I saw an opportunity to leverage some of struts2 new features. Maybe the better bet is to extend the struts FilterDispatcher, run my own code in the doFilter method then punch out to super() ? I guess the interceptors are executed after the action is already decided?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The thing to do is use the default-action-ref package configuration element:



See the Action Configuration docs for more details, in the "Action Default" section (I'm adding a TOC now, but you'll probably get there before it propagates).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: S2: Have custom interceptor execute before defaultStack