aspose file tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Recursion in implementation of Struts 2 workflow Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Reply Bookmark "Recursion in implementation of Struts 2 workflow" Watch "Recursion in implementation of Struts 2 workflow" New topic
Author

Recursion in implementation of Struts 2 workflow

Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Hi,

In Struts 2, ActionInvocation and Interceptor(s) work together to implement the flow of serving an incoming request.

ActionInvocation holds a list of interceptors applicable to the current request. Its invoke() method iterates through the list and calls intercept() method on each method one by one, while keeping track of which interceptors have been called. Interceptors, in intercept() method, do what they are supposed to do, and then they call invoke() back on ActionInvocation.

This way all interceptors are called one by one until an Action is called, and then the control passes back through all interceptors in the reverse order.

See -
DefaultActionInvocation
TimerInterceptor


What I am trying to understand is why they implemented it this way?

Same results could be achieved by ActionInvocation keeping control all the time. It could call a before() method on each interceptor, call the action, and then call an after() method on each interceptor in reverse order.

What does the recursive approach get us that the iterative approach won't?
Is the recursive approach considered more elegant?

Cheers,
Sonny


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
 
I agree. Here's the link: jrebel
 
subject: Recursion in implementation of Struts 2 workflow
 
Similar Threads
ActionInvocation.invoke() Method will do what ?
Encoding and decoding in struts
interceptor not working in struts 2
Configuring a Interceptor to a Struts Action class
Struts 2 Problem