Class AbstractProcessor

java.lang.Object
org.apache.coyote.AbstractProcessorLight
org.apache.coyote.AbstractProcessor
All Implemented Interfaces:
ActionHook, Processor
Direct Known Subclasses:
AjpProcessor, Http11Processor

public abstract class AbstractProcessor extends AbstractProcessorLight implements ActionHook
Provides functionality and attributes common to all supported protocols (currently HTTP and AJP) for processing a single request/response.
  • Field Details Link icon

    • adapter Link icon

      protected final Adapter adapter
    • asyncStateMachine Link icon

      protected final org.apache.coyote.AsyncStateMachine asyncStateMachine
    • request Link icon

      protected final Request request
    • response Link icon

      protected final Response response
    • socketWrapper Link icon

      protected volatile SocketWrapperBase<?> socketWrapper
    • sslSupport Link icon

      protected volatile SSLSupport sslSupport
    • userDataHelper Link icon

      protected final UserDataHelper userDataHelper
  • Constructor Details Link icon

    • AbstractProcessor Link icon

      public AbstractProcessor(Adapter adapter)
    • AbstractProcessor Link icon

      protected AbstractProcessor(Adapter adapter, Request coyoteRequest, Response coyoteResponse)
  • Method Details Link icon

    • setErrorState Link icon

      protected void setErrorState(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.
      Parameters:
      errorState - The error status details
      t - The error which occurred
    • getErrorState Link icon

      protected ErrorState getErrorState()
    • getRequest Link icon

      public Request getRequest()
      Specified by:
      getRequest in interface Processor
      Returns:
      The request associated with this processor.
    • getAdapter Link icon

      public Adapter getAdapter()
      Get the associated adapter.
      Returns:
      the associated adapter
    • setSocketWrapper Link icon

      protected void setSocketWrapper(SocketWrapperBase<?> socketWrapper)
      Set the socket wrapper being used.
      Parameters:
      socketWrapper - The socket wrapper
    • getSocketWrapper Link icon

      protected final SocketWrapperBase<?> getSocketWrapper()
      Returns:
      the socket wrapper being used.
    • setSslSupport Link icon

      public final void setSslSupport(SSLSupport sslSupport)
      Description copied from interface: Processor
      Set the SSL information for this HTTP connection.
      Specified by:
      setSslSupport in interface Processor
      Parameters:
      sslSupport - The SSL support object to use for this connection
    • execute Link icon

      protected void execute(Runnable runnable)
      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 Link icon

      public boolean isAsync()
      Specified by:
      isAsync in interface Processor
      Returns:
      true if the Processor state is async, otherwise false
    • asyncPostProcess Link icon

      public AbstractEndpoint.Handler.SocketState asyncPostProcess()
      Description copied from class: AbstractProcessorLight
      Calls the post process of the async state machine.
      Specified by:
      asyncPostProcess in class AbstractProcessorLight
      Returns:
      The state the caller should put the socket in when this method returns
    • dispatch Link icon

      public final AbstractEndpoint.Handler.SocketState dispatch(SocketEvent status) throws IOException
      Description copied from class: AbstractProcessorLight
      Process 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:
      dispatch in class AbstractProcessorLight
      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 Link icon

      protected void parseHost(MessageBytes valueMB)
    • populateHost Link icon

      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 Link icon

      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 Link icon

      public final void action(ActionCode actionCode, Object param)
      Description copied from interface: ActionHook
      Send an action to the connector.
      Specified by:
      action in interface ActionHook
      Parameters:
      actionCode - Type of the action
      param - Action parameter
    • dispatchNonBlockingRead Link icon

      protected void dispatchNonBlockingRead()
      Perform any necessary processing for a non-blocking read before dispatching to the adapter.
    • timeoutAsync Link icon

      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:
      timeoutAsync in interface Processor
      Parameters:
      now - The time (as returned by System.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 Link icon

      public boolean checkAsyncTimeoutGeneration()
      Description copied from interface: Processor
      Check 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:
      checkAsyncTimeoutGeneration in interface Processor
      Returns:
      true If the async generation has not changed since the async timeout was triggered
    • setAsyncTimeout Link icon

      public void setAsyncTimeout(long timeout)
    • getAsyncTimeout Link icon

      public long getAsyncTimeout()
    • recycle Link icon

      public void recycle()
      Description copied from interface: Processor
      Recycle the processor, ready for the next request which may be on the same connection or a different connection.
      Specified by:
      recycle in interface Processor
    • prepareResponse Link icon

      protected abstract void prepareResponse() throws IOException
      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 Link icon

      protected abstract void finishResponse() throws IOException
      Finish the current response.
      Throws:
      IOException - IO exception during the write
    • ack Link icon

      @Deprecated protected void ack()
      Deprecated.
      Unused. This will be removed in Tomcat 10 onwards. Use ack(ContinueResponseTiming).
    • ack Link icon

      protected abstract void ack(ContinueResponseTiming continueResponseTiming)
      Process acknowledgment of the request.
      Parameters:
      continueResponseTiming - specifies when an acknowledgment should be sent
    • earlyHints Link icon

      protected abstract void earlyHints() throws IOException
      Throws:
      IOException
    • flush Link icon

      protected abstract void flush() throws IOException
      Callback to write data from the buffer.
      Throws:
      IOException - IO exception during the write
    • available Link icon

      protected abstract int available(boolean doRead)
      Queries if bytes are available in buffers.
      Parameters:
      doRead - true to perform a read when no bytes are availble
      Returns:
      the amount of bytes that are known to be available
    • setRequestBody Link icon

      protected abstract void setRequestBody(ByteChunk body)
      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 Link icon

      protected abstract void setSwallowResponse()
      The response is finished and no additional bytes need to be sent to the client.
    • disableSwallowRequest Link icon

      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 Link icon

      protected boolean getPopulateRequestAttributesFromSocket()
      Processors that populate request attributes directly (e.g. AJP) should over-ride this method and return false.
      Returns:
      true if the SocketWrapper should be used to populate the request attributes, otherwise false.
    • populateRequestAttributeRemoteHost Link icon

      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 Link icon

      protected void populateSslRequestAttributes()
      Populate the TLS related request attributes from the SSLSupport instance associated with this processor. Protocols that populate TLS attributes from a different source (e.g. AJP) should override this method.
    • sslReHandShake Link icon

      protected void sslReHandShake() throws IOException
      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 Link icon

      protected void processSocketEvent(SocketEvent event, boolean dispatch)
    • isReadyForRead Link icon

      protected boolean isReadyForRead()
    • isRequestBodyFullyRead Link icon

      protected abstract boolean isRequestBodyFullyRead()
      Returns:
      true if it is known that the request body has been fully read
    • registerReadInterest Link icon

      protected abstract void registerReadInterest()
      When using non blocking IO, register to get a callback when polling determines that bytes are available for reading.
    • isReadyForWrite Link icon

      protected abstract boolean isReadyForWrite()
      Returns:
      true if bytes can be written without blocking
    • executeDispatches Link icon

      protected void executeDispatches()
    • getUpgradeToken Link icon

      public UpgradeToken getUpgradeToken()
      Generate an upgrade token. Processors that implement HTTP upgrade must override this method and provide the necessary token.
      Specified by:
      getUpgradeToken in interface Processor
      Returns:
      An upgrade token encapsulating the information required to process the upgrade request
    • doHttpUpgrade Link icon

      protected void doHttpUpgrade(UpgradeToken upgradeToken)
      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 Link icon

      public ByteBuffer getLeftoverInput()
      Allows retrieving additional input during the upgrade process. Processors that implement HTTP upgrade must override this method.
      Specified by:
      getLeftoverInput in interface Processor
      Returns:
      leftover bytes
    • isUpgrade Link icon

      public boolean isUpgrade()
      Processors that implement HTTP upgrade must override this method.
      Specified by:
      isUpgrade in interface Processor
      Returns:
      true if the Processor is currently processing an upgrade request, otherwise false
    • isPushSupported Link icon

      protected boolean isPushSupported()
      Protocols that support push should override this method and return true.
      Returns:
      true if push is supported by this processor, otherwise false.
    • doPush Link icon

      protected void doPush(Request pushTarget)
      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 Link icon

      protected abstract boolean isTrailerFieldsReady()
    • isTrailerFieldsSupported Link icon

      protected boolean isTrailerFieldsSupported()
      Protocols that support trailer fields should override this method and return true.
      Returns:
      true if trailer fields are supported by this processor, otherwise false.
    • getConnectionID Link icon

      protected Object getConnectionID()
      Protocols that support multiplexing (e.g. HTTP/2) should override this method and return the appropriate ID.
      Returns:
      The stream ID associated with this request or null if a multiplexing protocol is not being used
    • getStreamID Link icon

      protected Object getStreamID()
      Protocols that support multiplexing (e.g. HTTP/2) should override this method and return the appropriate ID.
      Returns:
      The stream ID associated with this request or null if a multiplexing protocol is not being used
    • flushBufferedWrite Link icon

      protected abstract boolean flushBufferedWrite() throws IOException
      Flush any pending writes. Used during non-blocking writes to flush any remaining data from a previous incomplete write.
      Returns:
      true if 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 Link icon

      protected abstract AbstractEndpoint.Handler.SocketState dispatchEndRequest() throws IOException
      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 Link icon

      protected final void logAccess(SocketWrapperBase<?> socketWrapper) throws IOException
      Description copied from class: AbstractProcessorLight
      Add an entry to the access log for a failed connection attempt.
      Overrides:
      logAccess in class AbstractProcessorLight
      Parameters:
      socketWrapper - The connection to process
      Throws:
      IOException - If an I/O error occurs during the processing of the request