-
Notifications
You must be signed in to change notification settings - Fork 37.7k
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 format text/plain if StringHttpMessageConverter is not configured #24465
Comments
The handling for So it not clear at all what the root cause of your issue is. Please, provide more details or a sample. |
I corrected the title because SseEmitter does no parsing, but rather the opposite. |
Sorry, you're right. Here you see the currently available converters for the ResponseBodyEmitterReturnValueHandler that the SseEmitter uses which is added here, in the RequestMappingHandlerAdapter And that list is set, in the adapter, over here Which is called from the RepositoryRestMvcConfiguration, in the repositoryExporterHandlerAdapter method, from which it get's it's defaultMessageConverter list where only a subselection of the converters are added. Please note: In my startup chain the repositoryExporterHandlerAdapter is called twice, only one of which comes from the RepositoryRestMvcConfiguration, the other initialization does include all the converters that would be needed. The SseEmitter uses the RepositoryRestMvc list of converters though, and because of that it cannot parse text/plain mediatypes |
Okay this makes is a bit more clear.
Either Spring Data REST can add If this isn't feasible we might be able to add special handling for SSE in case |
Happy to investigate what we can do to help. Just wondering why your controller ends up in the Spring Data REST specific |
I'm trying to make it work in an already existing spring data REST application, for outputting updated objects when they are altered. So the data i'd be sending would come from a spring data REST repository, and spring has been initialized to use it. So, for my test cases, I've tried sending both plaintext data and spring data REST entities, with both results in the same issue. The SseEmitter will always try to prepend a plaintext prefix, which will always fail because the converter chain lacks a text/plain capable converter. |
I've scheduled this to try an improvement in Spring MVC where we fall back on something for all the plain text in an SSE stream that surrounds the actual data. We're currently assuming there will always be a string message converter but we should be able to write text irrespective of that. |
Alright thanks! That seems like the proper solution in my scenario |
The SseEmitter included in the spring framework does not seem to include a capable text/plain parser in the underlying converter set.
Whenever i try to send any form of event, the emitter automatically includes a "data:" prefix, which it adds with the text/plain mediatype.
After a bit of digging i noticed some of the underlying functions use a subset of spring's default MessageConverters, this subset does not include the default String converter.
So, whenever i try to send any type of event like so:
it will inevitably result in a
java.lang.IllegalArgumentException: No suitable converter for class java.lang.String
The suggestion would be to either include the standard string converter, or let the SseEmitter use a different mediatype for pre- and suffixes that are supported in the Converter chain for the emitter.
I'm currently on spring boot version 2.1.12.RELEASE
The text was updated successfully, but these errors were encountered: