Package org.apache.coyote

## Class Request

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

    public final class Request
    extends java.lang.Object

This is a low-level, efficient representation of a server request. Most fields are GC-free, expensive operations are delayed until the user code needs the information. Processing is delegated to modules, using a hook mechanism. This class is not intended for user code - it is used internally by tomcat for processing the request in the most efficient way. Users ( servlets ) can access the information using a facade, which provides the high-level view of the request. Tomcat defines a number of attributes:

- "org.apache.tomcat.request" - allows access to the low-level request object in trusted applications

Author:
  James Duncan Davidson [duncan@eng.sun.com], James Todd [gonzo@eng.sun.com], Jason Hunter [jch@eng.sun.com], Harish Prabandham, Alex Cruikshank [alex@epitonic.com], Hans Bergsten [hans@gefionsoftware.com], Costin Manolache, Remy Maucherat

### Constructor Summary

Constructors
`Request()`

### Method Summary

All Methods Instance Methods Concrete Methods Deprecated Methods
`void` `action​(ActionCode actionCode, java.lang.Object param)`
`void` `addPathParameter​(java.lang.String name, java.lang.String value)`
`void` `clearRequestThread()`
`MessageBytes` `contentType()`
`MessageBytes` `decodedURI()`
`int` `doRead​(ByteChunk chunk)` Deprecated. Unused.
`int` `doRead​(ApplicationBufferHandler handler)` Read data from the input buffer and put it into ApplicationBufferHandler.
`java.lang.Object` `getAttribute​(java.lang.String name)`
`java.util.HashMap<java.lang.String,​java.lang.Object>` `getAttributes()`
`MessageBytes` `getAuthType()`
`int` `getAvailable()`
`long` `getBytesRead()`
`java.lang.String` `getCharacterEncoding()` Get the character encoding used for this request.
`java.nio.charset.Charset` `getCharset()` Get the character encoding used for this request.
`int` `getContentLength()`
`long` `getContentLengthLong()`
`java.lang.String` `getContentType()`
`ServerCookies` `getCookies()`
`java.lang.Exception` `getErrorException()` Get the Exception that occurred during the writing of the response.
`java.lang.String` `getHeader​(java.lang.String name)`
`InputBuffer` `getInputBuffer()`
`int` `getLocalPort()`
`MimeHeaders` `getMimeHeaders()`
`java.lang.Object` `getNote​(int pos)`
`Parameters` `getParameters()`
`java.lang.String` `getPathParameter​(java.lang.String name)`
`ReadListener` `getReadListener()`
`int` `getRemotePort()`
`MessageBytes` `getRemoteUser()`
`boolean` `getRemoteUserNeedsAuthorization()`
`RequestInfo` `getRequestProcessor()`
`Response` `getResponse()`
`boolean` `getSendfile()`
`int` `getServerPort()`
`long` `getStartTime()`
`boolean` `getSupportsRelativeRedirects()`
`long` `getThreadId()`
`UDecoder` `getURLDecoder()`
`boolean` `hasExpectation()`
`boolean` `isExceptionPresent()`
`boolean` `isFinished()`
`boolean` `isProcessing()`
`boolean` `isReady()`
`boolean` `isRequestThread()`
`MessageBytes` `localAddr()`
`MessageBytes` `localName()`
`MessageBytes` `method()`
`void` `onDataAvailable()`
`MessageBytes` `peerAddr()`
`MessageBytes` `protocol()`
`MessageBytes` `queryString()`
`void` `recycle()`
`MessageBytes` `remoteAddr()`
`MessageBytes` `remoteHost()`
`MessageBytes` `requestURI()`
`MessageBytes` `scheme()`
`boolean` `sendAllDataReadEvent()`
`MessageBytes` `serverName()` Get the "virtual host", derived from the Host: header associated with this request.
`void` `setAttribute​(java.lang.String name, java.lang.Object o)`
`void` `setAvailable​(int available)`
`void` `setCharacterEncoding​(java.lang.String enc)` Deprecated. This method will be removed in Tomcat 9.0.x
`void` `setCharset​(java.nio.charset.Charset charset)`
`void` `setContentLength​(long len)`
`void` `setContentType​(java.lang.String type)`
`void` `setContentType​(MessageBytes mb)`
`void` `setErrorException​(java.lang.Exception ex)` Set the error Exception that occurred during the writing of the response processing.
`void` `setExpectation​(boolean expectation)`
`protected void` `setHook​(ActionHook hook)`
`void` `setInputBuffer​(InputBuffer inputBuffer)`
`void` `setLocalPort​(int port)`
`void` `setNote​(int pos, java.lang.Object value)` Used to store private data.
`void` `setReadListener​(ReadListener listener)`
`void` `setRemotePort​(int port)`
`void` `setRemoteUserNeedsAuthorization​(boolean remoteUserNeedsAuthorization)`
`void` `setRequestThread()`
`void` `setResponse​(Response response)`
`void` `setSendfile​(boolean sendfile)`
`void` `setServerPort​(int serverPort)`
`void` `setStartTime​(long startTime)`
`java.lang.String` `toString()`
`void` `updateCounters()`

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

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

