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

public Interface DeferredResultProcessingInterceptor

Known Direct Implementers
org.springframework.web.context.request.async.TimeoutDeferredResultProcessingInterceptor
Imports
org.springframework.lang.Nullable, org.springframework.web.context.request.NativeWebRequest

Intercepts concurrent request handling, where the concurrent result is obtained by waiting for a DeferredResult to be set from a thread chosen by the application (e.g. in response to some external event).

A DeferredResultProcessingInterceptor is invoked before the start of async processing, after the DeferredResult is set as well as on timeout/error, or after completing for any reason including a timeout or network error.

As a general rule exceptions raised by interceptor methods will cause async processing to resume by dispatching back to the container and using the Exception instance as the concurrent result. Such exceptions will then be processed through the HandlerExceptionResolver mechanism.

The handleTimeout method can set the DeferredResult in order to resume processing.

Authors
Rossen Stoyanchev, Rob Winch
Since
3.2

Method Summary

Modifier and TypeMethod and Description
public default <T> void
afterCompletion(NativeWebRequest
the current request
request
,
DeferredResult<T>
the DeferredResult for the current request
deferredResult
)

Invoked from a container thread when an async request completed for any reason including timeout and network error.

public default <T> void
beforeConcurrentHandling(NativeWebRequest
the current request
request
,
DeferredResult<T>
the DeferredResult for the current request
deferredResult
)

Invoked immediately before the start of concurrent handling, in the same thread that started it.

public default <T> boolean

Returns:

true if error handling should continue, or false if other interceptors should be bypassed and not be invoked
handleError
(NativeWebRequest
the current request
request
,
DeferredResult<T>
the DeferredResult for the current request; if the DeferredResult is set, then concurrent processing is resumed and subsequent interceptors are not invoked
deferredResult
,
Throwable
the error that occurred while request processing
t
)

Invoked from a container thread when an error occurred while processing an async request before the DeferredResult has been set.

public default <T> boolean

Returns:

true if processing should continue, or false if other interceptors should not be invoked
handleTimeout
(NativeWebRequest
the current request
request
,
DeferredResult<T>
the DeferredResult for the current request; if the DeferredResult is set, then concurrent processing is resumed and subsequent interceptors are not invoked
deferredResult
)

Invoked from a container thread when an async request times out before the DeferredResult has been set.

public default <T> void
postProcess(NativeWebRequest
the current request
request
,
DeferredResult<T>
the DeferredResult for the current request
deferredResult
,
Object
the concurrent result
concurrentResult
)

Invoked after a DeferredResult has been set, via DeferredResult#setResult(Object) or DeferredResult#setErrorResult(Object), and is also ready to handle the concurrent result.

public default <T> void
preProcess(NativeWebRequest
the current request
request
,
DeferredResult<T>
the DeferredResult for the current request
deferredResult
)

Invoked immediately after the start of concurrent handling, in the same thread that started it.

Method Detail

afterCompletionback to summary
public default <T> void afterCompletion(NativeWebRequest request, DeferredResult<T> deferredResult) throws Exception

Invoked from a container thread when an async request completed for any reason including timeout and network error. This method is useful for detecting that a DeferredResult instance is no longer usable.

Parameters
request:NativeWebRequest

the current request

deferredResult:DeferredResult<T>

the DeferredResult for the current request

Exceptions
Exception:
in case of errors
beforeConcurrentHandlingback to summary
public default <T> void beforeConcurrentHandling(NativeWebRequest request, DeferredResult<T> deferredResult) throws Exception

Invoked immediately before the start of concurrent handling, in the same thread that started it. This method may be used to capture state just prior to the start of concurrent processing with the given DeferredResult.

Parameters
request:NativeWebRequest

the current request

deferredResult:DeferredResult<T>

the DeferredResult for the current request

Exceptions
Exception:
in case of errors
handleErrorback to summary
public default <T> boolean handleError(NativeWebRequest request, DeferredResult<T> deferredResult, Throwable t) throws Exception

Invoked from a container thread when an error occurred while processing an async request before the DeferredResult has been set. Implementations may invoke setResult or setErrorResult to resume processing.

Parameters
request:NativeWebRequest

the current request

deferredResult:DeferredResult<T>

the DeferredResult for the current request; if the DeferredResult is set, then concurrent processing is resumed and subsequent interceptors are not invoked

t:Throwable

the error that occurred while request processing

Returns:boolean

true if error handling should continue, or false if other interceptors should be bypassed and not be invoked

Exceptions
Exception:
in case of errors
handleTimeoutback to summary
public default <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> deferredResult) throws Exception

Invoked from a container thread when an async request times out before the DeferredResult has been set. Implementations may invoke setResult or setErrorResult to resume processing.

Parameters
request:NativeWebRequest

the current request

deferredResult:DeferredResult<T>

the DeferredResult for the current request; if the DeferredResult is set, then concurrent processing is resumed and subsequent interceptors are not invoked

Returns:boolean

true if processing should continue, or false if other interceptors should not be invoked

Exceptions
Exception:
in case of errors
postProcessback to summary
public default <T> void postProcess(NativeWebRequest request, DeferredResult<T> deferredResult, Object concurrentResult) throws Exception

Invoked after a DeferredResult has been set, via DeferredResult#setResult(Object) or DeferredResult#setErrorResult(Object), and is also ready to handle the concurrent result.

This method may also be invoked after a timeout when the DeferredResult was created with a constructor accepting a default timeout result.

Parameters
request:NativeWebRequest

the current request

deferredResult:DeferredResult<T>

the DeferredResult for the current request

concurrentResult:Object

the concurrent result

Exceptions
Exception:
in case of errors
preProcessback to summary
public default <T> void preProcess(NativeWebRequest request, DeferredResult<T> deferredResult) throws Exception

Invoked immediately after the start of concurrent handling, in the same thread that started it. This method may be used to detect the start of concurrent processing with the given DeferredResult.

The DeferredResult may have already been set, for example at the time of its creation or by another thread.

Parameters
request:NativeWebRequest

the current request

deferredResult:DeferredResult<T>

the DeferredResult for the current request

Exceptions
Exception:
in case of errors