Top Description Fields Constructors Methods
org.apache.coyote

public final Class Request

extends Object
Class Inheritance
Imports
java.io.IOException, .StringReader, .UnsupportedEncodingException, java.nio.charset.Charset, java.util.HashMap, .Map, java.util.concurrent.TimeUnit, java.util.concurrent.atomic.AtomicBoolean, .AtomicLong, .AtomicReference, jakarta.servlet.ReadListener, .ServletConnection, org.apache.tomcat.util.buf.B2CConverter, .MessageBytes, .UDecoder, org.apache.tomcat.util.http.MimeHeaders, .Parameters, .ServerCookies, org.apache.tomcat.util.http.parser.MediaType, org.apache.tomcat.util.net.ApplicationBufferHandler, org.apache.tomcat.util.res.StringManager

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:
Authors
James Duncan Davidson [[email protected]], James Todd [[email protected]], Jason Hunter [[email protected]], Harish Prabandham, Alex Cruikshank [[email protected]], Hans Bergsten [[email protected]], Costin Manolache, Remy Maucherat

Field Summary

Modifier and TypeField and Description
private final AtomicBoolean
private final HashMap<String, Object>
private final MessageBytes
private int
private long
private String
private Charset
private long
contentLength

HTTP specific fields.

private MessageBytes
private final MessageBytes
private Exception
errorException

Holds request body reading error exception.

private boolean
expectation

Is there an expectation ?

private boolean
private final MimeHeaders
private volatile ActionHook
private InputBuffer
inputBuffer

Associated input buffer.

pack-priv volatile ReadListener
private final MessageBytes
private final MessageBytes
private int
private final MessageBytes
private final Object
private final Object[]
notes

Notes.

private final Parameters
private final Map<String, String>
pathParameters

Path parameters

private final MessageBytes
private final MessageBytes
private final MessageBytes
private boolean
private final MessageBytes
private final MessageBytes
private int
private final MessageBytes
private boolean
private final RequestInfo
private volatile String
private static final AtomicLong
private Response
private final MessageBytes
private boolean
private final ServerCookies
private final MessageBytes
private int
private static final StringManager
private long
private long
private final Map<String, String>
private final MessageBytes
private final UDecoder
urlDecoder

URL decoder.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
action(ActionCode actionCode, Object param)

public void
private boolean
public void
public MessageBytes
public MessageBytes
public int

Returns:

The number of bytes copied
doRead
(ApplicationBufferHandler
The destination to which to copy the data
handler
)

Read data from the input buffer and put it into ApplicationBufferHandler.

public Object
public HashMap<String, Object>
public MessageBytes
public int
public long
public String

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.
getCharacterEncoding
()

Get the character encoding used for this request.

public Charset

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
()

Get the character encoding used for this request.

private static String
getCharsetFromContentType(String
a content type header
contentType
)

Parse the character encoding from the specified content type header.

public int
public long
public String
public ServerCookies
public Exception

Returns:

The exception that occurred
getErrorException
()

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

public String
public InputBuffer
public int
public MimeHeaders
public Object
getNote(int pos)

public Parameters
public String
public String
public ReadListener
public int
public MessageBytes
public boolean
public String
public RequestInfo
public Response
public boolean
public int
public ServletConnection
public long
public long
public boolean
public long
public Map<String, String>
public UDecoder
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public MessageBytes
public MessageBytes
public MessageBytes
public void
public MessageBytes
public MessageBytes
public MessageBytes
public void
public MessageBytes
public MessageBytes
public MessageBytes
public MessageBytes
public boolean
public MessageBytes

Returns:

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

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

public void
public void
setAvailable(int available)

public void
public void
setContentLength(long len)

public void
public void
public void
setErrorException(Exception
The exception that occurred
ex
)

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

public void
setExpectation(boolean expectation)

protected void
public void
public void
setLocalPort(int port)

public void
setNote(int
Index to use to store the note
pos
,
Object
The value to store at that index
value
)

Used to store private data.

public void
public void
setRemotePort(int port)

public void
setRemoteUserNeedsAuthorization(boolean remoteUserNeedsAuthorization)

public void
public void
public void
setSendfile(boolean sendfile)

public void
setServerPort(int serverPort)

public void
setStartTime(long
time
startTime
)
Deprecated This setter will be removed in Tomcat 11

public void
setStartTimeNanos(long startTimeNanos)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

allDataReadEventSentback to summary
private final AtomicBoolean allDataReadEventSent
attributesback to summary
private final HashMap<String, Object> attributes
authTypeback to summary
private final MessageBytes authType
availableback to summary
private int available
bytesReadback to summary
private long bytesRead
characterEncodingback to summary
private String characterEncoding
charsetback to summary
private Charset charset
contentLengthback to summary
private long contentLength

HTTP specific fields. (remove them ?)

contentTypeMBback to summary
private MessageBytes contentTypeMB
decodedUriMBback to summary
private final MessageBytes decodedUriMB
errorExceptionback to summary
private Exception errorException

Holds request body reading error exception.

expectationback to summary
private boolean expectation

Is there an expectation ?

fireListenerback to summary
private boolean fireListener
headersback to summary
private final MimeHeaders headers
hookback to summary
private volatile ActionHook hook
inputBufferback to summary
private InputBuffer inputBuffer

Associated input buffer.

listenerback to summary
pack-priv volatile ReadListener listener
localAddrMBback to summary
private final MessageBytes localAddrMB
localNameMBback to summary
private final MessageBytes localNameMB
localPortback to summary
private int localPort
methodMBback to summary
private final MessageBytes methodMB
nonBlockingStateLockback to summary
private final Object nonBlockingStateLock
notesback to summary
private final Object[] notes

Notes.

parametersback to summary
private final Parameters parameters
pathParametersback to summary
private final Map<String, String> pathParameters

Path parameters

peerAddrMBback to summary
private final MessageBytes peerAddrMB
protoMBback to summary
private final MessageBytes protoMB
queryMBback to summary
private final MessageBytes queryMB
registeredForReadback to summary
private boolean registeredForRead
remoteAddrMBback to summary
private final MessageBytes remoteAddrMB
remoteHostMBback to summary
private final MessageBytes remoteHostMB
remotePortback to summary
private int remotePort
remoteUserback to summary
private final MessageBytes remoteUser
remoteUserNeedsAuthorizationback to summary
private boolean remoteUserNeedsAuthorization
reqProcessorMXback to summary
private final RequestInfo reqProcessorMX
requestIdback to summary
private volatile String requestId
requestIdGeneratorback to summary
private static final AtomicLong requestIdGenerator
responseback to summary
private Response response
schemeMBback to summary
private final MessageBytes schemeMB
sendfileback to summary
private boolean sendfile
serverCookiesback to summary
private final ServerCookies serverCookies
serverNameMBback to summary
private final MessageBytes serverNameMB
serverPortback to summary
private int serverPort
smback to summary
private static final StringManager sm
startTimeNanosback to summary
private long startTimeNanos
threadIdback to summary
private long threadId
trailerFieldsback to summary
private final Map<String, String> trailerFields
uriMBback to summary
private final MessageBytes uriMB
urlDecoderback to summary
private final UDecoder urlDecoder

URL decoder.

Constructor Detail

Requestback to summary
public Request()

Method Detail

actionback to summary
public void action(ActionCode actionCode, Object param)
addPathParameterback to summary
public void addPathParameter(String name, String value)
checkRegisterForReadback to summary
private boolean checkRegisterForRead()
clearRequestThreadback to summary
public void clearRequestThread()
contentTypeback to summary
public MessageBytes contentType()
decodedURIback to summary
public MessageBytes decodedURI()
doReadback to summary
public int doRead(ApplicationBufferHandler handler) throws 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:ApplicationBufferHandler

The destination to which to copy the data

Returns:int

The number of bytes copied

Exceptions
IOException:
If an I/O error occurs during the copy
getAttributeback to summary
public Object getAttribute(String name)
getAttributesback to summary
public HashMap<String, Object> getAttributes()
getAuthTypeback to summary
public MessageBytes getAuthType()
getAvailableback to summary
public int getAvailable()
getBytesReadback to summary
public long getBytesRead()
getCharacterEncodingback to summary
public String getCharacterEncoding()

Get the character encoding used for this request.

Returns:String

The value set via setCharset(Charset) or if no call has been made to that method try to obtain if from the content type.

getCharsetback to summary
public Charset getCharset() throws UnsupportedEncodingException

Get the character encoding used for this request.

Returns:Charset

The value set via setCharset(Charset) or if no call has been made to that method try to obtain if from the content type.

Exceptions
UnsupportedEncodingException:
If the user agent has specified an invalid character encoding
getCharsetFromContentTypeback to summary
private static String getCharsetFromContentType(String contentType)

Parse the character encoding from the specified content type header. If the content type is null, or there is no explicit character encoding, null is returned.

Parameters
contentType:String

a content type header

getContentLengthback to summary
public int getContentLength()
getContentLengthLongback to summary
public long getContentLengthLong()
getContentTypeback to summary
public String getContentType()
getCookiesback to summary
public ServerCookies getCookies()
getErrorExceptionback to summary
public Exception getErrorException()

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

