Package com.ibm.wsspi.rest.handler
Interface RESTResponse
-
public interface RESTResponseThis 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.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddResponseHeader(java.lang.String key, java.lang.String value)Adds a response header with the given key and value.java.io.OutputStreamgetOutputStream()This method provides access to write to the outstream of the corresponding REST response.java.util.Set<java.lang.String>getRequiredRoles()Get the roles that would sufficient to perform the operation.intgetStatus()Gets the current status code of this response.java.io.WritergetWriter()This method provides access to write the outbound body of the corresponding REST response.voidsendError(int statusCode)Sends an error response using the specified status code.voidsendError(int statusCode, java.lang.String msg)Sends an error response using the specified status code and error message.voidsetCharacterEncoding(java.lang.String charset)Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.voidsetContentLength(int len)Sets the length of the content body in the response.voidsetContentType(java.lang.String contentType)Sets the content type of the response being sent to the client.voidsetRequiredRoles(java.util.Set<java.lang.String> requiredRoles)Set the roles that would sufficient to perform the request if it were to be repeated.voidsetResponseHeader(java.lang.String key, java.lang.String value)Sets a response header with the given key and value.voidsetStatus(int statusCode)Sets the response status code.
-
-
-
Method Detail
-
getWriter
java.io.Writer getWriter() throws java.io.IOExceptionThis method provides access to write the outbound body of the corresponding REST response. Either this method or getOutputStream() may be called to write the body, not both- Returns:
- a Writer over the outbound body.
- Throws:
java.io.IOException- if an I/O exception occurred.
-
getOutputStream
java.io.OutputStream getOutputStream() throws java.io.IOExceptionThis method provides access to write to the outstream of the corresponding REST response. Either this method or getWriter() may be called to write the body, not both- Returns:
- a OutputStream to the outbound Response OutputStream.
- Throws:
java.io.IOException- if an I/O exception occurred.
-
setResponseHeader
void setResponseHeader(java.lang.String key, java.lang.String value)Sets a response header with the given key and value. If a response header was already set with the key, the new value will override the old one.- Parameters:
key- of the header.value- of the header.
-
addResponseHeader
void addResponseHeader(java.lang.String key, java.lang.String value)Adds a response header with the given key and value. This method allows response headers to have multiple values.- Parameters:
key- of the header.value- of the header.
-
setStatus
void setStatus(int statusCode)
Sets the response status code.- Parameters:
statusCode- the HTTP status code
-
sendError
void sendError(int statusCode) throws java.io.IOExceptionSends an error response using the specified status code. This RESTResponse object should not be used after this method.- Parameters:
statusCode- the HTTP status code- Throws:
java.io.IOException- if an I/O exception occurred.
-
sendError
void sendError(int statusCode, java.lang.String msg) throws java.io.IOExceptionSends an error response using the specified status code and error message. This RESTResponse object should not be used after this method.- Parameters:
statusCode- the HTTP status codemsg- the error message- Throws:
java.io.IOException- if an I/O exception occurred.
-
setContentType
void setContentType(java.lang.String contentType)
Sets the content type of the response being sent to the client.- Parameters:
contentType- a String specifying the MIME type of the content.
-
setContentLength
void setContentLength(int len)
Sets the length of the content body in the response.- Parameters:
len- an integer specifying the length of the content being returned to the client.
-
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.- Parameters:
charset- a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets)
-
getStatus
int getStatus()
Gets the current status code of this response.- Returns:
- the current status code of this response.
-
setRequiredRoles
void setRequiredRoles(java.util.Set<java.lang.String> requiredRoles)
Set the roles that would sufficient to perform the request if it were to be repeated. Typically, these values are only set when a 403 FORBIDDEN is being returned. This method is intended for auditing purposes.- Parameters:
requiredRoles- The roles that would be sufficient to perform the request.
-
getRequiredRoles
java.util.Set<java.lang.String> getRequiredRoles()
Get the roles that would sufficient to perform the operation. Typically, these values are only set when a 403 FORBIDDEN is being returned. This method is intended for auditing purposes.- Returns:
- The roles that would be sufficient to perform the operation or
nullif there are none.
-
-