Class ServletServerHttpResponse

java.lang.Object
org.springframework.http.server.ServletServerHttpResponse
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, HttpMessage, HttpOutputMessage, ServerHttpResponse

public class ServletServerHttpResponse extends Object implements ServerHttpResponse
ServerHttpResponse implementation that is based on a HttpServletResponse.
Since:
3.0
Author:
Arjen Poutsma, Rossen Stoyanchev, Brian Clozel
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    System property that indicates whether response.getBody().flush() should effectively flush to the network.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ServletServerHttpResponse(jakarta.servlet.http.HttpServletResponse servletResponse)
    Construct a new instance of the ServletServerHttpResponse based on the given HttpServletResponse.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close this response, freeing any resources created.
    void
    Ensure that the headers and the content of the response are written out.
    Return the body of the message as an output stream.
    Return the headers of this message.
    jakarta.servlet.http.HttpServletResponse
    Return the HttpServletResponse this object is based on.
    void
    Set the HTTP status code of the response.

    Methods inherited from class Object

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

    • FLUSH_ENABLED_PROPERTY_NAME

      public static final String FLUSH_ENABLED_PROPERTY_NAME
      System property that indicates whether response.getBody().flush() should effectively flush to the network. This is by default disabled, and developers must set the "spring.http.response.flush.enabled" Spring property to turn it on.

      Applications should instead flush() on the response directly.

      Since:
      7.0.6
      See Also:
  • Constructor Details

    • ServletServerHttpResponse

      public ServletServerHttpResponse(jakarta.servlet.http.HttpServletResponse servletResponse)
      Construct a new instance of the ServletServerHttpResponse based on the given HttpServletResponse.
      Parameters:
      servletResponse - the servlet response
  • Method Details

    • getServletResponse

      public jakarta.servlet.http.HttpServletResponse getServletResponse()
      Return the HttpServletResponse this object is based on.
    • setStatusCode

      public void setStatusCode(HttpStatusCode 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
    • 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)
    • getBody

      public OutputStream getBody() throws IOException
      Return the body of the message as an output stream.

      By default, flushing the output stream has no effect (see FLUSH_ENABLED_PROPERTY_NAME) and should be performed using the ServerHttpResponse-level flush() method instead.

      Specified by:
      getBody in interface HttpOutputMessage
      Returns:
      the output stream body (never null)
      Throws:
      IOException - in case of I/O errors
    • flush

      public void flush() throws IOException
      Description copied from interface: ServerHttpResponse
      Ensure that the headers and the content of the response are written out.

      After the first flush, headers can no longer be changed. Only further content writing and content flushing is possible.

      Specified by:
      flush in interface Flushable
      Specified by:
      flush in interface ServerHttpResponse
      Throws:
      IOException
    • close

      public void close()
      Description copied from interface: ServerHttpResponse
      Close this response, freeing any resources created.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface ServerHttpResponse