Returns:Exception

The exception that occurred

getHeaderback to summary
public String getHeader(String name)
getInputBufferback to summary
public InputBuffer getInputBuffer()
getLocalPortback to summary
public int getLocalPort()
getMimeHeadersback to summary
public MimeHeaders getMimeHeaders()
getNoteback to summary
public Object getNote(int pos)
getParametersback to summary
public Parameters getParameters()
getPathParameterback to summary
public String getPathParameter(String name)
getProtocolRequestIdback to summary
public String getProtocolRequestId()
getReadListenerback to summary
public ReadListener getReadListener()
getRemotePortback to summary
public int getRemotePort()
getRemoteUserback to summary
public MessageBytes getRemoteUser()
getRemoteUserNeedsAuthorizationback to summary
public boolean getRemoteUserNeedsAuthorization()
getRequestIdback to summary
public String getRequestId()
getRequestProcessorback to summary
public RequestInfo getRequestProcessor()
getResponseback to summary
public Response getResponse()
getSendfileback to summary
public boolean getSendfile()
getServerPortback to summary
public int getServerPort()
getServletConnectionback to summary
public ServletConnection getServletConnection()
getStartTimeback to summary
public long getStartTime()
getStartTimeNanosback to summary
public long getStartTimeNanos()
getSupportsRelativeRedirectsback to summary
public boolean getSupportsRelativeRedirects()
getThreadIdback to summary
public long getThreadId()
getTrailerFieldsback to summary
public Map<String, String> getTrailerFields()
getURLDecoderback to summary
public UDecoder getURLDecoder()
hasExpectationback to summary
public boolean hasExpectation()
isExceptionPresentback to summary
public boolean isExceptionPresent()
isFinishedback to summary
public boolean isFinished()
isProcessingback to summary
public boolean isProcessing()
isReadyback to summary
public boolean isReady()
isRequestThreadback to summary
public boolean isRequestThread()
isTrailerFieldsReadyback to summary
public boolean isTrailerFieldsReady()
localAddrback to summary
public MessageBytes localAddr()
localNameback to summary
public MessageBytes localName()
methodback to summary
public MessageBytes method()
onDataAvailableback to summary
public void onDataAvailable() throws IOException
peerAddrback to summary
public MessageBytes peerAddr()
protocolback to summary
public MessageBytes protocol()
queryStringback to summary
public MessageBytes queryString()
recycleback to summary
public void recycle()
remoteAddrback to summary
public MessageBytes remoteAddr()
remoteHostback to summary
public MessageBytes remoteHost()
requestURIback to summary
public MessageBytes requestURI()
schemeback to summary
public MessageBytes scheme()
sendAllDataReadEventback to summary
public boolean sendAllDataReadEvent()
serverNameback to summary
public MessageBytes serverName()

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

Returns:MessageBytes

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

setAttributeback to summary
public void setAttribute(String name, Object o)
setAvailableback to summary
public void setAvailable(int available)
setCharsetback to summary
public void setCharset(Charset charset)
setContentLengthback to summary
public void setContentLength(long len)
setContentTypeback to summary
public void setContentType(String type)
setContentTypeback to summary
public void setContentType(MessageBytes mb)
setErrorExceptionback to summary
public void setErrorException(Exception ex)

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

Parameters
ex:Exception

The exception that occurred

setExpectationback to summary
public void setExpectation(boolean expectation)
setHookback to summary
protected void setHook(ActionHook hook)
setInputBufferback to summary
public void setInputBuffer(InputBuffer inputBuffer)
setLocalPortback to summary
public void setLocalPort(int port)
setNoteback to summary
public void setNote(int pos, 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 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:int

Index to use to store the note

value:Object

The value to store at that index

setReadListenerback to summary
public void setReadListener(ReadListener listener)
setRemotePortback to summary
public void setRemotePort(int port)
setRemoteUserNeedsAuthorizationback to summary
public void setRemoteUserNeedsAuthorization(boolean remoteUserNeedsAuthorization)
setRequestThreadback to summary
public void setRequestThread()
setResponseback to summary
public void setResponse(Response response)
setSendfileback to summary
public void setSendfile(boolean sendfile)
setServerPortback to summary
public void setServerPort(int serverPort)
setStartTimeback to summary
public void setStartTime(long startTime)

Deprecated

This setter will be removed in Tomcat 11

Parameters
startTime:long

time

Annotations
@Deprecated
setStartTimeNanosback to summary
public void setStartTimeNanos(long startTimeNanos)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
updateCountersback to summary
public void updateCounters()