Details
Description
The standard (https://www.w3.org/TR/eventsource/#parsing-an-event-stream) defines that in the stream event fields (data, event, id etc.) a space after the colon is optional, i.e. both options are valid:
data:test data: test
But SSE client does not accept stream events where format without a space after the colon (data:test).
In the class org.apache.cxf.jaxrs.sse.client.InboundSseEventProcessor line parsing is performed as
if (StringUtils.isEmpty(line) && builder != null) { ... } else if (line.startsWith("event: ")) { ... } else if (line.startsWith("id: ")) { ... } else if (line.startsWith(": ")) { ... } else if (line.startsWith("retry: ")) { ... } else if (line.startsWith("data: ")) { ... }
Why?
I use Spring with the SseEmitter class to generate an event stream, something like
SseEmitter emitter = new SseEmitter (); emitter.send ("test");
This class generate event using format "data:test", and I can't read this events in a client application where the SSE client is used.
If I change the line by adding a space, SSE client accept event....
emitter.send (" test"); // adding a space to get "data: test"
The SSE client in the client application:
try (SseEventSource source = SseEventSource.target(someurl).build()) { source.register( (inboundSseEvent) -> System.out.println(inboundSseEvent.readData() ); source.open(); } catch (Exception ex) { }
Dependency in pom.xml
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-rs-client</artifactId> <version>3.3.5</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-rs-sse</artifactId> <version>3.3.5</version> </dependency>