Dynamic Redirection?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Dynamic Redirection?

Gazoo101
Hey Struts 2 People,

Or at least those who are left. This forum seems uncharacteristically empty although I think it is the official one. Isn't it? Anyway - I have another conundrum...

I am trying to redirect an action. Here are the details:

I have an Authentication Interceptor which intercepts a user, checks for a session, and based on the result then either sends him to the login action or just invokes the request. The code looks as follows:

public String intercept(ActionInvocation actionInvocation) throws Exception {
                Map session = actionInvocation.getInvocationContext().getSession();

                actions.User user;
                user = (actions.User) session.get(actions.Constants.USER_KEY);

                boolean isAuthenticated = (null!=user);
               
                if (!isAuthenticated) {
                        return Action.LOGIN;            
                } else {

                        return actionInvocation.invoke();
                }

        }

Now then... I've scowered the internet and found the following page:

http://www.vitarara.org/cms/struts_2_cookbook/creating_a_login_interceptor

I have no problems retrieving the action name and parameters from the current context, but how to properly set the action that is invoked escapes me. The solution proposed on the above mentioned homepage doesn't work for me due to 2 reasons:

1. I have actually implemented the solution provided, but I have no idea how to get the String which reveals the directory all my struts is being executed in. For example, a regular action on my server could be "http://localhost:8080/jk/administration/items.action". The namespace parameter provides "administration" and the actionname is "items", but I have no idea how to get "jk" from the context.

2. More importantly, the solution provided on the page requires a jsp page to re-redirect the user, which I find somewhat ugly. I'd much rather redirect the user directly from Java code invoked by Struts 2.

So I guess it all boils down to one question:

How do I force a new action into the actionInvocation context instead of the one it currently contains?

Regards,

Gazoo