Heartbeat method overwrite

He there,

in my application I have set the heartbeat interval in the web.xml file.
Now with every heartbeat been send from the client, i must send a heartbeat to another service.
I search all documentation and of course I used google, but nothing popped up so far.

If anybody knows which method to overwrite to achieve this

please let me know




I’m not aware of any ‘heartbeatevent’ or anything like that. But one option would be to add your own request handler for example in your servlet init using the VaadinSession.getCurrent().addRequestHandler method.

The implementation of your custom request handler would be pretty much like com.vaadin.server.communication.HeartbeatHandler, but you should not write a response and you should always return false in order to invoke the actual HeartbeatHandler too. From this custom request handler you could then call any services etc. you want.

He there,

thanks for replying to my question. I understand that i have to add my own listener.
But in my Vaadinservlet instance the Vaadinsession.getCurrent() always returns null …

Adding the Handler in my UI does not seems to have any effect at all

so … no way to add a handler or to trace every heartbeat request in the UI :frowning:

bad luck

but thanks


In VaadinServlet.init() there can be no sessions, as the servlet is only initializing. But you can add a session init listener in which you can add the custom heartbeat listener:

class MyServlet extends VaadinServlet implements SessionInitListener {
public void init() {

public void sessionInit(SessionInitEvent event) throws ServiceException {
    event.getSession().addRequestHandler(new RequestHandler() {
        public boolean handleRequest(VaadinSession session,
               VaadinRequest request, VaadinResponse response) throws IOException {
            // Do stuff
            return false;

[/code]Alternatively, you can add a global RequestHandler by overriding VaadinServlet.createVaadinServletService() to return a custom VaadinServletService subclass that overrides VaadinService.createRequestHandlers().

He thanks,

that worked out! To access my UI Object from the Requestlistener I had to do a little trick.

As described in this thread: