Search code examples
gwtgwt-ext

Redirect to Index page after session timeout not working in .war


We are using Struts2 & GWT-EXT.

We have crated a LoginInterceptor which will be called before performing certain restricted tasks.

Here is the method of LoginInterceptor

public String intercept(ActionInvocation arg0) throws Exception {

        try
        {
            System.err.println("inside the login interceptor");
            Map session = arg0.getInvocationContext().getSession();
            User loggedInUser = (User)session.get("loggedInUser");

            if(loggedInUser != null)
            {

                return arg0.invoke();
            }else {

                throw new AuthorizationException("unAuthorized");               
            }

        }catch (Exception e) {          
            throw e;
        }       
    }

After session timout.. If a user clicks on any button. Before proceeding LoginInterceptor gets called and checks whethere user is logged in or not.

In the code

We have a method public void onFailure(Throwable caught) {

where i check that

if (caught instanceof InvocationException) {
        if (caught instanceof StatusCodeException
                && caught.getMessage().contains(
                    "<title>Error 500 unAuthorized</title>")) {
            MessageBox.alert("Session Expired", "Session has been expired. Press Ok to redirect to Login page.", new AlertCallback(){ 
                    public void execute(){ 
                        History.newItem(HistoryToken.INDEX_PAGE.toString());
                    } 
                }); 

        } else if (caught.getMessage().contains("LoginInterceptor")) {
            History.newItem(HistoryToken.INDEX_PAGE.toString(), true);
        }

Then, I redirect it to Index Page.

This works in Eclipse fine in Hosted Mode but when I create .war and run it in JBoss. It does not comes into onFailure method and gets redirected directly to Index Page.


Solution

  • Hiii...

    try this code just before the invocation exception code. before if (caught instanceof InvocationException) { condition....

    if(caught.getMessage().contains("unAuthorized") )
        {
            MessageBox.alert("Session Expired", "Session has been expired. Press Ok to redirect to Login page.", new AlertCallback(){ 
                public void execute(){ 
                    History.newItem(HistoryToken.INDEX_PAGE.toString());
                } 
            }); 
    
        }