org.springframework.http.server.reactive

Class AbstractServerHttpResponse

  • java.lang.Object
    • org.springframework.http.server.reactive.AbstractServerHttpResponse
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected Log logger 
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method and Description
      void addCookie(ResponseCookie cookie)
      Add the given ResponseCookie.
      protected abstract void applyCookies()
      Add cookies from getHeaders() to the underlying response.
      protected abstract void applyHeaders()
      Apply header changes from getHeaders() to the underlying response.
      protected abstract void applyStatusCode()
      Write the status code to the underlying response.
      void beforeCommit(java.util.function.Supplier<? extends reactor.core.publisher.Mono<java.lang.Void>> action)
      Register an action to apply just before the HttpOutputMessage is committed.
      DataBufferFactory bufferFactory()
      Return a DataBufferFactory that can be used to create the body.
      protected reactor.core.publisher.Mono<java.lang.Void> doCommit()
      A variant of doCommit(Supplier) for a response without no body.
      protected reactor.core.publisher.Mono<java.lang.Void> doCommit(java.util.function.Supplier<? extends reactor.core.publisher.Mono<java.lang.Void>> writeAction)
      Apply beforeCommit actions, apply the response status and headers/cookies, and write the response body.
      MultiValueMap<java.lang.String,ResponseCookie> getCookies()
      Return a mutable map with the cookies to send to the server.
      HttpHeaders getHeaders()
      Return the headers of this message.
      abstract <T> T getNativeResponse()
      Return the underlying server response.
      HttpStatus getStatusCode()
      Return the HTTP status code or null if not set.
      java.lang.Integer getStatusCodeValue()
      Return the HTTP status code of the response.
      boolean isCommitted()
      Whether the HttpOutputMessage is committed.
      reactor.core.publisher.Mono<java.lang.Void> setComplete()
      Indicate that message handling is complete, allowing for any cleanup or end-of-processing tasks to be performed such as applying header changes made via HttpMessage.getHeaders() to the underlying HTTP message (if not applied already).
      boolean setStatusCode(HttpStatus status)
      Set the HTTP status code of the response.
      void setStatusCodeValue(java.lang.Integer statusCode)
      Set the HTTP status code of the response.
      reactor.core.publisher.Mono<java.lang.Void> writeAndFlushWith(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
      Use the given Publisher of Publishers to write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after each Publisher<DataBuffer>.
      protected abstract reactor.core.publisher.Mono<java.lang.Void> writeAndFlushWithInternal(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
      Write to the underlying the response, and flush after each Publisher<DataBuffer>.
      reactor.core.publisher.Mono<java.lang.Void> writeWith(org.reactivestreams.Publisher<? extends DataBuffer> body)
      Use the given Publisher to write the body of the message to the underlying HTTP layer.
      protected abstract reactor.core.publisher.Mono<java.lang.Void> writeWithInternal(org.reactivestreams.Publisher<? extends DataBuffer> body)
      Write to the underlying the response.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        protected final Log logger
    • Constructor Detail

      • AbstractServerHttpResponse

        public AbstractServerHttpResponse(DataBufferFactory dataBufferFactory)
    • Method Detail

      • setStatusCode

        public boolean setStatusCode(@Nullable
                                     HttpStatus status)
        Description copied from interface: ServerHttpResponse
        Set the HTTP status code of the response.
        Specified by:
        setStatusCode in interface ServerHttpResponse
        Parameters:
        status - the HTTP status as an HttpStatus enum value
        Returns:
        false if the status code has not been set because the HTTP response is already committed, true if it has been set correctly.
      • setStatusCodeValue

        public void setStatusCodeValue(@Nullable
                                       java.lang.Integer statusCode)
        Set the HTTP status code of the response.
        Parameters:
        statusCode - the HTTP status as an integer value
        Since:
        5.0.1
      • getStatusCodeValue

        @Nullable
        public java.lang.Integer getStatusCodeValue()
        Return the HTTP status code of the response.
        Returns:
        the HTTP status as an integer value
        Since:
        5.0.1
      • getHeaders

        public HttpHeaders getHeaders()
        Description copied from interface: HttpMessage
        Return the headers of this message.
        Specified by:
        getHeaders in interface HttpMessage
        Returns:
        a corresponding HttpHeaders object (never null)
      • getNativeResponse

        public abstract <T> T getNativeResponse()
        Return the underlying server response.

        Note: This is exposed mainly for internal framework use such as WebSocket upgrades in the spring-webflux module.

      • beforeCommit

        public void beforeCommit(java.util.function.Supplier<? extends reactor.core.publisher.Mono<java.lang.Void>> action)
        Description copied from interface: ReactiveHttpOutputMessage
        Register an action to apply just before the HttpOutputMessage is committed.

        Note: the supplied action must be properly deferred, e.g. via Mono.defer(java.util.function.Supplier<? extends reactor.core.publisher.Mono<? extends T>>) or Mono.fromRunnable(java.lang.Runnable), to ensure it's executed in the right order, relative to other actions.

        Specified by:
        beforeCommit in interface ReactiveHttpOutputMessage
        Parameters:
        action - the action to apply
      • writeWith

        public final reactor.core.publisher.Mono<java.lang.Void> writeWith(org.reactivestreams.Publisher<? extends DataBuffer> body)
        Description copied from interface: ReactiveHttpOutputMessage
        Use the given Publisher to write the body of the message to the underlying HTTP layer.
        Specified by:
        writeWith in interface ReactiveHttpOutputMessage
        Parameters:
        body - the body content publisher
        Returns:
        a Mono that indicates completion or error
      • writeAndFlushWith

        public final reactor.core.publisher.Mono<java.lang.Void> writeAndFlushWith(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
        Description copied from interface: ReactiveHttpOutputMessage
        Use the given Publisher of Publishers to write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after each Publisher<DataBuffer>.
        Specified by:
        writeAndFlushWith in interface ReactiveHttpOutputMessage
        Parameters:
        body - the body content publisher
        Returns:
        a Mono that indicates completion or error
      • setComplete

        public reactor.core.publisher.Mono<java.lang.Void> setComplete()
        Description copied from interface: ReactiveHttpOutputMessage
        Indicate that message handling is complete, allowing for any cleanup or end-of-processing tasks to be performed such as applying header changes made via HttpMessage.getHeaders() to the underlying HTTP message (if not applied already).

        This method should be automatically invoked at the end of message processing so typically applications should not have to invoke it. If invoked multiple times it should have no side effects.

        Specified by:
        setComplete in interface ReactiveHttpOutputMessage
        Returns:
        a Mono that indicates completion or error
      • doCommit

        protected reactor.core.publisher.Mono<java.lang.Void> doCommit()
        A variant of doCommit(Supplier) for a response without no body.
        Returns:
        a completion publisher
      • doCommit

        protected reactor.core.publisher.Mono<java.lang.Void> doCommit(@Nullable
                                                                       java.util.function.Supplier<? extends reactor.core.publisher.Mono<java.lang.Void>> writeAction)
        Apply beforeCommit actions, apply the response status and headers/cookies, and write the response body.
        Parameters:
        writeAction - the action to write the response body (may be null)
        Returns:
        a completion publisher
      • writeWithInternal

        protected abstract reactor.core.publisher.Mono<java.lang.Void> writeWithInternal(org.reactivestreams.Publisher<? extends DataBuffer> body)
        Write to the underlying the response.
        Parameters:
        body - the publisher to write with
      • writeAndFlushWithInternal

        protected abstract reactor.core.publisher.Mono<java.lang.Void> writeAndFlushWithInternal(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
        Write to the underlying the response, and flush after each Publisher<DataBuffer>.
        Parameters:
        body - the publisher to write and flush with
      • applyStatusCode

        protected abstract void applyStatusCode()
        Write the status code to the underlying response. This method is called once only.
      • applyHeaders

        protected abstract void applyHeaders()
        Apply header changes from getHeaders() to the underlying response. This method is called once only.
      • applyCookies

        protected abstract void applyCookies()
        Add cookies from getHeaders() to the underlying response. This method is called once only.