public class ServerSentEventHttpMessageWriter extends Object implements HttpMessageWriter<Object>
HttpMessageWriter for "text/event-stream" responses.| Constructor and Description |
|---|
ServerSentEventHttpMessageWriter()
Constructor without an
Encoder. |
ServerSentEventHttpMessageWriter(org.springframework.core.codec.Encoder<?> encoder)
Constructor with JSON
Encoder for encoding objects. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canWrite(org.springframework.core.ResolvableType elementType,
MediaType mediaType)
Whether the given object type is supported by this writer.
|
org.springframework.core.codec.Encoder<?> |
getEncoder()
Return the configured
Encoder, if any. |
List<MediaType> |
getWritableMediaTypes()
Return the list of media types supported by this Writer.
|
reactor.core.publisher.Mono<Void> |
write(Publisher<?> input,
org.springframework.core.ResolvableType elementType,
MediaType mediaType,
ReactiveHttpOutputMessage message,
Map<String,Object> hints)
Write a given stream of object to the output message.
|
reactor.core.publisher.Mono<Void> |
write(Publisher<?> input,
org.springframework.core.ResolvableType actualType,
org.springframework.core.ResolvableType elementType,
MediaType mediaType,
ServerHttpRequest request,
ServerHttpResponse response,
Map<String,Object> hints)
Server-side only alternative to
HttpMessageWriter.write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)
with additional context available. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetWritableMediaTypespublic ServerSentEventHttpMessageWriter()
Encoder. In this mode only String
is supported for event data to be encoded.public ServerSentEventHttpMessageWriter(@Nullable
org.springframework.core.codec.Encoder<?> encoder)
Encoder for encoding objects.
Support for String event data is built-in.encoder - the Encoder to use (may be null)@Nullable public org.springframework.core.codec.Encoder<?> getEncoder()
Encoder, if any.public List<MediaType> getWritableMediaTypes()
HttpMessageWritercanWrite(elementType, null). The list may also exclude media types
supported only for a specific element type. Alternatively, use
HttpMessageWriter.getWritableMediaTypes(ResolvableType) for a more precise list.getWritableMediaTypes in interface HttpMessageWriter<Object>public boolean canWrite(org.springframework.core.ResolvableType elementType,
@Nullable
MediaType mediaType)
HttpMessageWritercanWrite in interface HttpMessageWriter<Object>elementType - the type of object to checkmediaType - the media type for the write (possibly null)true if writable, false otherwisepublic reactor.core.publisher.Mono<Void> write(Publisher<?> input, org.springframework.core.ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String,Object> hints)
HttpMessageWriterwrite in interface HttpMessageWriter<Object>input - the objects to writeelementType - 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 null to
indicate that the default content type of the writer must be used)message - the message to write tohints - additional information about how to encode and writepublic reactor.core.publisher.Mono<Void> write(Publisher<?> input, org.springframework.core.ResolvableType actualType, org.springframework.core.ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response, Map<String,Object> hints)
HttpMessageWriterHttpMessageWriter.write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)
with additional context available.write in interface HttpMessageWriter<Object>actualType - the actual return type of the method that returned the
value; for annotated controllers, the MethodParameter can be
accessed via ResolvableType.getSource().elementType - the type of Objects in the input streammediaType - the content type to use (possibly null indicating
the default content type of the writer should be used)request - the current requestresponse - the current responseMono that indicates completion of writing or error