Package org.springframework.http.codec
Class ServerSentEventHttpMessageWriter
java.lang.Object
org.springframework.http.codec.ServerSentEventHttpMessageWriter
- All Implemented Interfaces:
- HttpMessageWriter<Object>
HttpMessageWriter for "text/event-stream" responses.- Since:
- 5.0
- Author:
- Sebastien Deleuze, Arjen Poutsma, Rossen Stoyanchev
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor without anEncoder.ServerSentEventHttpMessageWriter(Encoder<?> encoder) Constructor with JSONEncoderfor encoding objects.
- 
Method SummaryModifier and TypeMethodDescriptionbooleancanWrite(ResolvableType elementType, MediaType mediaType) Whether the given object type is supported by this writer.Encoder<?>Return the configuredEncoder, if any.Return the list of media types supported by this Writer.reactor.core.publisher.Mono<Void>write(Publisher<?> input, ResolvableType actualType, ResolvableType elementType, MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> hints) Server-side only alternative toHttpMessageWriter.write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)with additional context available.reactor.core.publisher.Mono<Void>write(Publisher<?> input, ResolvableType elementType, MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints) Write a given stream of object to the output message.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.http.codec.HttpMessageWritergetWritableMediaTypes
- 
Constructor Details- 
ServerSentEventHttpMessageWriterpublic ServerSentEventHttpMessageWriter()Constructor without anEncoder. In this mode onlyStringis supported for event data to be encoded.
- 
ServerSentEventHttpMessageWriterConstructor with JSONEncoderfor encoding objects. Support forStringevent data is built-in.- Parameters:
- encoder- the Encoder to use (may be- null)
 
 
- 
- 
Method Details- 
getEncoderReturn the configuredEncoder, if any.
- 
getWritableMediaTypesDescription copied from interface:HttpMessageWriterReturn the list of media types supported by this Writer. The list may not apply to every possible target element type and calls to this method should typically be guarded viacanWrite(elementType, null). The list may also exclude media types supported only for a specific element type. Alternatively, useHttpMessageWriter.getWritableMediaTypes(ResolvableType)for a more precise list.- Specified by:
- getWritableMediaTypesin interface- HttpMessageWriter<Object>
- Returns:
- the general list of supported media types
 
- 
canWriteDescription copied from interface:HttpMessageWriterWhether the given object type is supported by this writer.- Specified by:
- canWritein interface- HttpMessageWriter<Object>
- Parameters:
- elementType- the type of object to check
- mediaType- the media type for the write (possibly- null)
- Returns:
- trueif writable,- falseotherwise
 
- 
writepublic reactor.core.publisher.Mono<Void> write(Publisher<?> input, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints) Description copied from interface:HttpMessageWriterWrite a given stream of object to the output message.- Specified by:
- writein interface- HttpMessageWriter<Object>
- Parameters:
- input- the objects to write
- elementType- the type of objects in the stream which must have been previously checked via- HttpMessageWriter.canWrite(ResolvableType, MediaType)
- mediaType- the content type for the write (possibly- nullto indicate that the default content type of the writer must be used)
- message- the message to write to
- hints- additional information about how to encode and write
- Returns:
- indicates completion or error
 
- 
writepublic reactor.core.publisher.Mono<Void> write(Publisher<?> input, ResolvableType actualType, ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> hints) Description copied from interface:HttpMessageWriterServer-side only alternative toHttpMessageWriter.write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)with additional context available.- Specified by:
- writein interface- HttpMessageWriter<Object>
- actualType- the actual return type of the method that returned the value; for annotated controllers, the- MethodParametercan be accessed via- ResolvableType.getSource().
- elementType- the type of Objects in the input stream
- mediaType- the content type to use (possibly- nullindicating the default content type of the writer should be used)
- request- the current request
- response- the current response
- Returns:
- a Monothat indicates completion of writing or error
 
 
-