public interface RESTResponse
This interface encapsulates the artifacts pertaining to an HTTP response.
Implementations of this interface are not guaranteed to be thread safe, and live only until the corresponding
RESTHandler.handleRequest(RESTRequest, RESTResponse)
method returns.
Modifier and Type | Method and Description |
---|---|
void |
addResponseHeader(java.lang.String key,
java.lang.String value)
Adds a response header with the given key and value.
|
java.io.OutputStream |
getOutputStream()
This method provides access to write to the outstream of the corresponding REST response.
|
java.io.Writer |
getWriter()
This method provides access to write the outbound body of the corresponding REST response.
|
void |
sendError(int statusCode)
Sends an error response using the specified status code.
|
void |
sendError(int statusCode,
java.lang.String msg)
Sends an error response using the specified status code and error message.
|
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.
|
void |
setContentLength(int len)
Sets the length of the content body in the response.
|
void |
setContentType(java.lang.String contentType)
Sets the content type of the response being sent to the client.
|
void |
setResponseHeader(java.lang.String key,
java.lang.String value)
Sets a response header with the given key and value.
|
void |
setStatus(int statusCode)
Sets the response status code.
|
java.io.Writer getWriter() throws java.io.IOException
java.io.IOException
- if an I/O exception occurred.java.io.OutputStream getOutputStream() throws java.io.IOException
java.io.IOException
- if an I/O exception occurred.void setResponseHeader(java.lang.String key, java.lang.String value)
key
- of the header.value
- of the header.void addResponseHeader(java.lang.String key, java.lang.String value)
key
- of the header.value
- of the header.void setStatus(int statusCode)
statusCode
- the HTTP status codevoid sendError(int statusCode) throws java.io.IOException
statusCode
- the HTTP status codejava.io.IOException
- if an I/O exception occurred.void sendError(int statusCode, java.lang.String msg) throws java.io.IOException
statusCode
- the HTTP status codemsg
- the error messagejava.io.IOException
- if an I/O exception occurred.void setContentType(java.lang.String contentType)
contentType
- a String specifying the MIME type of the content.void setContentLength(int len)
len
- an integer specifying the length of the content being returned to the client.void setCharacterEncoding(java.lang.String charset)
charset
- a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets)