Package org.springframework.http.codec
Class ServerSentEventHttpMessageWriter
- java.lang.Object
- org.springframework.http.codec.ServerSentEventHttpMessageWriter
- All Implemented Interfaces:
HttpMessageWriter<Object>
public class ServerSentEventHttpMessageWriter extends Object implements HttpMessageWriter<Object>
HttpMessageWriterfor"text/event-stream"responses.- Since:
- 5.0
- Author:
- Sebastien Deleuze, Arjen Poutsma, Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description ServerSentEventHttpMessageWriter()Constructor without anEncoder.ServerSentEventHttpMessageWriter(Encoder<?> encoder)Constructor with JSONEncoderfor encoding objects.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanWrite(ResolvableType elementType, MediaType mediaType)Whether the given object type is supported by this writer.Encoder<?>getEncoder()Return the configuredEncoder, if any.List<MediaType>getWritableMediaTypes()Return theMediaType's that this writer supports.reactor.core.publisher.Mono<Void>write(org.reactivestreams.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(org.reactivestreams.Publisher<?> input, ResolvableType elementType, MediaType mediaType, ReactiveHttpOutputMessage message, Map<String,Object> hints)Write an given stream of object to the output message.
Constructor Detail
ServerSentEventHttpMessageWriter
public ServerSentEventHttpMessageWriter()
Constructor without anEncoder. In this mode onlyStringis supported for event data to be encoded.
ServerSentEventHttpMessageWriter
public ServerSentEventHttpMessageWriter(@Nullable Encoder<?> encoder)
Constructor with JSONEncoderfor encoding objects. Support forStringevent data is built-in.- Parameters:
encoder- the Encoder to use (may benull)
Method Detail
getEncoder
@Nullable public Encoder<?> getEncoder()
Return the configuredEncoder, if any.
getWritableMediaTypes
public List<MediaType> getWritableMediaTypes()
Description copied from interface:HttpMessageWriterReturn theMediaType's that this writer supports.- Specified by:
getWritableMediaTypesin interfaceHttpMessageWriter<Object>
canWrite
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType)
Description copied from interface:HttpMessageWriterWhether the given object type is supported by this writer.- Specified by:
canWritein interfaceHttpMessageWriter<Object>- Parameters:
elementType- the type of object to checkmediaType- the media type for the write (possiblynull)- Returns:
trueif writable,falseotherwise
write
public reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<?> input, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String,Object> hints)
Description copied from interface:HttpMessageWriterWrite an given stream of object to the output message.- Specified by:
writein interfaceHttpMessageWriter<Object>- Parameters:
input- the objects to writeelementType- the type of objects in the stream which must have been previously checked viaHttpMessageWriter.canWrite(ResolvableType, MediaType)mediaType- the content type for the write (possiblynullto 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 write- Returns:
- indicates completion or error
write
public reactor.core.publisher.Mono<Void> write(org.reactivestreams.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 interfaceHttpMessageWriter<Object>actualType- the actual return type of the method that returned the value; for annotated controllers, theMethodParametercan be accessed viaResolvableType.getSource().elementType- the type of Objects in the input streammediaType- the content type to use (possiblynullindicating the default content type of the writer should be used)request- the current requestresponse- the current response- Returns:
- a
Monothat indicates completion of writing or error