An AsyncContext is created and initialized by a call to
ServletRequest#startAsync() or
ServletRequest#startAsync(ServletRequest, ServletResponse).
Repeated invocations of these methods will return the same AsyncContext
instance, reinitialized as appropriate.
In the event that an asynchronous operation has timed out, the container must run through these steps:
onTimeout method, all
AsyncListener instances registered with the ServletRequest
on which the asynchronous operation was initiated.complete or any of the
dispatch methods, perform an error dispatch with a status code
equal to HttpServletResponse.SC_INTERNAL_SERVER_ERROR.complete or any of the dispatch methods, call
complete.| Modifier and Type | Field and Description |
|---|---|
| public static final String | ASYNC_CONTEXT_PATH
The name of the request attribute under which the original
context path is made available to the target of a
|
| public static final String | ASYNC_MAPPING
The name of the request attribute under which the original
|
| public static final String | ASYNC_PATH_INFO
The name of the request attribute under which the original
path info is made available to the target of a
|
| public static final String | ASYNC_QUERY_STRING
The name of the request attribute under which the original
query string is made available to the target of a
|
| public static final String | ASYNC_REQUEST_URI
The name of the request attribute under which the original
request URI is made available to the target of a
|
| public static final String | ASYNC_SERVLET_PATH
The name of the request attribute under which the original
servlet path is made available to the target of a
|
| Modifier and Type | Method and Description |
|---|---|
| public void | addListener(AsyncListener
the AsyncListener to be registered listener)Registers the given |
| public void | addListener(AsyncListener
the AsyncListener to be registered listener, ServletRequest the ServletRequest that will be included
in the AsyncEvent servletRequest, ServletResponse the ServletResponse that will be included
in the AsyncEvent servletResponse)Registers the given |
| public void | complete()
Completes the asynchronous operation that was started on the request that was used to initialze this AsyncContext, closing the response that was used to initialize this AsyncContext. |
| public < the class of the object to instantiate T extends AsyncListener> T | Returns: the new AsyncListener instancethe AsyncListener class to instantiate clazz)Instantiates the given |
| public void | dispatch()
Dispatches the request and response objects of this AsyncContext to the servlet container. |
| public void | |
| public void | dispatch(ServletContext
the ServletContext of the dispatch target context, String the path of the dispatch target, scoped to the given
ServletContext path)Dispatches the request and response objects of this AsyncContext to the given path scoped to the given context. |
| public ServletRequest | Returns: the request that was used to initialize this AsyncContextGets the request that was used to initialize this AsyncContext
by calling |
| public ServletResponse | Returns: the response that was used to initialize this AsyncContextGets the response that was used to initialize this AsyncContext
by calling |
| public long | Returns: the timeout in millisecondsGets the timeout (in milliseconds) for this AsyncContext. |
| public boolean | Returns: true if this AsyncContext was initialized with the original request and response objects by callingServletRequest#startAsync(), or if it was initialized by
calling
ServletRequest#startAsync(ServletRequest, ServletResponse),
and neither the ServletRequest nor ServletResponse arguments
carried any application-provided wrappers; false otherwiseChecks if this AsyncContext was initialized with the original or application-wrapped request and response objects. |
| public void | setTimeout(long
the timeout in milliseconds timeout)Sets the timeout (in milliseconds) for this AsyncContext. |
| public void |
| ASYNC_CONTEXT_PATH | back to summary |
|---|---|
| public static final String ASYNC_CONTEXT_PATH The name of the request attribute under which the original
context path is made available to the target of a
| |
| ASYNC_MAPPING | back to summary |
|---|---|
| public static final String ASYNC_MAPPING The name of the request attribute under which the original
| |
| ASYNC_PATH_INFO | back to summary |
|---|---|
| public static final String ASYNC_PATH_INFO The name of the request attribute under which the original
path info is made available to the target of a
| |
| ASYNC_QUERY_STRING | back to summary |
|---|---|
| public static final String ASYNC_QUERY_STRING The name of the request attribute under which the original
query string is made available to the target of a
| |
| ASYNC_REQUEST_URI | back to summary |
|---|---|
| public static final String ASYNC_REQUEST_URI The name of the request attribute under which the original
request URI is made available to the target of a
| |
| ASYNC_SERVLET_PATH | back to summary |
|---|---|
| public static final String ASYNC_SERVLET_PATH The name of the request attribute under which the original
servlet path is made available to the target of a
| |
| addListener | back to summary |
|---|---|
| public void addListener(AsyncListener listener) Registers the given The given AsyncListener will receive an AsyncListener instances will be notified in the order in which they were added. If
| |
| addListener | back to summary |
|---|---|
| public void addListener(AsyncListener listener, ServletRequest servletRequest, ServletResponse servletResponse) Registers the given The given AsyncListener will receive an AsyncListener instances will be notified in the order in which they were added. The given ServletRequest and ServletResponse objects will
be made available to the given AsyncListener via the
| |
| complete | back to summary |
|---|---|
| public void complete() Completes the asynchronous operation that was started on the request that was used to initialze this AsyncContext, closing the response that was used to initialize this AsyncContext. Any listeners of type It is legal to call this method any time after a call to
| |
| createListener | back to summary |
|---|---|
| public <T extends AsyncListener> T createListener(Class<T> clazz) throws ServletException Instantiates the given The returned AsyncListener instance may be further customized
before it is registered with this AsyncContext via a call to one of
the The given AsyncListener class must define a zero argument constructor, which is used to instantiate it. This method supports resource injection if the given clazz represents a Managed Bean. See the Java EE platform and JSR 299 specifications for additional details about Managed Beans and resource injection. This method supports any annotations applicable to AsyncListener.
| |
| dispatch | back to summary |
|---|---|
| public void dispatch() Dispatches the request and response objects of this AsyncContext to the servlet container. If the asynchronous cycle was started with
The following sequence illustrates how this will work:
This method returns immediately after passing the request and response objects to a container managed thread, on which the dispatch operation will be performed. If this method is called before the container-initiated dispatch that called startAsync has returned to the container, the dispatch operation will be delayed until after the container-initiated dispatch has returned to the container. The dispatcher type of the request is set to
DispatcherType.ASYNC. Unlike
Control over the request and response is delegated
to the dispatch target, and the response will be closed when the
dispatch target has completed execution, unless
Any errors or exceptions that may occur during the execution of this method must be caught and handled by the container, as follows:
There can be at most one asynchronous dispatch operation per
asynchronous cycle, which is started by a call to one of the
| |
| dispatch | back to summary |
|---|---|
| public void dispatch(String path) Dispatches the request and response objects of this AsyncContext to the given path. The path parameter is interpreted in the same way
as in All path related query methods of the request must reflect the
dispatch target, while the original request URI, context path,
path info, servlet path, and query string may be recovered from
the There can be at most one asynchronous dispatch operation per
asynchronous cycle, which is started by a call to one of the
See
| |
| dispatch | back to summary |
|---|---|
| public void dispatch(ServletContext context, String path) Dispatches the request and response objects of this AsyncContext to the given path scoped to the given context. The path parameter is interpreted in the same way
as in All path related query methods of the request must reflect the
dispatch target, while the original request URI, context path,
path info, servlet path, and query string may be recovered from
the There can be at most one asynchronous dispatch operation per
asynchronous cycle, which is started by a call to one of the
See
| |
| getRequest | back to summary |
|---|---|
| public ServletRequest getRequest() Gets the request that was used to initialize this AsyncContext
by calling
| |
| getResponse | back to summary |
|---|---|
| public ServletResponse getResponse() Gets the response that was used to initialize this AsyncContext
by calling
| |
| getTimeout | back to summary |
|---|---|
| public long getTimeout() Gets the timeout (in milliseconds) for this AsyncContext. This method returns the container's default timeout for
asynchronous operations, or the timeout value passed to the most
recent invocation of A timeout value of zero or less indicates no timeout.
| |
| hasOriginalRequestAndResponse | back to summary |
|---|---|
| public boolean hasOriginalRequestAndResponse() Checks if this AsyncContext was initialized with the original or application-wrapped request and response objects. This information may be used by filters invoked in the outbound direction, after a request was put into asynchronous mode, to determine whether any request and/or response wrappers that they added during their inbound invocation need to be preserved for the duration of the asynchronous operation, or may be released.
| |
| setTimeout | back to summary |
|---|---|
| public void setTimeout(long timeout) Sets the timeout (in milliseconds) for this AsyncContext. The timeout applies to this AsyncContext once the
container-initiated dispatch during which one of the
The timeout will expire if neither the If The default value is
| |
| start | back to summary |
|---|---|
| public void start(Runnable run) Causes the container to dispatch a thread, possibly from a managed thread pool, to run the specified Runnable. The container may propagate appropriate contextual information to the Runnable.
| |