org.apache.coyote

## Class Response

- java.lang.Object
- - org.apache.coyote.Response

-     public final class Response
      extends Object

  Response object.
  Author:
    James Duncan Davidson [duncan@eng.sun.com], Jason Hunter [jch@eng.sun.com], James Todd [gonzo@eng.sun.com], Harish Prabandham, Hans Bergsten [hans@gefionsoftware.com], Remy Maucherat

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Response()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `action(ActionCode actionCode, Object param)`
    `void` | `addHeader(String name, String value)`
    `void` | `addHeader(String name, String value, Charset charset)`
    `boolean` | `checkRegisterForWrite()`
    `boolean` | `containsHeader(String name)` Does the response contain the given header.
    `void` | `doWrite(ByteBuffer chunk)` Write a chunk of bytes.
    `void` | `doWrite(ByteChunk chunk)` Deprecated. Unused. Will be removed in Tomcat 9. Use `doWrite(ByteBuffer)`
    `long` | `getBytesWritten(boolean flush)` Bytes written to socket - i.e. after compression, chunking, etc.
    `String` | `getCharacterEncoding()`
    `Charset` | `getCharset()`
    `long` | `getCommitTime()` Return the time the response was committed (based on System.currentTimeMillis).
    `String` | `getContentLanguage()` Return the content language.
    `int` | `getContentLength()`
    `long` | `getContentLengthLong()`
    `String` | `getContentType()`
    `long` | `getContentWritten()` Bytes written by application - i.e. before compression, chunking, etc.
    `Exception` | `getErrorException()` Get the Exception that occurred during request processing.
    `Locale` | `getLocale()`
    `String` | `getMessage()` Get the status message.
    `MimeHeaders` | `getMimeHeaders()`
    `Object` | `getNote(int pos)`
    `Request` | `getRequest()`
    `int` | `getStatus()`
    `WriteListener` | `getWriteListener()`
    `boolean` | `isCommitted()`
    `boolean` | `isError()` Error flag accessor.
    `boolean` | `isErrorReportRequired()`
    `boolean` | `isExceptionPresent()`
    `boolean` | `isReady()`
    `void` | `onWritePossible()`
    `void` | `recycle()`
    `void` | `reset()`
    `void` | `sendHeaders()` Signal that we're done with the headers, and body will follow.
    `void` | `setCharacterEncoding(String characterEncoding)` Overrides the character encoding used in the body of the response.
    `void` | `setCommitted(boolean v)`
    `void` | `setContentLength(long contentLength)`
    `void` | `setContentType(String type)` Sets the content type.
    `void` | `setContentTypeNoCharset(String type)`
    `boolean` | `setError()` Set the error flag.
    `void` | `setErrorException(Exception ex)` Set the error Exception that occurred during request processing.
    `boolean` | `setErrorReported()`
    `void` | `setHeader(String name, String value)`
    `protected void` | `setHook(ActionHook hook)`
    `void` | `setLocale(Locale locale)` Called explicitly by user to set the Content-Language and the default encoding.
    `void` | `setMessage(String message)` Set the status message.
    `void` | `setNote(int pos, Object value)`
    `void` | `setOutputBuffer(OutputBuffer outputBuffer)`
    `void` | `setRequest(Request req)`
    `void` | `setStatus(int status)` Set the response status.
    `void` | `setWriteListener(WriteListener listener)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Response

          public Response()

  - ### Method Detail

    - #### getRequest

          public Request getRequest()

    - #### setRequest

          public void setRequest(Request req)

    - #### setOutputBuffer

          public void setOutputBuffer(OutputBuffer outputBuffer)

    - #### getMimeHeaders

          public MimeHeaders getMimeHeaders()

    - #### setHook

          protected void setHook(ActionHook hook)

    - #### setNote

          public final void setNote(int pos,
                     Object value)

    - #### getNote

          public final Object getNote(int pos)

    - #### action

          public void action(ActionCode actionCode,
                    Object param)

    - #### getStatus

          public int getStatus()

    - #### setStatus

          public void setStatus(int status)

      Set the response status.
      Parameters:
        `status` - The status value to set

    - #### getMessage

          public String getMessage()

      Get the status message.
      Returns:
        The message associated with the current status

    - #### setMessage

          public void setMessage(String message)

      Set the status message.
      Parameters:
        `message` - The status message to set

    - #### isCommitted

          public boolean isCommitted()

    - #### setCommitted

          public void setCommitted(boolean v)

    - #### getCommitTime

          public long getCommitTime()

      Return the time the response was committed (based on System.currentTimeMillis).
      Returns:
        the time the response was committed

    - #### setErrorException

          public void setErrorException(Exception ex)

      Set the error Exception that occurred during request processing.
      Parameters:
        `ex` - The exception that occurred

    - #### getErrorException

          public Exception getErrorException()

      Get the Exception that occurred during request processing.
      Returns:
        The exception that occurred

    - #### isExceptionPresent

          public boolean isExceptionPresent()

    - #### setError

          public boolean setError()

      Set the error flag.
      Returns:
        `false` if the error flag was already set

    - #### isError

          public boolean isError()

      Error flag accessor.
      Returns:
        `true` if the response has encountered an error

    - #### isErrorReportRequired

          public boolean isErrorReportRequired()

    - #### setErrorReported

          public boolean setErrorReported()

    - #### reset

          public void reset()
                     throws IllegalStateException

      Throws:
        `IllegalStateException`

    - #### containsHeader

          public boolean containsHeader(String name)

      Does the response contain the given header.
      Warning: This method always returns `false` for Content-Type and Content-Length.
      Parameters:
        `name` - The name of the header of interest
      Returns:
        `true` if the response contains the header.

    - #### setHeader

          public void setHeader(String name,
                       String value)

    - #### addHeader

          public void addHeader(String name,
                       String value)

    - #### addHeader

          public void addHeader(String name,
                       String value,
                       Charset charset)

    - #### sendHeaders

          public void sendHeaders()

      Signal that we're done with the headers, and body will follow. Any implementation needs to notify ContextManager, to allow interceptors to fix headers.

    - #### getLocale

          public Locale getLocale()

    - #### setLocale

          public void setLocale(Locale locale)

      Called explicitly by user to set the Content-Language and the default encoding.
      Parameters:
        `locale` - The locale to use for this response

    - #### getContentLanguage

          public String getContentLanguage()

      Return the content language.
      Returns:
        The language code for the language currently associated with this response

    - #### setCharacterEncoding

          public void setCharacterEncoding(String characterEncoding)

      Overrides the character encoding used in the body of the response. This method must be called prior to writing output using getWriter().
      Parameters:
        `characterEncoding` - The name of character encoding.

    - #### getCharacterEncoding

          public String getCharacterEncoding()

      Returns:
        The name of the current encoding

    - #### getCharset

          public Charset getCharset()

    - #### setContentType

          public void setContentType(String type)

      Sets the content type. This method must preserve any response charset that may already have been set via a call to response.setContentType(), response.setLocale(), or response.setCharacterEncoding().
      Parameters:
        `type` - the content type

    - #### setContentTypeNoCharset

          public void setContentTypeNoCharset(String type)

    - #### getContentType

          public String getContentType()

    - #### setContentLength

          public void setContentLength(long contentLength)

    - #### getContentLength

          public int getContentLength()

    - #### getContentLengthLong

          public long getContentLengthLong()

    - #### doWrite

          @Deprecated
          public void doWrite(ByteChunk chunk)
                       throws IOException

      Deprecated. Unused. Will be removed in Tomcat 9. Use `doWrite(ByteBuffer)`
      Write a chunk of bytes.
      Parameters:
        `chunk` - The bytes to write
      Throws:
        `IOException` - If an I/O error occurs during the write

    - #### doWrite

          public void doWrite(ByteBuffer chunk)
                       throws IOException

      Write a chunk of bytes.
      Parameters:
        `chunk` - The ByteBuffer to write
      Throws:
        `IOException` - If an I/O error occurs during the write

    - #### recycle

          public void recycle()

    - #### getContentWritten

          public long getContentWritten()

      Bytes written by application - i.e. before compression, chunking, etc.
      Returns:
        The total number of bytes written to the response by the application. This will not be the number of bytes written to the network which may be more or less than this value.

    - #### getBytesWritten

          public long getBytesWritten(boolean flush)

      Bytes written to socket - i.e. after compression, chunking, etc.
      Parameters:
        `flush` - Should any remaining bytes be flushed before returning the total? If `false` bytes remaining in the buffer will not be included in the returned value
      Returns:
        The total number of bytes written to the socket for this response

    - #### getWriteListener

          public WriteListener getWriteListener()

    - #### setWriteListener

          public void setWriteListener(WriteListener listener)

    - #### isReady

          public boolean isReady()

    - #### checkRegisterForWrite

          public boolean checkRegisterForWrite()

    - #### onWritePossible

          public void onWritePossible()
                               throws IOException

      Throws:
        `IOException`

Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.