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 Type
    Method
    Description
    void
    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.
    int
    Gets the current status code of this response.
    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, String msg)
    Sends an error response using the specified status code and error message.
    void
    Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.
    void
    Sets the length of the content body in the response.
    void
    setContentType(String contentType)
    Sets the content type of the response being sent to the client.
    void
    setRequiredRoles(Set<String> requiredRoles)
    Set the roles that would sufficient to perform the request if it were to be repeated.
    void
    Sets a response header with the given key and value.
    void
    setStatus(int statusCode)
    Sets the response status code.
  • Method Details

    • getWriter

      Writer getWriter() throws IOException
      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

      OutputStream getOutputStream() throws IOException
      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

      void setResponseHeader(String key, 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(String key, 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 IOException
      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

      void sendError(int statusCode, String msg) throws IOException
      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 code
      msg - the error message
      Throws:
      IOException - if an I/O exception occurred.
    • setContentType

      void setContentType(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(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(Set<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

      Set<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 null if there are none.