### Constructor Detail

#### Request

    public Request()

### Method Detail

#### getReadListener

    public ReadListener getReadListener()

#### setReadListener

    public void setReadListener​(ReadListener listener)

#### isReady

    public boolean isReady()

#### onDataAvailable

    public void onDataAvailable()
                         throws java.io.IOException

Throws:
  `java.io.IOException`

#### sendAllDataReadEvent

    public boolean sendAllDataReadEvent()

#### getMimeHeaders

    public MimeHeaders getMimeHeaders()

#### getURLDecoder

    public UDecoder getURLDecoder()

#### scheme

    public MessageBytes scheme()

#### method

    public MessageBytes method()

#### requestURI

    public MessageBytes requestURI()

#### decodedURI

    public MessageBytes decodedURI()

#### queryString

    public MessageBytes queryString()

#### protocol

    public MessageBytes protocol()

#### serverName

    public MessageBytes serverName()

Get the "virtual host", derived from the Host: header associated with this request.

Returns:
  The buffer holding the server name, if any. Use isNull() to check if there is no value set.

#### getServerPort

    public int getServerPort()

#### setServerPort

    public void setServerPort​(int serverPort)

#### remoteAddr

    public MessageBytes remoteAddr()

#### peerAddr

    public MessageBytes peerAddr()

#### remoteHost

    public MessageBytes remoteHost()

#### localName

    public MessageBytes localName()

#### localAddr

    public MessageBytes localAddr()

#### getRemotePort

    public int getRemotePort()

#### setRemotePort

    public void setRemotePort​(int port)

#### getLocalPort

    public int getLocalPort()

#### setLocalPort

    public void setLocalPort​(int port)

#### getCharacterEncoding

    public java.lang.String getCharacterEncoding()

Get the character encoding used for this request.

Returns:
  The value set via `setCharacterEncoding(String)` or if no call has been made to that method try to obtain if from the content type.

#### getCharset

    public java.nio.charset.Charset getCharset()
                                        throws java.io.UnsupportedEncodingException

Get the character encoding used for this request.

Returns:
  The value set via `setCharacterEncoding(String)` or if no call has been made to that method try to obtain if from the content type.
Throws:
  `java.io.UnsupportedEncodingException` - If the user agent has specified an invalid character encoding

#### setCharacterEncoding

    @Deprecated
    public void setCharacterEncoding​(java.lang.String enc)
                              throws java.io.UnsupportedEncodingException

Deprecated.
This method will be removed in Tomcat 9.0.x

Parameters:
  `enc` - The new encoding
Throws:
  `java.io.UnsupportedEncodingException` - If the encoding is invalid

#### setCharset

    public void setCharset​(java.nio.charset.Charset charset)

#### setContentLength

    public void setContentLength​(long len)

#### getContentLength

    public int getContentLength()

#### getContentLengthLong

    public long getContentLengthLong()

#### getContentType

    public java.lang.String getContentType()

#### setContentType

    public void setContentType​(java.lang.String type)

#### contentType

    public MessageBytes contentType()

#### setContentType

    public void setContentType​(MessageBytes mb)

#### getHeader

    public java.lang.String getHeader​(java.lang.String name)

#### setExpectation

    public void setExpectation​(boolean expectation)

#### hasExpectation

    public boolean hasExpectation()

#### getResponse

    public Response getResponse()

#### setResponse

    public void setResponse​(Response response)

#### setHook

    protected void setHook​(ActionHook hook)

#### action

    public void action​(ActionCode actionCode,
                       java.lang.Object param)

#### getCookies

    public ServerCookies getCookies()

