I am trying to get server-sent events working with a JavaScript web client and a Spring Boot 1.5.7 application. I get the following error in the server log when the SseEmitter is returned from the REST endpoint when the client initially connects:
o.g.j.m.i.WriterInterceptorExecutor :
MessageBodyWriter not found for media type=text/event-stream,
type=class org.springframework.web.servlet.mvc.method.annotation.SseEmitter,
genericType=class org.springframework.web.servlet.mvc.method.annotation.SseEmitter
The REST method gets called fine and I create and save the emitter for later. When the emitter is returned from the REST method, the above exception gets thrown.
I only get this when using EventSource in the web clients (Chrome and Firefox), not when using curl. I can even enter the URL in the browser and get a response without getting an error on the server.
I'm following pretty much every example I could find.
JavaScript:
const es = new EventSource('https://localhost:8443/sse');
es.onmessage = e => {console.log(e.data);};
es.onerror = e => {console.log('onerror:' + e);};
es.onopen = e => {console.log('onopen');};
Server:
@GET
@Path("/sse")
@Produces({"text/event-stream"})
public SseEmitter sse() {
SseEmitter emitter = new SseEmitter();
... save for later ...
return emitter;
}
Any ideas?
Thank You.