Session Expired "click here" link

Hello,

I’ve noticed that when I restart the Apache Tomcat while logged into the vaadin application, on the next “action” I get:

Session Expired
Take note of any unsaved data, and
click here
to continue.

The
click here
link takes you back (looks like it tries to refresh) to the page you were on when session expired. I’d like this link to take the user to the login page. I can’t seem to find information on how to change it.

Any help appreciate. Thanks.

Hi Srki,

Not something I’ve done myself, but I think if you provide SystemMessages, you can specify a SessionExpiredUrl. See:

https://vaadin.com/book/vaadin7/-/page/application.errors.html#application.errors.systemmessages

    protected void servletInitialized() throws ServletException {

        getService().setSystemMessagesProvider(new SystemMessagesProvider() {

            public SystemMessages getSystemMessages(SystemMessagesInfo systemMessagesInfo) {
                CustomizedSystemMessages messages = new CustomizedSystemMessages();
                messages.setSessionExpiredNotificationEnabled(true);
                messages.setSessionExpiredURL("/login");
                return messages;
            }
        });
        super.servletInitialized();
    }

Dave

Dave,

Thanks for your response. I ended up making it work by creating CustomSystemMessageProvider class:

public class CustomSystemMessageProvider implements SystemMessagesProvider { @Override public SystemMessages getSystemMessages(SystemMessagesInfo systemMessagesInfo) { CustomizedSystemMessages messages = new CustomizedSystemMessages(); messages.setSessionExpiredURL("/login"); return messages; } } and then setting the SystemMessageProvider in the UI to use CustomSystemMessageProvider:

protected void init(VaadinRequest request) {
    // some code here .....
    // .............
    VaadinService.getCurrent().setSystemMessagesProvider(new CustomSystemMessageProvider());
    // some code here ......
    // ......
}

For some reason this haven’t worked for me on the first try. Now it is working as expected.

Thanks.

Glad you’ve got something that works for you!

Out of interest, is there a specific reason you choose to do this in the UI rather than in the servlet? It would be more efficient to configure once during servlet initialisation, and then shared across all sessions/UIs.

I don’t know if replacing the SystemMessageProvider in the UI might be less reliable - e.g. if the messages have already been prepared to send to the client before your UI code is run, swapping your custom provider for the default provider? Not an area I know well, but something like this might explain why it didn’t work on your first try…

Dave

Dave,

Very good point. Moved to servlet.

Thanks again!