[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:
{noformat}
data:test
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
{code:java}
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: ")) {
  ...
}{code}
Why?

 

I use Spring with the SseEmitter class to generate an event stream, something like 
{code:java}
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....
{code:java}
emitter.send (" test");  // adding a space to get "data: test"{code}
 

The SSE client in the client application: 
{code:java}
try (SseEventSource source = SseEventSource.target(someurl).build()) {
   source.register(
      (inboundSseEvent) -> System.out.println(inboundSseEvent.readData()
   );
   source.open();
} catch (Exception ex) {
}{code}
Dependency in pom.xml 
{code:java}
<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>{code}
 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)