Vaadin 10 Flow application continually and automatically refreshes itself i

Hi,

I am trying to understand how heartbeatInterval operates when @Push is used.

If I configure my application as follows, everything works as I would expect based on my understanding of heartbeatInterval, closeIdleSessions and session-timeout.

@WebServlet(urlPatterns = “/*”, name = “arplaunch”, asyncSupported = false,
initParams = {
@WebInitParam(name = “productionMode”, value = “false”),
@WebInitParam(name = “heartbeatInterval”, value = “-1”),
@WebInitParam(name = “closeIdleSessions”, value = “true”) })

There are no heartbeats sent by the client and the application in the browser never automatically refreshes itself even if the browser tab is left open. The session timeout is configured on the Tomcat server at 2 minutes ( for testing purposes ). It would normally be 5 - 10 minutes.

Now if I add an @Push annotation to the application and change nothing else, the behaviour changes.

Again there are no heartbeats sent by the client. However, if the browser tab is open and idle it automatically resends the request every 3 minutes - it seems like it detects that the session has been destroyed and it re-establishes a new session. This appears to be done by VaadinPush.js.

Can this be changed and still use Push in the application?

I want to use push from the server side to update the UI in my application.
However, if the browser tab is open and idle, I don’t want the last URL request replayed continuously.

Thanks for any help,

John.

Hi John,

In order to change this (default) behavior, sessionExpiredNotificationEnabled of com.vaadin.flow.server.SystemMessages class should be set to true.

VaadinService uses an instance of SystemMessagesProvider interface for getting system messages to display to users of the service.
There is a default implementation of it called DefaultSystemMessagesProvider but you can create your own custom implementation and have the fields of SystemMessages changed:

You can do it by registering a custom VaadinServiceInitListener and set you custom SystemMessagesProvider inside the serviceInit method as below.


public class ApplicationServiceInitListener implements VaadinServiceInitListener {

    @Override
    public void serviceInit(ServiceInitEvent event) {
        event.getSource().setSystemMessagesProvider(new SysMessageProvider());
    }


    public static class SysMessageProvider implements SystemMessagesProvider{

        @Override
        public SystemMessages getSystemMessages(SystemMessagesInfo systemMessagesInfo) {
            CustomizedSystemMessages messages =
                    new CustomizedSystemMessages();
            messages.setSessionExpiredNotificationEnabled(true);
            return messages;
        }
    }
}

To register the listener take a look at https://vaadin.com/docs/v14/flow/advanced/tutorial-service-init-listener.html

Regards,

Hi,

I am coming back to this again and am re-reading Klaudeta’s response from before. I cannot explain the behaviour I am seeing so perhaps someone can help.

If I set the following in application.properties (I am using Spring)

vaadin.productionMode=true
vaadin.heartbeatInterval=-1
vaadin.closeIdleSessions=true

and I set the session-timeout=4 minutes in the tomcat web.xml configuration file. I get the following behaviour…

If there is no activity, tomcat kills the session after 4 minutes and my application is returned to the login page which is what I want. However, there are a bunch of exceptions generated in the application log file because the http session is effectively pulled out from beneath the VaadinSession by tomcat. This seems to be not the right way to do it, however, it is the only way I can get the desired behaviour.

If I set the following

vaadin.productionMode=true
vaadin.heartbeatInterval=60
vaadin.closeIdleSessions=true

Now, again there is no activity by the user but the application sends a heartbeat every 1 minute. Tomcat sees activity and keeps the session alive. However, I would expect the closeIdleSessions parameter to take over and recognise that we have had three heartbeats in a row with no other user activity and so the Vaadin session should be closed and if the user returns to the application, they are diverted to the login page. However, this is does not happen. It seems that the session is kept open and the user can continue using the session.

Is there another “vaadin session timeout” parameter setting? i.e. NOT the http session timeout setting configured in Tomcat.

Thanks for any help,
John