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

      All Methods Instance Methods Abstract Methods 
      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.
    • Method Detail

      • getWriter

        java.io.Writer getWriter()
                          throws java.io.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:
        java.io.IOException - if an I/O exception occurred.
      • getOutputStream

        java.io.OutputStream getOutputStream()
                                      throws java.io.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:
        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.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:
        java.io.IOException - if an I/O exception occurred.
      • sendError

        void sendError(int statusCode,
                       java.lang.String msg)
                throws java.io.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:
        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)