How to check on Java-side if WebSocket push is used

Have seem to have situations where WebSocket push does not work in development mode. Usually it works, but sometimes it does not and falls back to long-polling. I still have no real clue why this is the case. In development mode I can check the push type by looking at the browsers development console. However, in production mode I can’t. In order to check if things are working in production mode I need to know in production mode if WebSocket push is working.

Is there any API or possibility on Java-side to check if WebSocket push is working?

Thanks and kind regards,

Martin

Hi.

You can check the used Push setting on the server through:

PushConfiguration pushConfiguration = UI.getPushConfiguration();
boolean isPushDisabled = pushConfiguration.getPushMode().equals(PushMode.DISABLED);
Transport transport = pushConfiguration.getTransport();
boolean isWebSocket = transport.equals(Transport.WEBSOCKET);
boolean isWebSocketXhr = transport.equals(Transport.WEBSOCKET_XHR);
  • Mikael

It actually seems like the PushConfiguration transport will only give the requested transport method and not the actual transport in use. So it would appear the we do not know on the server if we use the requested transport or the fallbackTransport.

Hi,

I am not actually sure if you want to check what communication mechanism is in use for your customers or just how to test against a production mode build. Just in case if you need the latter one, all you need to do is open the browsers developer tools and choose the network tab. That should tell you whether the communication channel in use is websockets or normal XHR.

In chrome the sequence would be: Open dev tools → Open the network tab → tick “WS” → click a row in the table below (if there is one) → click “messages”

If you end up seeing the websocket communication, you are using websockets. If the table is empty, you are probably using a fall-back method.

-Matti