Reputation: 4165
I'm trying to set up some websocket enabled resources using Dropwizard and Atmosphere. I have based my setup on the code here: https://cvwjensen.wordpress.com/2014/08/02/websockets-in-dropwizard/
I use the following code to set up Atmosphere in Dropwizard:
AtmosphereServlet atmosphere = new AtmosphereServlet();
atmosphere.framework().addInitParameter(ApplicationConfig.ANNOTATION_PACKAGE, "my.classes");
atmosphere.framework().addInitParameter(ApplicationConfig.WEBSOCKET_SUPPORT, "true");
atmosphere.framework().addInitParameter(ApplicationConfig.PROPERTY_NATIVE_COMETSUPPORT, "true");
atmosphere.framework().addInitParameter(ApplicationConfig.PROPERTY_COMET_SUPPORT, "org.atmosphere.container.Jetty9AsyncSupportWithWebSocket");
ServletRegistration.Dynamic servlet = environment.servlets().addServlet("atmosphere", atmosphere);
servlet.addMapping("/APIWS/*");
And the resource I use to test it looks like this:
@GET
@Produces({"application/xml", "application/json"})
public SuspendResponse<JAXBElement<CustomerListType>> getUpdates(@Context BroadcasterFactory bf) {
Broadcaster bc = getBroadcaster(bf, hash);
registerBroadcaster(hash, query, apiContext.getUser());
return new SuspendResponse.SuspendResponseBuilder<JAXBElement<CustomerListType>>()
.broadcaster(bc)
.build();
}
It mostly works, but if I set the header Accept: application/json
in my Websocket request, it fails when the server tries to push something. Setting Accept: application/xml
works fine.
I test it using the following curl command:
curl -i -N -H "Accept: application/json" -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Sec-Websocket-Version: 13" -H "Sec-WebSocket-Key: 258E" http://localhost:8080/APIWS/customers
As soon as the server pushes some data, it fails with the following messages:
* STATE: PERFORM => DONE handle 0x80048248; line 1617 (connection #0)
* Curl_done
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
Upvotes: 1
Views: 376