#### getParameters

    public Parameters getParameters()

#### addPathParameter

    public void addPathParameter​(java.lang.String name,
                                 java.lang.String value)

#### getPathParameter

    public java.lang.String getPathParameter​(java.lang.String name)

#### setAttribute

    public void setAttribute​(java.lang.String name,
                             java.lang.Object o)

#### getAttributes

    public java.util.HashMap<java.lang.String,​java.lang.Object> getAttributes()

#### getAttribute

    public java.lang.Object getAttribute​(java.lang.String name)

#### getRemoteUser

    public MessageBytes getRemoteUser()

#### getRemoteUserNeedsAuthorization

    public boolean getRemoteUserNeedsAuthorization()

#### setRemoteUserNeedsAuthorization

    public void setRemoteUserNeedsAuthorization​(boolean remoteUserNeedsAuthorization)

#### getAuthType

    public MessageBytes getAuthType()

#### getAvailable

    public int getAvailable()

#### setAvailable

    public void setAvailable​(int available)

#### getSendfile

    public boolean getSendfile()

#### setSendfile

    public void setSendfile​(boolean sendfile)

#### isFinished

    public boolean isFinished()

#### getSupportsRelativeRedirects

    public boolean getSupportsRelativeRedirects()

#### getInputBuffer

    public InputBuffer getInputBuffer()

#### setInputBuffer

    public void setInputBuffer​(InputBuffer inputBuffer)

#### doRead

    @Deprecated
    public int doRead​(ByteChunk chunk)
               throws java.io.IOException

Deprecated.
Unused. Will be removed in Tomcat 9. Use `doRead(ApplicationBufferHandler)`
Read data from the input buffer and put it into a byte chunk. The buffer is owned by the protocol implementation - it will be reused on the next read. The Adapter must either process the data in place or copy it to a separate buffer if it needs to hold it. In most cases this is done during byte->char conversions or via InputStream. Unlike InputStream, this interface allows the app to process data in place, without copy.

Parameters:
  `chunk` - The destination to which to copy the data
Returns:
  The number of bytes copied
Throws:
  `java.io.IOException` - If an I/O error occurs during the copy

#### doRead

    public int doRead​(ApplicationBufferHandler handler)
               throws java.io.IOException

Read data from the input buffer and put it into ApplicationBufferHandler. The buffer is owned by the protocol implementation - it will be reused on the next read. The Adapter must either process the data in place or copy it to a separate buffer if it needs to hold it. In most cases this is done during byte->char conversions or via InputStream. Unlike InputStream, this interface allows the app to process data in place, without copy.

Parameters:
  `handler` - The destination to which to copy the data
Returns:
  The number of bytes copied
Throws:
  `java.io.IOException` - If an I/O error occurs during the copy

#### setErrorException

    public void setErrorException​(java.lang.Exception ex)

Set the error Exception that occurred during the writing of the response processing.

Parameters:
  `ex` - The exception that occurred

#### getErrorException

    public java.lang.Exception getErrorException()

Get the Exception that occurred during the writing of the response.

Returns:
  The exception that occurred

#### isExceptionPresent

    public boolean isExceptionPresent()

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`

#### getStartTime

    public long getStartTime()

#### setStartTime

    public void setStartTime​(long startTime)

#### getThreadId

    public long getThreadId()

#### clearRequestThread

    public void clearRequestThread()

#### setRequestThread

    public void setRequestThread()

#### isRequestThread

    public boolean isRequestThread()

#### setNote

    public final void setNote​(int pos,
                              java.lang.Object value)

Used to store private data. Thread data could be used instead - but if you have the req, getting/setting a note is just a array access, may be faster than ThreadLocal for very frequent operations. Example use: Catalina CoyoteAdapter: ADAPTER_NOTES = 1 - stores the HttpServletRequest object ( req/res) To avoid conflicts, note in the range 0 - 8 are reserved for the servlet container ( catalina connector, etc ), and values in 9 - 16 for connector use. 17-31 range is not allocated or used.

Parameters:
  `pos` - Index to use to store the note
  `value` - The value to store at that index

#### getNote

    public final java.lang.Object getNote​(int pos)

#### recycle

    public void recycle()

#### updateCounters

    public void updateCounters()

#### getRequestProcessor

    public RequestInfo getRequestProcessor()

#### getBytesRead

    public long getBytesRead()

#### isProcessing

    public boolean isProcessing()