Class AbstractProcessor
java.lang.Object
org.apache.coyote.AbstractProcessorLight
org.apache.coyote.AbstractProcessor
- All Implemented Interfaces:
ActionHook, Processor
- Direct Known Subclasses:
AjpProcessor, Http11Processor
Provides functionality and attributes common to all supported protocols (currently HTTP and AJP) for processing a
single request/response.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AdapterThe adapter for this processor.protected final org.apache.coyote.AsyncStateMachineState machine for async processing.protected final RequestThe request being processed.protected final ResponseThe response being processed.protected SocketWrapperBase<?> The socket wrapper for this processor.protected SSLSupportSSL support for this connection.protected final UserDataHelperUser data helper for logging. -
Constructor Summary
ConstructorsModifierConstructorDescriptionAbstractProcessor(Adapter adapter) Creates a new processor with the given adapter.protectedAbstractProcessor(Adapter adapter, Request coyoteRequest, Response coyoteResponse) Constructs a new processor with the given adapter, request, and response. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidack(ContinueResponseTiming continueResponseTiming) Process acknowledgment of the request.final voidaction(ActionCode actionCode, Object param) Send an action to the connector.Calls the post process of the async state machine.protected abstract intavailable(boolean doRead) Queries if bytes are available in buffers.booleanCheck to see if the async generation (each cycle of async increments the generation of the AsyncStateMachine) is the same as the generation when the most recent async timeout was triggered.protected abstract voidSwallowing bytes is required for pipelining requests, so this allows to avoid doing extra operations in case an error occurs and the connection is to be closed instead.dispatch(SocketEvent status) Process an in-progress request that is no longer in standard HTTP mode.protected abstract AbstractEndpoint.Handler.SocketStatePerform any necessary clean-up processing if the dispatch resulted in the completion of processing for the current request.protected voidPerform any necessary processing for a non-blocking read before dispatching to the adapter.protected voiddoHttpUpgrade(UpgradeToken upgradeToken) Process an HTTP upgrade.protected voidProcess a push.protected abstract voidProcess early hints (103 Early Hints).protected voidProvides a mechanism to trigger processing on a container thread.protected voidExecutes any pending non-blocking dispatches.protected abstract voidFinish the current response.protected abstract voidflush()Callback to write data from the buffer.protected abstract booleanFlush any pending writes.Get the associated adapter.longGets the async timeout.protected ErrorStateGets the current error state.Allows retrieving additional input during the upgrade process.protected booleanProcessors that populate request attributes directly (e.g.protected ObjectProtocols that provide per HTTP request IDs (e.g.Gets the request associated with this processor.protected abstract ServletConnectionProtocols must override this method and return an appropriate ServletConnection instanceprotected final SocketWrapperBase<?> Get the socket wrapper being used.Generate an upgrade token.booleanisAsync()Checks if the Processor is in async state.protected booleanProtocols that support push should override this method and returntrue.protected booleanChecks if the processor is ready for reading.protected abstract booleanChecks if the processor is ready for writing.protected abstract booleanChecks if the request body has been fully read.protected abstract booleanChecks if trailer fields are ready.protected booleanProtocols that support trailer fields should override this method and returntrue.booleanChecks if the Processor is processing an upgrade request.protected final voidlogAccess(SocketWrapperBase<?> socketWrapper) Add an entry to the access log for a failed connection attempt.protected voidparseHost(MessageBytes valueMB) Parses the Host header value and populates the server name and port.protected voidCalled when a host header is not present in the request (e.g.protected voidCalled when a host header is not present or is empty in the request (e.g.protected voidPopulate the remote host request attribute.protected voidPopulate the TLS related request attributes from theSSLSupportinstance associated with this processor.protected abstract voidWhen committing the response, we have to validate the set of headers, as well as set up the response filters.protected voidprocessSocketEvent(SocketEvent event, boolean dispatch) Processes a socket event.voidrecycle()Recycle the processor, ready for the next request which may be on the same connection or a different connection.protected abstract voidWhen using non blocking IO, register to get a callback when polling determines that bytes are available for reading.voidsetAsyncTimeout(long timeout) Sets the async timeout.protected voidsetErrorState(ErrorState errorState, Throwable t) Update the current error state to the new error state if the new error state is more severe than the current error state.protected abstract voidsetRequestBody(ByteChunk body) Set the specified byte chunk as the request body that will be read.protected voidsetSocketWrapper(SocketWrapperBase<?> socketWrapper) Set the socket wrapper being used.final voidsetSslSupport(SSLSupport sslSupport) Set the SSL information for this HTTP connection.protected abstract voidThe response is finished and no additional bytes need to be sent to the client.protected voidProcessors that can perform a TLS re-handshake (e.g.voidtimeoutAsync(long now) Check this processor to see if the timeout has expired and process a timeout if that is that case.Methods inherited from class AbstractProcessorLight
addDispatch, clearDispatches, getIteratorAndClearDispatches, getLog, process, service
-
Field Details
-
adapter
The adapter for this processor. -
asyncStateMachine
protected final org.apache.coyote.AsyncStateMachine asyncStateMachineState machine for async processing. -
request
The request being processed. -
response
The response being processed. -
socketWrapper
The socket wrapper for this processor. -
sslSupport
SSL support for this connection. -
userDataHelper
User data helper for logging.
-
-
Constructor Details
-
AbstractProcessor
Creates a new processor with the given adapter.- Parameters:
adapter- The adapter for this processor
-
AbstractProcessor
-
-
Method Details
-
setErrorState
Update the current error state to the new error state if the new error state is more severe than the current error state.- Parameters:
errorState- The error status detailst- The error which occurred
-
getErrorState
-
getRequest
Description copied from interface:ProcessorGets the request associated with this processor.- Specified by:
getRequestin interfaceProcessor- Returns:
- The request associated with this processor.
-
getAdapter
-
setSocketWrapper
Set the socket wrapper being used.- Parameters:
socketWrapper- The socket wrapper
-
getSocketWrapper
Get the socket wrapper being used.- Returns:
- the socket wrapper being used.
-
setSslSupport
Description copied from interface:ProcessorSet the SSL information for this HTTP connection.- Specified by:
setSslSupportin interfaceProcessor- Parameters:
sslSupport- The SSL support object to use for this connection
-
execute
Provides a mechanism to trigger processing on a container thread.- Parameters:
runnable- The task representing the processing that needs to take place on a container thread
-
isAsync
-
asyncPostProcess
Description copied from class:AbstractProcessorLightCalls the post process of the async state machine.- Specified by:
asyncPostProcessin classAbstractProcessorLight- Returns:
- The state the caller should put the socket in when this method returns
-
dispatch
Description copied from class:AbstractProcessorLightProcess an in-progress request that is no longer in standard HTTP mode. Uses currently include Servlet 3.0 Async and HTTP upgrade connections. Further uses may be added in the future. These will typically start as HTTP requests.- Specified by:
dispatchin classAbstractProcessorLight- Parameters:
status- The event to process- Returns:
- The state the caller should put the socket in when this method returns
- Throws:
IOException- If an I/O error occurs during the processing of the request
-
parseHost
Parses the Host header value and populates the server name and port.- Parameters:
valueMB- The MessageBytes containing the Host header value
-
populateHost
protected void populateHost()Called when a host header is not present in the request (e.g. HTTP/1.0). It populates the server name with appropriate information. The source is expected to vary by protocol.The default implementation is a NO-OP.
-
populatePort
protected void populatePort()Called when a host header is not present or is empty in the request (e.g. HTTP/1.0). It populates the server port with appropriate information. The source is expected to vary by protocol.The default implementation is a NO-OP.
-
action
Description copied from interface:ActionHookSend an action to the connector.- Specified by:
actionin interfaceActionHook- Parameters:
actionCode- Type of the actionparam- Action parameter
-
dispatchNonBlockingRead
protected void dispatchNonBlockingRead()Perform any necessary processing for a non-blocking read before dispatching to the adapter. -
timeoutAsync
public void timeoutAsync(long now) Check this processor to see if the timeout has expired and process a timeout if that is that case.Note: The name of this method originated with the Servlet 3.0 asynchronous processing but evolved over time to represent a timeout that is triggered independently of the socket read/write timeouts.
Subclasses of this base class represent a single request/response pair. The timeout to be processed is, therefore, the Servlet asynchronous processing timeout.
- Specified by:
timeoutAsyncin interfaceProcessor- Parameters:
now- The time (as returned bySystem.currentTimeMillis()) to use as the current time to determine whether the timeout has expired. If negative, the timeout will always be treated as if it has expired.
-
checkAsyncTimeoutGeneration
public boolean checkAsyncTimeoutGeneration()Description copied from interface:ProcessorCheck to see if the async generation (each cycle of async increments the generation of the AsyncStateMachine) is the same as the generation when the most recent async timeout was triggered. This is intended to be used to avoid unnecessary processing.- Specified by:
checkAsyncTimeoutGenerationin interfaceProcessor- Returns:
trueIf the async generation has not changed since the async timeout was triggered
-
setAsyncTimeout
public void setAsyncTimeout(long timeout) Sets the async timeout.- Parameters:
timeout- The timeout in milliseconds
-
getAsyncTimeout
public long getAsyncTimeout()Gets the async timeout.- Returns:
- the async timeout in milliseconds
-
recycle
-
prepareResponse
When committing the response, we have to validate the set of headers, as well as set up the response filters.- Throws:
IOException- IO exception during commit
-
finishResponse
Finish the current response.- Throws:
IOException- IO exception during the write
-
ack
Process acknowledgment of the request.- Parameters:
continueResponseTiming- specifies when an acknowledgment should be sent
-
earlyHints
Process early hints (103 Early Hints).- Throws:
IOException- IO exception during processing
-
flush
Callback to write data from the buffer.- Throws:
IOException- IO exception during the write
-
available
protected abstract int available(boolean doRead) Queries if bytes are available in buffers.- Parameters:
doRead-trueto perform a read when no bytes are availble- Returns:
- the amount of bytes that are known to be available
-
setRequestBody
Set the specified byte chunk as the request body that will be read. This allows saving and processing requests.- Parameters:
body- the byte chunk containing all the request bytes
-
setSwallowResponse
protected abstract void setSwallowResponse()The response is finished and no additional bytes need to be sent to the client. -
disableSwallowRequest
protected abstract void disableSwallowRequest()Swallowing bytes is required for pipelining requests, so this allows to avoid doing extra operations in case an error occurs and the connection is to be closed instead. -
getPopulateRequestAttributesFromSocket
protected boolean getPopulateRequestAttributesFromSocket()Processors that populate request attributes directly (e.g. AJP) should over-ride this method and returnfalse.- Returns:
trueif the SocketWrapper should be used to populate the request attributes, otherwisefalse.
-
populateRequestAttributeRemoteHost
protected void populateRequestAttributeRemoteHost()Populate the remote host request attribute. Processors (e.g. AJP) that populate this from an alternative source should override this method. -
populateSslRequestAttributes
protected void populateSslRequestAttributes()Populate the TLS related request attributes from theSSLSupportinstance associated with this processor. Protocols that populate TLS attributes from a different source (e.g. AJP) should override this method. -
sslReHandShake
Processors that can perform a TLS re-handshake (e.g. HTTP/1.1) should override this method and implement the re-handshake.- Throws:
IOException- If authentication is required then there will be I/O with the client and this exception will be thrown if that goes wrong
-
processSocketEvent
Processes a socket event.- Parameters:
event- The socket event to processdispatch-trueto dispatch to a container thread
-
isReadyForRead
protected boolean isReadyForRead()Checks if the processor is ready for reading.- Returns:
trueif there is data available or read interest is registered
-
isRequestBodyFullyRead
protected abstract boolean isRequestBodyFullyRead()Checks if the request body has been fully read.- Returns:
trueif it is known that the request body has been fully read
-
registerReadInterest
protected abstract void registerReadInterest()When using non blocking IO, register to get a callback when polling determines that bytes are available for reading. -
isReadyForWrite
protected abstract boolean isReadyForWrite()Checks if the processor is ready for writing.- Returns:
trueif bytes can be written without blocking
-
executeDispatches
protected void executeDispatches()Executes any pending non-blocking dispatches. -
getUpgradeToken
Generate an upgrade token. Processors that implement HTTP upgrade must override this method and provide the necessary token.- Specified by:
getUpgradeTokenin interfaceProcessor- Returns:
- An upgrade token encapsulating the information required to process the upgrade request
-
doHttpUpgrade
Process an HTTP upgrade. Processors that support HTTP upgrade should override this method and process the provided token.- Parameters:
upgradeToken- Contains all the information necessary for the Processor to process the upgrade- Throws:
UnsupportedOperationException- if the protocol does not support HTTP upgrade
-
getLeftoverInput
Allows retrieving additional input during the upgrade process. Processors that implement HTTP upgrade must override this method.- Specified by:
getLeftoverInputin interfaceProcessor- Returns:
- leftover bytes
-
isUpgrade
-
isPushSupported
protected boolean isPushSupported()Protocols that support push should override this method and returntrue.- Returns:
trueif push is supported by this processor, otherwisefalse.
-
doPush
Process a push. Processors that support push should override this method and process the provided token.- Parameters:
pushTarget- Contains all the information necessary for the Processor to process the push request- Throws:
UnsupportedOperationException- if the protocol does not support push
-
isTrailerFieldsReady
protected abstract boolean isTrailerFieldsReady()Checks if trailer fields are ready.- Returns:
trueif trailer fields are ready
-
isTrailerFieldsSupported
protected boolean isTrailerFieldsSupported()Protocols that support trailer fields should override this method and returntrue.- Returns:
trueif trailer fields are supported by this processor, otherwisefalse.
-
getProtocolRequestId
Protocols that provide per HTTP request IDs (e.g. Stream ID for HTTP/2) should override this method and return the appropriate ID.- Returns:
- The ID associated with this request or the empty string if no such ID is defined
-
getServletConnection
Protocols must override this method and return an appropriate ServletConnection instance- Returns:
- the ServletConnection instance associated with the current request.
-
flushBufferedWrite
Flush any pending writes. Used during non-blocking writes to flush any remaining data from a previous incomplete write.- Returns:
trueif data remains to be flushed at the end of method- Throws:
IOException- If an I/O error occurs while attempting to flush the data
-
dispatchEndRequest
Perform any necessary clean-up processing if the dispatch resulted in the completion of processing for the current request.- Returns:
- The state to return for the socket once the clean-up for the current request has completed
- Throws:
IOException- If an I/O error occurs while attempting to end the request
-
logAccess
Description copied from class:AbstractProcessorLightAdd an entry to the access log for a failed connection attempt.- Overrides:
logAccessin classAbstractProcessorLight- Parameters:
socketWrapper- The connection to process- Throws:
IOException- If an I/O error occurs during the processing of the request
-