Package org.springframework.http.server
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
ServerHttpResponseimplementation that is based on aHttpServletResponse.- Since:
- 3.0
- Author:
- Arjen Poutsma, Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description ServletServerHttpResponse(HttpServletResponse servletResponse)Construct a new instance of the ServletServerHttpResponse based on the givenHttpServletResponse.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close this response, freeing any resources created.voidflush()Ensure that the headers and the content of the response are written out.OutputStreamgetBody()Return the body of the message as an output stream.HttpHeadersgetHeaders()Return the headers of this message.HttpServletResponsegetServletResponse()Return theHttpServletResponsethis object is based on.voidsetStatusCode(HttpStatus status)Set the HTTP status code of the response.
Constructor Detail
ServletServerHttpResponse
public ServletServerHttpResponse(HttpServletResponse servletResponse)
Construct a new instance of the ServletServerHttpResponse based on the givenHttpServletResponse.- Parameters:
servletResponse- the servlet response
Method Detail
getServletResponse
public HttpServletResponse getServletResponse()
Return theHttpServletResponsethis object is based on.
setStatusCode
public void setStatusCode(HttpStatus status)
Description copied from interface:ServerHttpResponseSet the HTTP status code of the response.- Specified by:
setStatusCodein interfaceServerHttpResponse- Parameters:
status- the HTTP status as an HttpStatus enum value
getHeaders
public HttpHeaders getHeaders()
Description copied from interface:HttpMessageReturn the headers of this message.- Specified by:
getHeadersin interfaceHttpMessage- Returns:
- a corresponding HttpHeaders object (never
null)
getBody
public OutputStream getBody() throws IOException
Description copied from interface:HttpOutputMessageReturn the body of the message as an output stream.- Specified by:
getBodyin interfaceHttpOutputMessage- 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:ServerHttpResponseEnsure 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:
flushin interfaceFlushable- Specified by:
flushin interfaceServerHttpResponse- Throws:
IOException
close
public void close()
Description copied from interface:ServerHttpResponseClose this response, freeing any resources created.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceServerHttpResponse