Class ResponseTemplate

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addHeader​(java.lang.String name, java.lang.String value)
      Add the given single header value to the current list of values for the given header.
      void commit​(Activity activity)
      The result of the activity is processed into a specific response form and then sent to the client.
      boolean containsHeader​(java.lang.String name)
      Returns a boolean indicating whether the named response header has already been set.
      void flush()
      Forces any content in the buffer to be written to the client.
      <T> T getAdaptee()
      Returns the adaptee object to provide response information.
      java.lang.String getContentType()
      Gets the content type.
      java.lang.String getEncoding()
      Returns the name of the character encoding (MIME charset) used for the body sent in this response.
      java.lang.String getHeader​(java.lang.String name)
      Returns the value of the response header with the given name.
      java.util.Collection<java.lang.String> getHeaderNames()
      Returns the names of the headers of this response.
      java.util.Collection<java.lang.String> getHeaders​(java.lang.String name)
      Returns the values of the response header with the given name.
      java.io.OutputStream getOutputStream()
      Returns a OutputStream suitable for writing binary data in the response.
      ResponseType getResponseType()
      Gets the response type.
      int getStatus()
      Returns the status code.
      java.io.Writer getWriter()
      Returns a Writer object that can send character text to the client.
      java.lang.String redirect​(RedirectRule redirectRule)
      Redirects a client to a new URL.
      void redirect​(java.lang.String location)
      Sends a temporary redirect response to the client using the specified redirect location.
      Response replicate()
      Replicates and returns this response.
      void setContentType​(java.lang.String contentType)
      Sets the content type of the response being sent to the client, if the response has not been committed yet.
      void setEncoding​(java.lang.String encoding)
      Sets the character encoding of the response being sent to the client.
      void setHeader​(java.lang.String name, java.lang.String value)
      Set the given single header value under the given header name.
      void setStatus​(int status)
      Sets the status code.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • commit

        public void commit​(Activity activity)
                    throws ResponseException
        Description copied from interface: Response
        The result of the activity is processed into a specific response form and then sent to the client.
        Specified by:
        commit in interface Response
        Parameters:
        activity - the current Activity
        Throws:
        ResponseException - the response exception
      • getAdaptee

        public <T> T getAdaptee()
        Description copied from interface: ResponseAdapter
        Returns the adaptee object to provide response information.
        Specified by:
        getAdaptee in interface ResponseAdapter
        Type Parameters:
        T - the type of the adaptee object
        Returns:
        the adaptee object
      • getHeader

        public java.lang.String getHeader​(java.lang.String name)
        Description copied from interface: ResponseAdapter
        Returns the value of the response header with the given name.

        If a response header with the given name exists and contains multiple values, the value that was added first will be returned.

        Specified by:
        getHeader in interface ResponseAdapter
        Parameters:
        name - the name of the response header whose value to return
        Returns:
        the value of the response header with the given name, or null if no header with the given name has been set on this response
      • getHeaders

        public java.util.Collection<java.lang.String> getHeaders​(java.lang.String name)
        Description copied from interface: ResponseAdapter
        Returns the values of the response header with the given name.
        Specified by:
        getHeaders in interface ResponseAdapter
        Parameters:
        name - the name of the response header whose values to return
        Returns:
        a (possibly empty) Collection of the values of the response header with the given name
      • getHeaderNames

        public java.util.Collection<java.lang.String> getHeaderNames()
        Description copied from interface: ResponseAdapter
        Returns the names of the headers of this response.
        Specified by:
        getHeaderNames in interface ResponseAdapter
        Returns:
        a (possibly empty) Collection of the names of the headers of this response
      • containsHeader

        public boolean containsHeader​(java.lang.String name)
        Description copied from interface: ResponseAdapter
        Returns a boolean indicating whether the named response header has already been set.
        Specified by:
        containsHeader in interface ResponseAdapter
        Parameters:
        name - the header name
        Returns:
        true if the named response header has already been set; false otherwise
      • setHeader

        public void setHeader​(java.lang.String name,
                              java.lang.String value)
        Description copied from interface: ResponseAdapter
        Set the given single header value under the given header name. If the header had already been set, the new value overwrites the previous one.
        Specified by:
        setHeader in interface ResponseAdapter
        Parameters:
        name - the header name
        value - the header value to set
      • addHeader

        public void addHeader​(java.lang.String name,
                              java.lang.String value)
        Description copied from interface: ResponseAdapter
        Add the given single header value to the current list of values for the given header.
        Specified by:
        addHeader in interface ResponseAdapter
        Parameters:
        name - the header name
        value - the header value to be added
      • getEncoding

        public java.lang.String getEncoding()
        Description copied from interface: ResponseAdapter
        Returns the name of the character encoding (MIME charset) used for the body sent in this response.
        Specified by:
        getEncoding in interface ResponseAdapter
        Returns:
        a String specifying the name of the character encoding, for example, UTF-8
      • setEncoding

        public void setEncoding​(java.lang.String encoding)
                         throws java.io.UnsupportedEncodingException
        Description copied from interface: ResponseAdapter
        Sets the character encoding of the response being sent to the client.
        Specified by:
        setEncoding in interface ResponseAdapter
        Parameters:
        encoding - a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets)
        Throws:
        java.io.UnsupportedEncodingException - if character encoding is not supported
      • setContentType

        public void setContentType​(java.lang.String contentType)
        Description copied from interface: ResponseAdapter
        Sets the content type of the response being sent to the client, if the response has not been committed yet.
        Specified by:
        setContentType in interface ResponseAdapter
        Parameters:
        contentType - a String specifying the MIME type of the content
      • getOutputStream

        public java.io.OutputStream getOutputStream()
                                             throws java.io.IOException
        Description copied from interface: ResponseAdapter
        Returns a OutputStream suitable for writing binary data in the response.
        Specified by:
        getOutputStream in interface ResponseAdapter
        Returns:
        a OutputStream for writing binary data
        Throws:
        java.io.IOException - if an input or output exception occurs
      • getWriter

        public java.io.Writer getWriter()
                                 throws java.io.IOException
        Description copied from interface: ResponseAdapter
        Returns a Writer object that can send character text to the client.
        Specified by:
        getWriter in interface ResponseAdapter
        Returns:
        a Writer object that can return character data to the client
        Throws:
        java.io.IOException - if an input or output exception occurs
      • flush

        public void flush()
                   throws java.io.IOException
        Description copied from interface: ResponseAdapter
        Forces any content in the buffer to be written to the client.
        Specified by:
        flush in interface ResponseAdapter
        Throws:
        java.io.IOException - if an input or output exception occurs
      • redirect

        public void redirect​(java.lang.String location)
                      throws java.io.IOException
        Description copied from interface: ResponseAdapter
        Sends a temporary redirect response to the client using the specified redirect location.
        Specified by:
        redirect in interface ResponseAdapter
        Parameters:
        location - the redirect location
        Throws:
        java.io.IOException - if an input or output exception occurs
      • redirect

        public java.lang.String redirect​(RedirectRule redirectRule)
                                  throws java.io.IOException
        Description copied from interface: ResponseAdapter
        Redirects a client to a new URL.
        Specified by:
        redirect in interface ResponseAdapter
        Parameters:
        redirectRule - the redirect rule
        Returns:
        the redirect path
        Throws:
        java.io.IOException - if an input or output exception occurs
      • setStatus

        public void setStatus​(int status)
        Description copied from interface: ResponseAdapter
        Sets the status code.
        Specified by:
        setStatus in interface ResponseAdapter
        Parameters:
        status - the status code