Class StandardServletAsyncWebRequest

All Implemented Interfaces:
jakarta.servlet.AsyncListener, EventListener, AsyncWebRequest, NativeWebRequest, RequestAttributes, WebRequest

public class StandardServletAsyncWebRequest extends ServletWebRequest implements AsyncWebRequest, jakarta.servlet.AsyncListener
A Servlet implementation of AsyncWebRequest.

The servlet and all filters involved in an async request must have async support enabled using the Servlet API or by adding an <async-supported>true</async-supported> element to servlet and filter declarations in web.xml.

Since:
3.2
Author:
Rossen Stoyanchev
  • Constructor Details

    • StandardServletAsyncWebRequest

      public StandardServletAsyncWebRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Create a new instance for the given request/response pair.
      Parameters:
      request - current HTTP request
      response - current HTTP response
  • Method Details

    • setTimeout

      public void setTimeout(@Nullable Long timeout)
      In Servlet 3 async processing, the timeout period begins after the container processing thread has exited.
      Specified by:
      setTimeout in interface AsyncWebRequest
      Parameters:
      timeout - amount of time in milliseconds; null means no timeout, i.e. rely on the default timeout of the container.
    • addTimeoutHandler

      public void addTimeoutHandler(Runnable timeoutHandler)
      Description copied from interface: AsyncWebRequest
      Add a handler to invoke when concurrent handling has timed out.
      Specified by:
      addTimeoutHandler in interface AsyncWebRequest
    • addErrorHandler

      public void addErrorHandler(Consumer<Throwable> exceptionHandler)
      Description copied from interface: AsyncWebRequest
      Add a handler to invoke when an error occurred while concurrent handling of a request.
      Specified by:
      addErrorHandler in interface AsyncWebRequest
    • addCompletionHandler

      public void addCompletionHandler(Runnable runnable)
      Description copied from interface: AsyncWebRequest
      Add a handler to invoke when request processing completes.
      Specified by:
      addCompletionHandler in interface AsyncWebRequest
    • isAsyncStarted

      public boolean isAsyncStarted()
      Description copied from interface: AsyncWebRequest
      Whether the request is in async mode following a call to AsyncWebRequest.startAsync(). Returns "false" if asynchronous processing never started, has completed, or the request was dispatched for further processing.
      Specified by:
      isAsyncStarted in interface AsyncWebRequest
    • isAsyncComplete

      public boolean isAsyncComplete()
      Whether async request processing has completed.

      It is important to avoid use of request and response objects after async processing has completed. Servlet containers often re-use them.

      Specified by:
      isAsyncComplete in interface AsyncWebRequest
    • startAsync

      public void startAsync()
      Description copied from interface: AsyncWebRequest
      Mark the start of asynchronous request processing so that when the main processing thread exits, the response remains open for further processing in another thread.
      Specified by:
      startAsync in interface AsyncWebRequest
    • dispatch

      public void dispatch()
      Description copied from interface: AsyncWebRequest
      Dispatch the request to the container in order to resume processing after concurrent execution in an application thread.
      Specified by:
      dispatch in interface AsyncWebRequest
    • onStartAsync

      public void onStartAsync(jakarta.servlet.AsyncEvent event) throws IOException
      Specified by:
      onStartAsync in interface jakarta.servlet.AsyncListener
      Throws:
      IOException
    • onTimeout

      public void onTimeout(jakarta.servlet.AsyncEvent event) throws IOException
      Specified by:
      onTimeout in interface jakarta.servlet.AsyncListener
      Throws:
      IOException
    • onError

      public void onError(jakarta.servlet.AsyncEvent event) throws IOException
      Specified by:
      onError in interface jakarta.servlet.AsyncListener
      Throws:
      IOException
    • onComplete

      public void onComplete(jakarta.servlet.AsyncEvent event) throws IOException
      Specified by:
      onComplete in interface jakarta.servlet.AsyncListener
      Throws:
      IOException