Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

S2: Have custom interceptor execute before defaultStack

 
Chris Boldon
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic