Class StandardServletAsyncWebRequest
- java.lang.Object
- org.springframework.web.context.request.AbstractRequestAttributes
- org.springframework.web.context.request.ServletRequestAttributes
- org.springframework.web.context.request.ServletWebRequest
- org.springframework.web.context.request.async.StandardServletAsyncWebRequest
- All Implemented Interfaces:
EventListener,AsyncListener,AsyncWebRequest,NativeWebRequest,RequestAttributes,WebRequest
public class StandardServletAsyncWebRequest extends ServletWebRequest implements AsyncWebRequest, AsyncListener
A Servlet 3.0 implementation ofAsyncWebRequest.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 inweb.xml.- Since:
- 3.2
- Author:
- Rossen Stoyanchev
Field Summary
Fields inherited from class org.springframework.web.context.request.ServletRequestAttributes
DESTRUCTION_CALLBACK_NAME_PREFIX, immutableValueTypes
Fields inherited from class org.springframework.web.context.request.AbstractRequestAttributes
requestDestructionCallbacks
Fields inherited from interface org.springframework.web.context.request.RequestAttributes
REFERENCE_REQUEST, REFERENCE_SESSION, SCOPE_REQUEST, SCOPE_SESSION
Constructor Summary
Constructors Constructor Description StandardServletAsyncWebRequest(HttpServletRequest request, HttpServletResponse response)Create a new instance for the given request/response pair.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCompletionHandler(Runnable runnable)Add a handler to invoke when request processing completes.voidaddErrorHandler(Consumer<Throwable> exceptionHandler)Add a handler to invoke when an error occurred while concurrent handling of a request.voidaddTimeoutHandler(Runnable timeoutHandler)Add a handler to invoke when concurrent handling has timed out.voiddispatch()Dispatch the request to the container in order to resume processing after concurrent execution in an application thread.booleanisAsyncComplete()Whether async request processing has completed.booleanisAsyncStarted()Whether the request is in async mode following a call toAsyncWebRequest.startAsync().voidonComplete(AsyncEvent event)Notifies this AsyncListener that an asynchronous operation has been completed.voidonError(AsyncEvent event)Notifies this AsyncListener that an asynchronous operation has failed to complete.voidonStartAsync(AsyncEvent event)Notifies this AsyncListener that a new asynchronous cycle is being initiated via a call to one of theServletRequest.startAsync()methods.voidonTimeout(AsyncEvent event)Notifies this AsyncListener that an asynchronous operation has timed out.voidsetTimeout(Long timeout)In Servlet 3 async processing, the timeout period begins after the container processing thread has exited.voidstartAsync()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.Methods inherited from class org.springframework.web.context.request.ServletWebRequest
checkNotModified, checkNotModified, checkNotModified, getContextPath, getDescription, getHeader, getHeaderNames, getHeaderValues, getHttpMethod, getLocale, getNativeRequest, getNativeRequest, getNativeResponse, getNativeResponse, getParameter, getParameterMap, getParameterNames, getParameterValues, getRemoteUser, getUserPrincipal, isNotModified, isSecure, isUserInRole, toString
Methods inherited from class org.springframework.web.context.request.ServletRequestAttributes
getAttribute, getAttributeNames, getRequest, getResponse, getSession, getSessionId, getSessionMutex, isImmutableSessionAttribute, registerDestructionCallback, registerSessionDestructionCallback, removeAttribute, resolveReference, setAttribute, updateAccessedSessionAttributes
Methods inherited from class org.springframework.web.context.request.AbstractRequestAttributes
isRequestActive, registerRequestDestructionCallback, removeRequestDestructionCallback, requestCompleted
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.web.context.request.NativeWebRequest
getNativeRequest, getNativeRequest, getNativeResponse, getNativeResponse
Methods inherited from interface org.springframework.web.context.request.RequestAttributes
getAttribute, getAttributeNames, getSessionId, getSessionMutex, registerDestructionCallback, removeAttribute, resolveReference, setAttribute
Methods inherited from interface org.springframework.web.context.request.WebRequest
checkNotModified, checkNotModified, checkNotModified, getContextPath, getDescription, getHeader, getHeaderNames, getHeaderValues, getLocale, getParameter, getParameterMap, getParameterNames, getParameterValues, getRemoteUser, getUserPrincipal, isSecure, isUserInRole
Constructor Detail
StandardServletAsyncWebRequest
public StandardServletAsyncWebRequest(HttpServletRequest request, HttpServletResponse response)
Create a new instance for the given request/response pair.- Parameters:
request- current HTTP requestresponse- current HTTP response
Method Detail
setTimeout
public void setTimeout(Long timeout)
In Servlet 3 async processing, the timeout period begins after the container processing thread has exited.- Specified by:
setTimeoutin interfaceAsyncWebRequest- Parameters:
timeout- amount of time in milliseconds;nullmeans no timeout, i.e. rely on the default timeout of the container.
addTimeoutHandler
public void addTimeoutHandler(Runnable timeoutHandler)
Description copied from interface:AsyncWebRequestAdd a handler to invoke when concurrent handling has timed out.- Specified by:
addTimeoutHandlerin interfaceAsyncWebRequest
addErrorHandler
public void addErrorHandler(Consumer<Throwable> exceptionHandler)
Description copied from interface:AsyncWebRequestAdd a handler to invoke when an error occurred while concurrent handling of a request.- Specified by:
addErrorHandlerin interfaceAsyncWebRequest
addCompletionHandler
public void addCompletionHandler(Runnable runnable)
Description copied from interface:AsyncWebRequestAdd a handler to invoke when request processing completes.- Specified by:
addCompletionHandlerin interfaceAsyncWebRequest
isAsyncStarted
public boolean isAsyncStarted()
Description copied from interface:AsyncWebRequestWhether the request is in async mode following a call toAsyncWebRequest.startAsync(). Returns "false" if asynchronous processing never started, has completed, or the request was dispatched for further processing.- Specified by:
isAsyncStartedin interfaceAsyncWebRequest
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:
isAsyncCompletein interfaceAsyncWebRequest
startAsync
public void startAsync()
Description copied from interface:AsyncWebRequestMark 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:
startAsyncin interfaceAsyncWebRequest
dispatch
public void dispatch()
Description copied from interface:AsyncWebRequestDispatch the request to the container in order to resume processing after concurrent execution in an application thread.- Specified by:
dispatchin interfaceAsyncWebRequest
onStartAsync
public void onStartAsync(AsyncEvent event) throws IOException
Description copied from interface:javax.servlet.AsyncListenerNotifies this AsyncListener that a new asynchronous cycle is being initiated via a call to one of theServletRequest.startAsync()methods.The
AsyncContextcorresponding to the asynchronous operation that is being reinitialized may be obtained by callinggetAsyncContexton the given event.In addition, if this AsyncListener had been registered via a call to
AsyncContext.addListener(AsyncListener, ServletRequest, ServletResponse), the supplied ServletRequest and ServletResponse objects may be retrieved by callinggetSuppliedRequestandgetSuppliedResponse, respectively, on the given event.This AsyncListener will not receive any events related to the new asynchronous cycle unless it registers itself (via a call to
AsyncContext.addListener(javax.servlet.AsyncListener)) with the AsyncContext that is delivered as part of the given AsyncEvent.- Specified by:
onStartAsyncin interfaceAsyncListener- Parameters:
event- the AsyncEvent indicating that a new asynchronous cycle is being initiated- Throws:
IOException- if an I/O related error has occurred during the processing of the given AsyncEvent
onError
public void onError(AsyncEvent event) throws IOException
Description copied from interface:javax.servlet.AsyncListenerNotifies this AsyncListener that an asynchronous operation has failed to complete.The
AsyncContextcorresponding to the asynchronous operation that failed to complete may be obtained by callinggetAsyncContexton the given event.In addition, if this AsyncListener had been registered via a call to
AsyncContext.addListener(AsyncListener, ServletRequest, ServletResponse), the supplied ServletRequest and ServletResponse objects may be retrieved by callinggetSuppliedRequestandgetSuppliedResponse, respectively, on the given event.- Specified by:
onErrorin interfaceAsyncListener- Parameters:
event- the AsyncEvent indicating that an asynchronous operation has failed to complete- Throws:
IOException- if an I/O related error has occurred during the processing of the given AsyncEvent
onTimeout
public void onTimeout(AsyncEvent event) throws IOException
Description copied from interface:javax.servlet.AsyncListenerNotifies this AsyncListener that an asynchronous operation has timed out.The
AsyncContextcorresponding to the asynchronous operation that has timed out may be obtained by callinggetAsyncContexton the given event.In addition, if this AsyncListener had been registered via a call to
AsyncContext.addListener(AsyncListener, ServletRequest, ServletResponse), the supplied ServletRequest and ServletResponse objects may be retrieved by callinggetSuppliedRequestandgetSuppliedResponse, respectively, on the given event.- Specified by:
onTimeoutin interfaceAsyncListener- Parameters:
event- the AsyncEvent indicating that an asynchronous operation has timed out- Throws:
IOException- if an I/O related error has occurred during the processing of the given AsyncEvent
onComplete
public void onComplete(AsyncEvent event) throws IOException
Description copied from interface:javax.servlet.AsyncListenerNotifies this AsyncListener that an asynchronous operation has been completed.The
AsyncContextcorresponding to the asynchronous operation that has been completed may be obtained by callinggetAsyncContexton the given event.In addition, if this AsyncListener had been registered via a call to
AsyncContext.addListener(AsyncListener, ServletRequest, ServletResponse), the supplied ServletRequest and ServletResponse objects may be retrieved by callinggetSuppliedRequestandgetSuppliedResponse, respectively, on the given event.- Specified by:
onCompletein interfaceAsyncListener- Parameters:
event- the AsyncEvent indicating that an asynchronous operation has been completed- Throws:
IOException- if an I/O related error has occurred during the processing of the given AsyncEvent