Question

I am using Spring annotations to initialize my BayeuxServer. I enabled websocket by setting the transport in my Spring bean -

 BayeuxServerImpl bean = new BayeuxServerImpl();

 bean.setTransports(new WebSocketTransport(bean));

But now, when websocket connection fails or is disabled in js($.cometd.websocketEnabled = false;), it's not falling back to long polling successfully. It throws error "400 Unknown Bayeux Transport" in firebug console.

I couldn't set LongPollingTransport in setTransports since LongPollingTransport is an abstract class in the library. I tried creating a class which extends LongPollingTransport and specifying it in the setTransports API, but that didn't work either. Please let me know if I am doing something wrong. We need long polling to work in case websockets fail.

cometd version: 2.5.1

jetty version: 7.6.8

Was it helpful?

Solution

By calling BayeuxServer.setTransports(...) with just one transport, you basically disable any fall back capability since you are explicitly telling CometD to use 1 transport only.

Class LongPollingTransport has 2 subclasses depending on the specific mechanism to use; you may want to use class JSONTransport.

Note that the CometD documentation has an example of how to setup WebSocket with Spring using XML, but it is enough to translate the XML into code to have it working with annotations.

Basically, it all boils down to:

bayeuxServer.setTransports(new WebSocketTransport(bayeuxServer), new JSONTransport(bayeuxServer));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top