Package com.ibm.wsspi.rest.handler
Interface RESTResponse
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.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddResponseHeader(String key, String value) Adds a response header with the given key and value.This method provides access to write to the outstream of the corresponding REST response.Get the roles that would sufficient to perform the operation.intGets the current status code of this response.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.voidSends an error response using the specified status code and error message.voidsetCharacterEncoding(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(String contentType) Sets the content type of the response being sent to the client.voidsetRequiredRoles(Set<String> requiredRoles) Set the roles that would sufficient to perform the request if it were to be repeated.voidsetResponseHeader(String key, String value) Sets a response header with the given key and value.voidsetStatus(int statusCode) Sets the response status code.
-
Method Details
-
getWriter
This 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:
IOException- if an I/O exception occurred.
-
getOutputStream
This 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:
IOException- if an I/O exception occurred.
-
setResponseHeader
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
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
Sends 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:
IOException- if an I/O exception occurred.
-
sendError
Sends 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:
IOException- if an I/O exception occurred.
-
setContentType
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
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
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
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.
-