org.springframework.http.codec

Class ServerSentEventHttpMessageReader

  • java.lang.Object
    • org.springframework.http.codec.ServerSentEventHttpMessageReader
  • All Implemented Interfaces:
    HttpMessageReader<java.lang.Object>


    public class ServerSentEventHttpMessageReader
    extends java.lang.Object
    implements HttpMessageReader<java.lang.Object>
    Reader that supports a stream of ServerSentEvents and also plain Objects which is the same as an ServerSentEvent with data only.
    Since:
    5.0
    Author:
    Sebastien Deleuze, Rossen Stoyanchev
    • Constructor Detail

      • ServerSentEventHttpMessageReader

        public ServerSentEventHttpMessageReader()
        Constructor without a Decoder. In this mode only String is supported as the data of an event.
      • ServerSentEventHttpMessageReader

        public ServerSentEventHttpMessageReader(@Nullable
                                                Decoder<?> decoder)
        Constructor with JSON Decoder for decoding to Objects. Support for decoding to String event data is built-in.
    • Method Detail

      • getDecoder

        @Nullable
        public Decoder<?> getDecoder()
        Return the configured Decoder.
      • 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 interface HttpMessageReader<java.lang.Object>
        Parameters:
        elementType - the type of object to check
        mediaType - the media type for the read (possibly null)
        Returns:
        true if readable, false otherwise
      • read

        public reactor.core.publisher.Flux<java.lang.Object> read(ResolvableType elementType,
                                                                  ReactiveHttpInputMessage message,
                                                                  java.util.Map<java.lang.String,java.lang.Object> hints)
        Description copied from interface: HttpMessageReader
        Read from the input message and encode to a stream of objects.
        Specified by:
        read in interface HttpMessageReader<java.lang.Object>
        Parameters:
        elementType - the type of objects in the stream which must have been previously checked via HttpMessageReader.canRead(ResolvableType, MediaType)
        message - the message to read from
        hints - additional information about how to read and decode the input
        Returns:
        the decoded stream of elements
      • readMono

        public reactor.core.publisher.Mono<java.lang.Object> readMono(ResolvableType elementType,
                                                                      ReactiveHttpInputMessage message,
                                                                      java.util.Map<java.lang.String,java.lang.Object> hints)
        Description copied from interface: HttpMessageReader
        Read from the input message and encode to a single object.
        Specified by:
        readMono in interface HttpMessageReader<java.lang.Object>
        Parameters:
        elementType - the type of objects in the stream which must have been previously checked via HttpMessageReader.canRead(ResolvableType, MediaType)
        message - the message to read from
        hints - additional information about how to read and decode the input
        Returns:
        the decoded object