Package org.springframework.http.codec
Class ServerSentEventHttpMessageReader
- java.lang.Object
- org.springframework.http.codec.ServerSentEventHttpMessageReader
- All Implemented Interfaces:
HttpMessageReader<Object>
public class ServerSentEventHttpMessageReader extends Object implements HttpMessageReader<Object>
Reader that supports a stream ofServerSentEvents
and also plainObjects
which is the same as anServerSentEvent
with data only.- Since:
- 5.0
- Author:
- Sebastien Deleuze, Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description ServerSentEventHttpMessageReader()
Constructor without aDecoder
.ServerSentEventHttpMessageReader(Decoder<?> decoder)
Constructor with JSONDecoder
for decoding to Objects.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canRead(ResolvableType elementType, MediaType mediaType)
Whether the given object type is supported by this reader.Decoder<?>
getDecoder()
Return the configuredDecoder
.int
getMaxInMemorySize()
Return theconfigured
byte count limit.List<MediaType>
getReadableMediaTypes()
Return theMediaType
's that this reader supports.reactor.core.publisher.Flux<Object>
read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
Read from the input message and encode to a stream of objects.reactor.core.publisher.Mono<Object>
readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
Read from the input message and encode to a single object.void
setMaxInMemorySize(int byteCount)
Configure a limit on the maximum number of bytes per SSE event which are buffered before the event is parsed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.http.codec.HttpMessageReader
read, readMono
Constructor Detail
ServerSentEventHttpMessageReader
public ServerSentEventHttpMessageReader()
Constructor without aDecoder
. In this mode onlyString
is supported as the data of an event.
ServerSentEventHttpMessageReader
public ServerSentEventHttpMessageReader(@Nullable Decoder<?> decoder)
Constructor with JSONDecoder
for decoding to Objects. Support for decoding toString
event data is built-in.
Method Detail
getDecoder
@Nullable public Decoder<?> getDecoder()
Return the configuredDecoder
.
setMaxInMemorySize
public void setMaxInMemorySize(int byteCount)
Configure a limit on the maximum number of bytes per SSE event which are buffered before the event is parsed.Note that the
data decoder
, if provided, must also be customized accordingly to raise the limit if necessary in order to be able to parse the data portion of the event.By default this is set to 256K.
- Parameters:
byteCount
- the max number of bytes to buffer, or -1 for unlimited- Since:
- 5.1.13
getMaxInMemorySize
public int getMaxInMemorySize()
Return theconfigured
byte count limit.- Since:
- 5.1.13
getReadableMediaTypes
public List<MediaType> getReadableMediaTypes()
Description copied from interface:HttpMessageReader
Return theMediaType
's that this reader supports.- Specified by:
getReadableMediaTypes
in interfaceHttpMessageReader<Object>
canRead
public boolean canRead(ResolvableType elementType, @Nullable MediaType mediaType)
Description copied from interface:HttpMessageReader
Whether the given object type is supported by this reader.- Specified by:
canRead
in interfaceHttpMessageReader<Object>
- Parameters:
elementType
- the type of object to checkmediaType
- the media type for the read (possiblynull
)- Returns:
true
if readable,false
otherwise
read
public reactor.core.publisher.Flux<Object> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
Description copied from interface:HttpMessageReader
Read from the input message and encode to a stream of objects.- Specified by:
read
in interfaceHttpMessageReader<Object>
- Parameters:
elementType
- the type of objects in the stream which must have been previously checked viaHttpMessageReader.canRead(ResolvableType, MediaType)
message
- the message to read fromhints
- additional information about how to read and decode the input- Returns:
- the decoded stream of elements
readMono
public reactor.core.publisher.Mono<Object> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
Description copied from interface:HttpMessageReader
Read from the input message and encode to a single object.- Specified by:
readMono
in interfaceHttpMessageReader<Object>
- Parameters:
elementType
- the type of objects in the stream which must have been previously checked viaHttpMessageReader.canRead(ResolvableType, MediaType)
message
- the message to read fromhints
- additional information about how to read and decode the input- Returns:
- the decoded object