Class Request
java.lang.Object
org.apache.coyote.Request
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
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaction(ActionCode actionCode, Object param) Perform an action on this request.voidaddPathParameter(String name, String value) Add a path parameter.voidClear the request thread ID.Return the content type.Return the decoded request URI.intdoRead(ApplicationBufferHandler handler) Read data from the input buffer and put it into ApplicationBufferHandler.getAttribute(String name) Return the value of the specified attribute.Return the request attributes map.Return the authentication type.intReturn the number of available bytes.longReturn the number of bytes read.Deprecated.Unused.Deprecated.Unused.Return the charset holder.intReturn the content length.longReturn the content length as a long.Return the content type as a string.Return the server cookies.Get the Exception that occurred during the writing of the response.Return the value of the specified header.Return the input buffer.intReturn the local port.Return the HTTP method.Return the MIME headers.Return the MIME trailer fields.getNote(int pos) Return the note at the specified position.Return the request parameters.getPathParameter(String name) Return the value of the specified path parameter.Return the protocol request ID.Return the read listener.intReturn the remote port.Return the remote user.booleanCheck if the remote user needs authorization.Return the request ID.Return the request processor info.Return the associated response.booleanCheck if sendfile is enabled.intReturn the server port.Return the servlet connection.Return the request start instant.longReturn the request start time in milliseconds.longReturn the request start time in nanoseconds.booleanCheck if relative redirects are supported.longReturn the thread ID.Return the trailer fields as a map.Return the URL decoder.booleanCheck if there is an expectation.booleanCheck if an error exception is present.booleanCheck if the request body has been fully read.booleanCheck if the request is currently being processed.booleanisReady()Check if the request is ready for reading.booleanCheck if the current thread is the request thread.booleanCheck if trailer fields are ready.Return the local address.Return the local name.voidMark the request start time.method()Deprecated.voidCalled when data is available for reading.peerAddr()Return the peer address.protocol()Return the protocol.Return the query string.voidrecycle()Recycle this request for reuse.Return the remote address.Return the remote host.Return the request URI.scheme()Return the scheme (e.g.booleanSend the all-data-read event.Get the "virtual host", derived from the Host: header associated with this request.voidsetAttribute(String name, Object o) Set an attribute.voidsetAvailable(int available) Set the number of available bytes.voidsetCharset(Charset charset) Deprecated.Unused.voidsetCharsetHolder(CharsetHolder charsetHolder) Set the charset holder.voidsetContentLength(long len) Set the content length.voidsetContentType(String type) Set the content type.voidSet the content type.voidSet the error Exception that occurred during the writing of the response processing.voidsetExpectation(boolean expectation) Set the expectation flag.voidsetInputBuffer(InputBuffer inputBuffer) Set the input buffer.voidsetLocalPort(int port) Set the local port.voidsetMethod(byte[] buf, int start, int len) Set the HTTP method from a byte buffer.voidSet the HTTP method.voidUsed to store private data.voidsetReadListener(ReadListener listener) Set the read listener for non-blocking reads.voidsetRemotePort(int port) Set the remote port.voidsetRemoteUserNeedsAuthorization(boolean remoteUserNeedsAuthorization) Set whether the remote user needs authorization.voidSet the request thread ID.voidsetResponse(Response response) Set the associated response.voidsetSendfile(boolean sendfile) Set whether sendfile is enabled.voidsetServerPort(int serverPort) Set the server port.voidsetStartTimeNanos(long startTimeNanos) Deprecated.Unused.toString()voidUpdate request counters.
-
Field Details
-
NOTE_BAD_REQUEST
public static final int NOTE_BAD_REQUESTNote key for bad request.- See Also:
-
-
Constructor Details
-
Request
public Request()Default constructor.
-
-
Method Details
-
getReadListener
-
setReadListener
Set the read listener for non-blocking reads.- Parameters:
listener- the read listener
-
isReady
public boolean isReady()Check if the request is ready for reading.- Returns:
trueif ready for reading
-
onDataAvailable
Called when data is available for reading.- Throws:
IOException- if an I/O error occurs
-
sendAllDataReadEvent
public boolean sendAllDataReadEvent()Send the all-data-read event.- Returns:
trueif the event was sent
-
getMimeHeaders
-
isTrailerFieldsReady
public boolean isTrailerFieldsReady()Check if trailer fields are ready.- Returns:
trueif trailer fields are ready
-
getTrailerFields
-
getMimeTrailerFields
Return the MIME trailer fields.- Returns:
- the MIME trailer fields
-
getURLDecoder
-
scheme
-
method
Deprecated.Get a MessageBytes instance that holds the current request's HTTP method.- Returns:
- a MessageBytes instance that holds the current request's HTTP method.
-
setMethod
-
setMethod
public void setMethod(byte[] buf, int start, int len) Set the HTTP method from a byte buffer.- Parameters:
buf- the byte bufferstart- the start offsetlen- the length
-
getMethod
-
requestURI
-
decodedURI
-
queryString
-
protocol
-
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()Return the server port.- Returns:
- the server port
-
setServerPort
public void setServerPort(int serverPort) Set the server port.- Parameters:
serverPort- the server port
-
remoteAddr
-
peerAddr
-
remoteHost
-
localName
-
localAddr
-
getRemotePort
public int getRemotePort()Return the remote port.- Returns:
- the remote port
-
setRemotePort
public void setRemotePort(int port) Set the remote port.- Parameters:
port- the remote port
-
getLocalPort
public int getLocalPort()Return the local port.- Returns:
- the local port
-
setLocalPort
public void setLocalPort(int port) Set the local port.- Parameters:
port- the local port
-
getCharacterEncoding
Deprecated.Unused. This method will be removed in Tomcat 12.Get the character encoding used for this request.- Returns:
- The value set via
setCharset(Charset)or if no call has been made to that method try to obtain if from the content type.
-
getCharset
Deprecated.Unused. This method will be removed in Tomcat 12.Get the character encoding used for this request.- Returns:
- The value set via
setCharset(Charset)or if no call has been made to that method try to obtain if from the content type. - Throws:
UnsupportedEncodingException- If the user agent has specified an invalid character encoding
-
setCharset
Deprecated.Unused. This method will be removed in Tomcat 12.Unused.- Parameters:
charset- The Charset to use for the request
-
getCharsetHolder
-
setCharsetHolder
Set the charset holder.- Parameters:
charsetHolder- the charset holder
-
setContentLength
public void setContentLength(long len) Set the content length.- Parameters:
len- the content length
-
getContentLength
public int getContentLength()Return the content length.- Returns:
- the content length
-
getContentLengthLong
public long getContentLengthLong()Return the content length as a long.- Returns:
- the content length
-
getContentType
-
setContentType
-
contentType
-
setContentType
-
getHeader
-
setExpectation
public void setExpectation(boolean expectation) Set the expectation flag.- Parameters:
expectation- the expectation flag
-
hasExpectation
public boolean hasExpectation()Check if there is an expectation.- Returns:
trueif there is an expectation
-
getResponse
-
setResponse
Set the associated response.- Parameters:
response- the response
-
action
Perform an action on this request.- Parameters:
actionCode- the action codeparam- the action parameter
-
getCookies
-
getParameters
-
addPathParameter
-
getPathParameter
-
setAttribute
-
getAttributes
-
getAttribute
-
getRemoteUser
-
getRemoteUserNeedsAuthorization
public boolean getRemoteUserNeedsAuthorization()Check if the remote user needs authorization.- Returns:
trueif the remote user needs authorization
-
setRemoteUserNeedsAuthorization
public void setRemoteUserNeedsAuthorization(boolean remoteUserNeedsAuthorization) Set whether the remote user needs authorization.- Parameters:
remoteUserNeedsAuthorization-trueif authorization is needed
-
getAuthType
-
getAvailable
public int getAvailable()Return the number of available bytes.- Returns:
- the available bytes
-
setAvailable
public void setAvailable(int available) Set the number of available bytes.- Parameters:
available- the available bytes
-
getSendfile
public boolean getSendfile()Check if sendfile is enabled.- Returns:
trueif sendfile is enabled
-
setSendfile
public void setSendfile(boolean sendfile) Set whether sendfile is enabled.- Parameters:
sendfile-trueto enable sendfile
-
isFinished
public boolean isFinished()Check if the request body has been fully read.- Returns:
trueif finished
-
getSupportsRelativeRedirects
public boolean getSupportsRelativeRedirects()Check if relative redirects are supported.- Returns:
trueif relative redirects are supported
-
getInputBuffer
-
setInputBuffer
Set the input buffer.- Parameters:
inputBuffer- the input buffer
-
doRead
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:
IOException- If an I/O error occurs during the copy
-
setErrorException
Set the error Exception that occurred during the writing of the response processing.- Parameters:
ex- The exception that occurred
-
getErrorException
Get the Exception that occurred during the writing of the response.- Returns:
- The exception that occurred
-
isExceptionPresent
public boolean isExceptionPresent()Check if an error exception is present.- Returns:
trueif an exception is present
-
getRequestId
-
getProtocolRequestId
Return the protocol request ID.- Returns:
- the protocol request ID
-
getServletConnection
Return the servlet connection.- Returns:
- the servlet connection
-
toString
-
getStartTime
public long getStartTime()Return the request start time in milliseconds.- Returns:
- the start time
-
getStartTimeNanos
public long getStartTimeNanos()Return the request start time in nanoseconds.- Returns:
- the start time in nanoseconds
-
setStartTimeNanos
Deprecated.Unused. Will be removed in Tomcat 12 onwards. UsemarkStartTime().Set the start time using the value provided bySystem.nanoTime().- Parameters:
startTimeNanos- The value returned fromSystem.nanoTime()at the point the requests started.
-
markStartTime
public void markStartTime()Mark the request start time. -
getStartInstant
-
getThreadId
public long getThreadId()Return the thread ID.- Returns:
- the thread ID
-
clearRequestThread
public void clearRequestThread()Clear the request thread ID. -
setRequestThread
public void setRequestThread()Set the request thread ID. -
isRequestThread
public boolean isRequestThread()Check if the current thread is the request thread.- Returns:
trueif the current thread is the request thread
-
setNote
Used to store private data. Thread data could be used instead - but if you have the req, getting/setting a note is just an 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 notevalue- The value to store at that index
-
getNote
Return the note at the specified position.- Parameters:
pos- the position- Returns:
- the note
-
recycle
public void recycle()Recycle this request for reuse. -
updateCounters
public void updateCounters()Update request counters. -
getRequestProcessor
Return the request processor info.- Returns:
- the request processor info
-
getBytesRead
public long getBytesRead()Return the number of bytes read.- Returns:
- the bytes read
-
isProcessing
public boolean isProcessing()Check if the request is currently being processed.- Returns:
trueif processing
-