4. Adding workflow with interceptors Flashcards
What’s the object called that encapsulates the Action, Result, and all the interceptors?
ActionInvocation
What’s the method an interceptor needs to implement?
public String intercept(ActionInvocation invocation) throws Exception
How does an interceptor call the next item in the chain? What does this return?
invocation.invoke();
Call the invoke method on the ActionInvocation that’s passed to it.
Make sure to return this value! It returns the result, so we can respond to the result or just pass it along.
If you have an interceptor that should not continue, how can you accomplish that?
Return a control string rather than calling invoke()
How can an interceptor get access to the Action?
invocation.getAction();
What interceptor will map exceptions to error pages?
What XML properties would you modify to map them?
exception – Interceptor
exception-mapping – Holds an exception & result.
How can you register application wide results?
XML: global-results
How do you create an application level exception-mapping?
XML: global-exception-mappings
How do you declare an interceptor?
In XML there’s an interceptors tag, we can add an individual interceptor with name and class parameters.
How do you declare an interceptor stack?
In XML there’s an interceptor-stack tag with a name parameter, here we add individual interceptor-ref with a name parameter that references an interceptor.
How can you add an interceptor to a specific action?
Add an interceptor-ref to the action.
What happens to the inherited interceptors when you manually set interceptors for an action? Can we fix it?
They’re lost, your manually defined interceptors will be all that’s used. You can add it back in by adding the ‘defaultStack’ interceptor.
How can you pass parameters to an interceptor?
Inside the interceptor-ref tag you can add param with a name and has the value in the tag.
How can you get access to user sessions in an Action?
implement SessionAware interface. Now you have access to ‘session’ which is a map that you can put/get items.
Within an interceptor, how can you get access to the users session?
invocation.getInvocationContext().getSession()
First we use the ActionInvocation that’s passed in to get the ActionContext, then use that to get the session.