Package org.sonar.api.server.http
Interface HttpResponse
-
public interface HttpResponseFramework-agnostic definition of an HTTP response.- Since:
- 9.16
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddCookie(Cookie cookie)Adds the specified cookie to the response.voidaddHeader(java.lang.String name, java.lang.String value)Adds a response header with the given name and value.java.lang.StringgetHeader(java.lang.String name)Gets the value of the response header with the given name.java.util.Collection<java.lang.String>getHeaders(java.lang.String name)Gets the values of the response header with the given name.java.io.OutputStreamgetOutputStream()Returns aOutputStreamsuitable for writing binary data in the response.intgetStatus()Gets the current status code of this response.java.io.PrintWritergetWriter()Returns aPrintWriterobject that can send character text to the client.voidsendRedirect(java.lang.String location)Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer.voidsetCharacterEncoding(java.lang.String charset)Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.voidsetContentType(java.lang.String contentType)Sets the content type of the response being sent to the client, if the response has not been committed yet.voidsetHeader(java.lang.String name, java.lang.String value)Sets a response header with the given name and value.voidsetStatus(int sc)Sets the status code for this response.
-
-
-
Method Detail
-
addHeader
void addHeader(java.lang.String name, java.lang.String value)Adds a response header with the given name and value. This method allows response headers to have multiple values.
-
getHeader
java.lang.String getHeader(java.lang.String name)
Gets the value of the response header with the given name. If a response header with the given name exists and contains multiple values, the value that was added first will be returned.
-
getHeaders
java.util.Collection<java.lang.String> getHeaders(java.lang.String name)
Gets the values of the response header with the given name.
-
setStatus
void setStatus(int sc)
Sets the status code for this response.
-
getStatus
int getStatus()
Gets the current status code of this response.
-
setContentType
void setContentType(java.lang.String contentType)
Sets the content type of the response being sent to the client, if the response has not been committed yet.
-
getWriter
java.io.PrintWriter getWriter() throws java.io.IOExceptionReturns aPrintWriterobject that can send character text to the client. Calling flush() on thePrintWritercommits the response.- Throws:
java.io.IOException
-
setHeader
void setHeader(java.lang.String name, java.lang.String value)Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one.
-
sendRedirect
void sendRedirect(java.lang.String location) throws java.io.IOExceptionSends a temporary redirect response to the client using the specified redirect location URL and clears the buffer. The buffer will be replaced with the data set by this method.- Throws:
java.io.IOException
-
addCookie
void addCookie(Cookie cookie)
Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.
-
getOutputStream
java.io.OutputStream getOutputStream() throws java.io.IOExceptionReturns aOutputStreamsuitable for writing binary data in the response. The servlet container does not encode the binary data. Either this method orgetWriter()may be called to write the body, not both.- Throws:
java.io.IOException
-
setCharacterEncoding
void setCharacterEncoding(java.lang.String charset)
Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.
-
-