public class ServerSentEventHttpMessageWriter extends java.lang.Object implements HttpMessageWriter<java.lang.Object>
HttpMessageWriter
for "text/event-stream"
responses.Modifier and Type | Field and Description |
---|---|
private static MediaType |
DEFAULT_MEDIA_TYPE |
private Encoder<?> |
encoder |
private static java.util.List<MediaType> |
WRITABLE_MEDIA_TYPES |
Constructor and Description |
---|
ServerSentEventHttpMessageWriter()
Constructor without an
Encoder . |
ServerSentEventHttpMessageWriter(Encoder<?> encoder)
Constructor with JSON
Encoder for encoding objects. |
Modifier and Type | Method and Description |
---|---|
boolean |
canWrite(ResolvableType elementType,
MediaType mediaType)
Whether the given object type is supported by this writer.
|
private <any> |
encode(<any> input,
ResolvableType elementType,
MediaType mediaType,
DataBufferFactory factory,
java.util.Map<java.lang.String,java.lang.Object> hints) |
private <T> <any> |
encodeData(T dataValue,
ResolvableType valueType,
MediaType mediaType,
DataBufferFactory factory,
java.util.Map<java.lang.String,java.lang.Object> hints) |
private <any> |
encodeText(java.lang.CharSequence text,
MediaType mediaType,
DataBufferFactory bufferFactory) |
private java.util.Map<java.lang.String,java.lang.Object> |
getEncodeHints(ResolvableType actualType,
ResolvableType elementType,
MediaType mediaType,
ServerHttpRequest request,
ServerHttpResponse response) |
Encoder<?> |
getEncoder()
Return the configured
Encoder , if any. |
java.util.List<MediaType> |
getWritableMediaTypes()
Return the
MediaType 's that this writer supports. |
<any> |
write(<any> input,
ResolvableType elementType,
MediaType mediaType,
ReactiveHttpOutputMessage message,
java.util.Map<java.lang.String,java.lang.Object> hints)
Write an given stream of object to the output message.
|
<any> |
write(<any> input,
ResolvableType actualType,
ResolvableType elementType,
MediaType mediaType,
ServerHttpRequest request,
ServerHttpResponse response,
java.util.Map<java.lang.String,java.lang.Object> hints)
Server-side only alternative to
#write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)
with additional context available. |
private void |
writeField(java.lang.String fieldName,
java.lang.Object fieldValue,
java.lang.StringBuilder sb) |
private static final MediaType DEFAULT_MEDIA_TYPE
private static final java.util.List<MediaType> WRITABLE_MEDIA_TYPES
public ServerSentEventHttpMessageWriter()
Encoder
. In this mode only String
is supported for event data to be encoded.public java.util.List<MediaType> getWritableMediaTypes()
HttpMessageWriter
MediaType
's that this writer supports.getWritableMediaTypes
in interface HttpMessageWriter<java.lang.Object>
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType)
HttpMessageWriter
canWrite
in interface HttpMessageWriter<java.lang.Object>
elementType
- the type of object to checkmediaType
- the media type for the write, possibly null
true
if writable, false
otherwisepublic <any> write(<any> input, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, java.util.Map<java.lang.String,java.lang.Object> hints)
HttpMessageWriter
write
in interface HttpMessageWriter<java.lang.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 writeprivate <any> encode(<any> input, ResolvableType elementType, MediaType mediaType, DataBufferFactory factory, java.util.Map<java.lang.String,java.lang.Object> hints)
private void writeField(java.lang.String fieldName, java.lang.Object fieldValue, java.lang.StringBuilder sb)
private <T> <any> encodeData(@Nullable T dataValue, ResolvableType valueType, MediaType mediaType, DataBufferFactory factory, java.util.Map<java.lang.String,java.lang.Object> hints)
private <any> encodeText(java.lang.CharSequence text, MediaType mediaType, DataBufferFactory bufferFactory)
public <any> write(<any> input, ResolvableType actualType, ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response, java.util.Map<java.lang.String,java.lang.Object> hints)
HttpMessageWriter
#write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)
with additional context available.write
in interface HttpMessageWriter<java.lang.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 errorprivate java.util.Map<java.lang.String,java.lang.Object> getEncodeHints(ResolvableType actualType, ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response)