Top Description Fields Constructors Methods
org.springframework.web.context.request.async

public Class StandardServletAsyncWebRequest

extends ServletWebRequest
implements AsyncWebRequest, AsyncListener
Class Inheritance
All Implemented Interfaces
jakarta.servlet.AsyncListener, java.util.EventListener, org.springframework.web.context.request.async.AsyncWebRequest, org.springframework.web.context.request.NativeWebRequest, org.springframework.web.context.request.WebRequest, org.springframework.web.context.request.RequestAttributes
Imports
java.io.IOException, java.util.ArrayList, .List, java.util.concurrent.atomic.AtomicBoolean, java.util.function.Consumer, jakarta.servlet.AsyncContext, .AsyncEvent, .AsyncListener, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.web.context.request.ServletWebRequest

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.

Author
Rossen Stoyanchev
Since
3.2

Field Summary

Modifier and TypeField and Description
private final AtomicBoolean
private AsyncContext
private final List<Runnable>
private final List<Consumer<Throwable>>
private Long
private final List<Runnable>

Constructor Summary

AccessConstructor and Description
public
StandardServletAsyncWebRequest(HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
)

Create a new instance for the given request/response pair.

Method Summary

Modifier and TypeMethod and Description
public void
addCompletionHandler(Runnable runnable)

Implements org.springframework.web.context.request.async.AsyncWebRequest.addCompletionHandler.

Add a handler to invoke when request processing completes.

public void
addErrorHandler(Consumer<Throwable> exceptionHandler)

Implements org.springframework.web.context.request.async.AsyncWebRequest.addErrorHandler.

Add a handler to invoke when an error occurred while concurrent handling of a request.

public void
addTimeoutHandler(Runnable timeoutHandler)

Implements org.springframework.web.context.request.async.AsyncWebRequest.addTimeoutHandler.

Add a handler to invoke when concurrent handling has timed out.

public void
dispatch()

Implements org.springframework.web.context.request.async.AsyncWebRequest.dispatch.

Dispatch the request to the container in order to resume processing after concurrent execution in an application thread.

public boolean
isAsyncComplete()

Implements org.springframework.web.context.request.async.AsyncWebRequest.isAsyncComplete.

Whether async request processing has completed.

public boolean
isAsyncStarted()

Implements org.springframework.web.context.request.async.AsyncWebRequest.isAsyncStarted.

Whether the request is in async mode following a call to startAsync().

public void
onComplete(AsyncEvent
Provides access to the objects associated with the event
event
)

Implements jakarta.servlet.AsyncListener.onComplete.

This event is fired after the call to AsyncContext#complete() has been processed by the container.

public void
onError(AsyncEvent
Provides access to the objects associated with the event
event
)

Implements jakarta.servlet.AsyncListener.onError.

This event is fired if an error occurs during an asynchronous operation but before the container takes any action as a result of the error.

public void
onStartAsync(AsyncEvent
Provides access to the objects associated with the event
event
)

Implements jakarta.servlet.AsyncListener.onStartAsync.

This event is fired if new call is made to ServletRequest#startAsync() after the completion of the AsyncContext to which this listener was added.

public void
onTimeout(AsyncEvent
Provides access to the objects associated with the event
event
)

Implements jakarta.servlet.AsyncListener.onTimeout.

This event is fired if an asynchronous operation times out but before the container takes any action as a result of the timeout.

public void
setTimeout(Long
amount of time in milliseconds; null means no timeout, i.e. rely on the default timeout of the container.
timeout
)

Implements org.springframework.web.context.request.async.AsyncWebRequest.setTimeout.

In Servlet 3 async processing, the timeout period begins after the container processing thread has exited.

public void
startAsync()

Implements org.springframework.web.context.request.async.AsyncWebRequest.startAsync.

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.

Inherited from org.springframework.web.context.request.ServletWebRequest:
checkNotModifiedcheckNotModifiedcheckNotModifiedgetContextPathgetDescriptiongetHeadergetHeaderNamesgetHeaderValuesgetHttpMethodgetLocalegetNativeRequestgetNativeRequestgetNativeResponsegetNativeResponsegetParametergetParameterMapgetParameterNamesgetParameterValuesgetRemoteUsergetUserPrincipalisNotModifiedisSecureisUserInRoletoString

Field Detail

asyncCompletedback to summary
private final AtomicBoolean asyncCompleted
asyncContextback to summary
private AsyncContext asyncContext
Annotations
@Nullable
completionHandlersback to summary
private final List<Runnable> completionHandlers
exceptionHandlersback to summary
private final List<Consumer<Throwable>> exceptionHandlers
timeoutback to summary
private Long timeout
Annotations
@Nullable
timeoutHandlersback to summary
private final List<Runnable> timeoutHandlers

Constructor Detail

StandardServletAsyncWebRequestback to summary
public StandardServletAsyncWebRequest(HttpServletRequest request, HttpServletResponse response)

