Session Timeout AJAX Error in Tapestry Application Session Timeout AJAX Error in Tapestry Application ajax ajax

Session Timeout AJAX Error in Tapestry Application


For the AJAX that uses Prototype, you could add a global listener that reacts to AJAX failures using AJAX.Responders; jQuery has a similar construct called Ajax Events that you could use.

Both event handlers should just redirect to the login page on a 403 error. You could create a mixin with this functionality and add it to your layout component.

I have also used a mechanism that prevents session timeouts while the app is still open in a browser window by just doing an AJAX call and receiving an empty response every couple of minutes, thus keeping the session open. Stupid, but works okay.


you can contribute the T5 master dispatcher

public class AjaxAccessController implements Dispatcher {    @Override    public boolean dispatch(Request request, Response response) throws IOException {        // Si no hay session y la petición es ajax, recargar la página        Session session = request.getSession(false);        if (session == null && request.isXHR()) {            OutputStream os = response.getOutputStream("application/json;charset=UTF-8");            os.write("{\"script\":\"window.location.reload();\"}".getBytes());            os.flush();            return true;        }        return false;    }}

In your AppModule.java

public static void bind(ServiceBinder binder) {        // binder.bind(MyServiceInterface.class, MyServiceImpl.class);        // Make bind() calls on the binder object to define most IoC services.        // Use service builder methods (example below) when the implementation        // is provided inline, or requires more initialization than simply        // invoking the constructor.        // Id de AjaxAccessController        binder.bind(AjaxAccessController.class).withId("AjaxAccessController");    }public void contributeMasterDispatcher(            OrderedConfiguration configuration,            @InjectService("AjaxAccessController") Dispatcher accessController) {        configuration.add("AjaxAccessController", accessController, "before:ComponentEvent");    }

So every ajax request without session, the page will reloads and it redirects to your index page


Well, Ajax request is made to server it sends the header "HTTP_X_REQUESTED_WITH" with value "XMLHttpRequest". You can just check serverside that whether it is ajax request with above header and condition for login and session timeout before proceeding further in your index page.

If your criteria gets matched then simply print "window.top.location.href='login page'" in your function.

In PHP i can do this as ,

<?php if($_SERVER['HTTP_X_REQUESTED_WITH'] === "XMLHttpRequest" && condition for session check){    echo "<script>window.top.location.href='login.php'</script>";    }?>

You can add the condition similar to it in your framework.