[jira] [Created] (CXF-8249) SSE client refuses to accept valid stream

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[jira] [Created] (CXF-8249) SSE client refuses to accept valid stream

ASF GitHub Bot (Jira)
Ihor Zahoruiko created CXF-8249:

             Summary: SSE client refuses to accept valid stream
                 Key: CXF-8249
                 URL: https://issues.apache.org/jira/browse/CXF-8249
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
    Affects Versions: 3.3.5
            Reporter: Ihor Zahoruiko

The standard (https://www.w3.org/TR/eventsource/#parsing-an-event-stream) defines that in the stream event fields (date, event, id etc.) a space after the colon is optional, i.e. both options are valid:
data: test{noformat}
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: ")) {


I use Spring with the SseEmitter class to generate an event stream, something like 
SseEmitter emitter = new SseEmitter ();
emitter.send ("test");{code}
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"{code}

The SSE client in the client application: 
try (SseEventSource source = SseEventSource.target(someurl).build()) {
      (inboundSseEvent) -> System.out.println(inboundSseEvent.readData()
} catch (Exception ex) {
Dependency in pom.xml 

This message was sent by Atlassian Jira