Create a new instance for the given request/response pair.

Parameters
request:HttpServletRequest

current HTTP request

response:HttpServletResponse

current HTTP response

Method Detail

addCompletionHandlerback to summary
public void addCompletionHandler(Runnable runnable)

Implements org.springframework.web.context.request.async.AsyncWebRequest.addCompletionHandler.

Doc from org.springframework.web.context.request.async.AsyncWebRequest.addCompletionHandler.

Add a handler to invoke when request processing completes.

Annotations
@Override
addErrorHandlerback to summary
public void addErrorHandler(Consumer<Throwable> exceptionHandler)

Implements org.springframework.web.context.request.async.AsyncWebRequest.addErrorHandler.

Doc from org.springframework.web.context.request.async.AsyncWebRequest.addErrorHandler.

Add a handler to invoke when an error occurred while concurrent handling of a request.

Annotations
@Override
addTimeoutHandlerback to summary
public void addTimeoutHandler(Runnable timeoutHandler)

Implements org.springframework.web.context.request.async.AsyncWebRequest.addTimeoutHandler.

Doc from org.springframework.web.context.request.async.AsyncWebRequest.addTimeoutHandler.

Add a handler to invoke when concurrent handling has timed out.

Annotations
@Override
dispatchback to summary
public void dispatch()

Implements org.springframework.web.context.request.async.AsyncWebRequest.dispatch.

Doc from org.springframework.web.context.request.async.AsyncWebRequest.dispatch.

Dispatch the request to the container in order to resume processing after concurrent execution in an application thread.

Annotations
@Override
isAsyncCompleteback to summary
public boolean isAsyncComplete()

Implements org.springframework.web.context.request.async.AsyncWebRequest.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.

Annotations
@Override
isAsyncStartedback to summary
public boolean isAsyncStarted()

Implements org.springframework.web.context.request.async.AsyncWebRequest.isAsyncStarted.

Doc from org.springframework.web.context.request.async.AsyncWebRequest.isAsyncStarted.

Whether the request is in async mode following a call to startAsync(). Returns "false" if asynchronous processing never started, has completed, or the request was dispatched for further processing.

Annotations
@Override
onCompleteback to summary
public void onComplete(AsyncEvent event) throws IOException

Implements jakarta.servlet.AsyncListener.onComplete.

Doc from jakarta.servlet.AsyncListener.onComplete.

This event is fired after the call to AsyncContext#complete() has been processed by the container.

Parameters
event:AsyncEvent

Provides access to the objects associated with the event

Annotations
@Override
Exceptions
IOException:
Should be thrown if an I/O error occurs during the processing of the event
onErrorback to summary
public void onError(AsyncEvent event) throws IOException

Implements jakarta.servlet.AsyncListener.onError.

Doc from jakarta.servlet.AsyncListener.onError.

This event is fired if an error occurs during an asynchronous operation but before the container takes any action as a result of the error.

Parameters
event:AsyncEvent

Provides access to the objects associated with the event

Annotations
@Override
Exceptions
IOException:
Should be thrown if an I/O error occurs during the processing of the event
onStartAsyncback to summary
public void onStartAsync(AsyncEvent event) throws IOException

Implements jakarta.servlet.AsyncListener.onStartAsync.

Doc from jakarta.servlet.AsyncListener.onStartAsync.

This event is fired if new call is made to ServletRequest#startAsync() after the completion of the AsyncContext to which this listener was added.

Parameters
event:AsyncEvent

Provides access to the objects associated with the event

Annotations
@Override
Exceptions
IOException:
Should be thrown if an I/O error occurs during the processing of the event
onTimeoutback to summary
public void onTimeout(AsyncEvent event) throws IOException

Implements jakarta.servlet.AsyncListener.onTimeout.

Doc from jakarta.servlet.AsyncListener.onTimeout.

This event is fired if an asynchronous operation times out but before the container takes any action as a result of the timeout.

Parameters
event:AsyncEvent

Provides access to the objects associated with the event

Annotations
@Override
Exceptions
IOException:
Should be thrown if an I/O error occurs during the processing of the event
setTimeoutback to summary
public void setTimeout(Long timeout)

Implements org.springframework.web.context.request.async.AsyncWebRequest.setTimeout.

In Servlet 3 async processing, the timeout period begins after the container processing thread has exited.

Parameters
timeout:Long

Doc from org.springframework.web.context.request.async.AsyncWebRequest.setTimeout.

amount of time in milliseconds; null means no timeout, i.e. rely on the default timeout of the container.

Annotations
@Override
startAsyncback to summary
public void startAsync()

Implements org.springframework.web.context.request.async.AsyncWebRequest.startAsync.

Doc from org.springframework.web.context.request.async.AsyncWebRequest.startAsync.

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.

Annotations
@Override