New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SseEmitter cannot use "send(SseEventBuilder builder)" method with custom SseEventBuilder implementation [SPR-13591] #18169

Closed
spring-issuemaster opened this Issue Oct 20, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Oct 20, 2015

Maksym Shalak opened SPR-13591 and commented

SseEmitter class contains method "send(SseEventBuilder builder)" which is supposed to be used for custom messages. But the first line of this method contains code

Set<DataWithMediaType> dataToSend = ((SseEventBuilderImpl) builder).build();

That means if we pass SseEventBuilder to the method we receive a ClassCastException since we cannot cast our implementation of interface SseEventBuilder to built-in implementation SseEventBuilderImpl. And SseEventBuilderImpl is a private class, so we will not be able to override it.
So basically that means we cannot create our custom messages at all.


Affects: 4.2.1

Attachments:

Referenced from: commits 1c382be

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Oct 26, 2015

Rossen Stoyanchev commented

I've removed the class cast and added a build method to SseEventBuilder.

By the way I'd interested to hear more about your use case with creating a custom message, i.e. the underlying reason for wanting to extend SseEventBuilder.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Oct 26, 2015

Maksym Shalak commented

We just wanted to get rid of the "data:" prefix and pass pure JSON into the stream.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Oct 27, 2015

Rossen Stoyanchev commented

Is this for Server-Sent Events you mean? According to the spec the field name should be: event, data, id, retry, or otherwise should be ignored. Or if you just want to stream data to the response (not necessarily SSE-formatted) why not use ResponseBodyEmitter instead of SseEmitter?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Oct 28, 2015

Maksym Shalak commented

Yep, looks like ResponseBodyEmitter better suites my needs, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment