|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.catalina.connector.Request.AsyncContextImpl
public class Request.AsyncContextImpl
Field Summary | |
---|---|
protected boolean |
original
|
protected java.lang.String |
path
|
protected boolean |
ready
|
protected java.lang.Runnable |
runnable
|
protected javax.servlet.ServletContext |
servletContext
|
protected javax.servlet.ServletRequest |
servletRequest
|
protected javax.servlet.ServletResponse |
servletResponse
|
protected boolean |
useAttributes
|
Fields inherited from interface javax.servlet.AsyncContext |
---|
ASYNC_CONTEXT_PATH, ASYNC_PATH_INFO, ASYNC_QUERY_STRING, ASYNC_REQUEST_URI, ASYNC_SERVLET_PATH |
Constructor Summary | |
---|---|
Request.AsyncContextImpl()
|
Method Summary | ||
---|---|---|
void |
addListener(javax.servlet.AsyncListener listener)
Registers the given AsyncListener with the most recent
asynchronous cycle that was started by a call to one of the
ServletRequest.startAsync() methods. |
|
void |
addListener(javax.servlet.AsyncListener listener,
javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse)
Registers the given AsyncListener with the most recent
asynchronous cycle that was started by a call to one of the
ServletRequest.startAsync() methods. |
|
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. |
|
|
createListener(java.lang.Class<T> clazz)
Instantiates the given AsyncListener class. |
|
void |
dispatch()
Dispatches the request and response objects of this AsyncContext to the servlet container. |
|
void |
dispatch(javax.servlet.ServletContext servletContext,
java.lang.String path)
Dispatches the request and response objects of this AsyncContext to the given path scoped to the given context. |
|
void |
dispatch(java.lang.String path)
Dispatches the request and response objects of this AsyncContext to the given path. |
|
void |
done()
|
|
java.util.Map<javax.servlet.AsyncListener,Request.AsyncListenerRegistration> |
getAsyncListeners()
|
|
java.lang.String |
getPath()
|
|
javax.servlet.ServletRequest |
getRequest()
Gets the request that was used to initialize this AsyncContext by calling ServletRequest.startAsync() or
ServletRequest.startAsync(ServletRequest, ServletResponse) . |
|
javax.servlet.ServletResponse |
getResponse()
Gets the response that was used to initialize this AsyncContext by calling ServletRequest.startAsync() or
ServletRequest.startAsync(ServletRequest, ServletResponse) . |
|
java.lang.Runnable |
getRunnable()
|
|
javax.servlet.ServletContext |
getServletContext()
|
|
long |
getTimeout()
Gets the timeout (in milliseconds) for this AsyncContext. |
|
boolean |
getUseAttributes()
|
|
boolean |
hasOriginalRequestAndResponse()
Checks if this AsyncContext was initialized with the original or application-wrapped request and response objects. |
|
boolean |
isReady()
|
|
void |
reset()
|
|
void |
setRequestAndResponse(javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse)
|
|
void |
setTimeout(long timeout)
Sets the timeout (in milliseconds) for this AsyncContext. |
|
void |
start(java.lang.Runnable runnable)
Causes the container to dispatch a thread, possibly from a managed thread pool, to run the specified Runnable. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected javax.servlet.ServletRequest servletRequest
protected javax.servlet.ServletResponse servletResponse
protected javax.servlet.ServletContext servletContext
protected java.lang.String path
protected java.lang.Runnable runnable
protected boolean useAttributes
protected boolean original
protected boolean ready
Constructor Detail |
---|
public Request.AsyncContextImpl()
Method Detail |
---|
public void complete()
javax.servlet.AsyncContext
Any listeners of type AsyncListener
that were registered
with the ServletRequest for which this AsyncContext was created will
be invoked at their onComplete
method.
It is legal to call this method any time after a call to
ServletRequest.startAsync()
or
ServletRequest.startAsync(ServletRequest, ServletResponse)
,
and before a call to one of the dispatch methods
of this class.
If this method is called before the container-initiated dispatch
that called startAsync has returned to the container, then
the call will not take effect (and any invocations of
AsyncListener.onComplete(AsyncEvent)
will be delayed) until
after the container-initiated dispatch has returned to the container.
complete
in interface javax.servlet.AsyncContext
public void dispatch()
javax.servlet.AsyncContext
If the asynchronous cycle was started with
ServletRequest.startAsync(ServletRequest, ServletResponse)
,
and the request passed is an instance of HttpServletRequest,
then the dispatch is to the URI returned by
HttpServletRequest.getRequestURI()
.
Otherwise, the dispatch is to the URI of the request when it was
last dispatched by the container.
The following sequence illustrates how this will work:
// REQUEST dispatch to /url/A
AsyncContext ac = request.startAsync();
...
ac.dispatch(); // ASYNC dispatch to /url/A
// FORWARD dispatch to /url/B
getRequestDispatcher("/url/B").forward(request,response);
// Start async operation from within the target of the FORWARD
// dispatch
ac = request.startAsync();
...
ac.dispatch(); // ASYNC dispatch to /url/A
// FORWARD dispatch to /url/B
getRequestDispatcher("/url/B").forward(request,response);
// Start async operation from within the target of the FORWARD
// dispatch
ac = request.startAsync(request,response);
...
ac.dispatch(); // ASYNC dispatch to /url/B
This method returns immediately after passing the request and response objects to a container managed thread, on which the dispatch operation will be performed.
The dispatcher type of the request is set to
DispatcherType.ASYNC. Unlike
forward dispatches
, the response buffer and
headers will not be reset, and it is legal to dispatch even if the
response has already been committed.
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
ServletRequest.startAsync()
or
ServletRequest.startAsync(ServletRequest, ServletResponse)
are called.
Any errors or exceptions that may occur during the execution of this method must be caught and handled by the container, as follows:
onError
method, all
AsyncListener
instances registered with the ServletRequest
for which this AsyncContext was created, and make the caught
Throwable available via AsyncEvent.getThrowable()
.AsyncContext.complete()
or any of the
AsyncContext.dispatch()
methods, perform an error dispatch with a status code
equal to HttpServletResponse.SC_INTERNAL_SERVER_ERROR, and
make the above Throwable available as the value of the
RequestDispatcher.ERROR_EXCEPTION request attribute.AsyncContext.complete()
or any of the AsyncContext.dispatch()
methods, call
AsyncContext.complete()
.There can be at most one asynchronous dispatch operation per
asynchronous cycle, which is started by a call to one of the
ServletRequest.startAsync()
methods. Any attempt to perform an
additional asynchronous dispatch operation within the same
asynchronous cycle will result in an IllegalStateException.
If startAsync is subsequently called on the dispatched request,
then any of the dispatch or AsyncContext.complete()
methods may be called.
dispatch
in interface javax.servlet.AsyncContext
ServletRequest.getDispatcherType()
public void dispatch(java.lang.String path)
javax.servlet.AsyncContext
The path parameter is interpreted in the same way
as in ServletRequest.getRequestDispatcher(String)
, within
the scope of the ServletContext
from which this
AsyncContext was initialized.
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 AsyncContext.ASYNC_REQUEST_URI
, AsyncContext.ASYNC_CONTEXT_PATH
,
AsyncContext.ASYNC_PATH_INFO
, AsyncContext.ASYNC_SERVLET_PATH
, and
AsyncContext.ASYNC_QUERY_STRING
attributes of the request. These
attributes will always reflect the original path elements, even under
repeated dispatches.
There can be at most one asynchronous dispatch operation per
asynchronous cycle, which is started by a call to one of the
ServletRequest.startAsync()
methods. Any attempt to perform an
additional asynchronous dispatch operation within the same
asynchronous cycle will result in an IllegalStateException.
If startAsync is subsequently called on the dispatched request,
then any of the dispatch or AsyncContext.complete()
methods may be called.
See AsyncContext.dispatch()
for additional details, including error
handling.
dispatch
in interface javax.servlet.AsyncContext
path
- the path of the dispatch target, scoped to the
ServletContext from which this AsyncContext was initializedServletRequest.getDispatcherType()
public void dispatch(javax.servlet.ServletContext servletContext, java.lang.String path)
javax.servlet.AsyncContext
The path parameter is interpreted in the same way
as in ServletRequest.getRequestDispatcher(String)
, except that
it is scoped to the given context.
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 AsyncContext.ASYNC_REQUEST_URI
, AsyncContext.ASYNC_CONTEXT_PATH
,
AsyncContext.ASYNC_PATH_INFO
, AsyncContext.ASYNC_SERVLET_PATH
, and
AsyncContext.ASYNC_QUERY_STRING
attributes of the request. These
attributes will always reflect the original path elements, even under
repeated dispatches.
There can be at most one asynchronous dispatch operation per
asynchronous cycle, which is started by a call to one of the
ServletRequest.startAsync()
methods. Any attempt to perform an
additional asynchronous dispatch operation within the same
asynchronous cycle will result in an IllegalStateException.
If startAsync is subsequently called on the dispatched request,
then any of the dispatch or AsyncContext.complete()
methods may be called.
See AsyncContext.dispatch()
for additional details, including error
handling.
dispatch
in interface javax.servlet.AsyncContext
servletContext
- the ServletContext of the dispatch targetpath
- the path of the dispatch target, scoped to the given
ServletContextServletRequest.getDispatcherType()
public javax.servlet.ServletRequest getRequest()
javax.servlet.AsyncContext
ServletRequest.startAsync()
or
ServletRequest.startAsync(ServletRequest, ServletResponse)
.
getRequest
in interface javax.servlet.AsyncContext
public javax.servlet.ServletResponse getResponse()
javax.servlet.AsyncContext
ServletRequest.startAsync()
or
ServletRequest.startAsync(ServletRequest, ServletResponse)
.
getResponse
in interface javax.servlet.AsyncContext
public boolean hasOriginalRequestAndResponse()
javax.servlet.AsyncContext
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.
hasOriginalRequestAndResponse
in interface javax.servlet.AsyncContext
ServletRequest.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 otherwisepublic void start(java.lang.Runnable runnable)
javax.servlet.AsyncContext
start
in interface javax.servlet.AsyncContext
runnable
- the asynchronous handlerpublic boolean isReady()
public void done()
public void setRequestAndResponse(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)
public javax.servlet.ServletContext getServletContext()
public java.lang.String getPath()
public boolean getUseAttributes()
public java.lang.Runnable getRunnable()
public void reset()
public java.util.Map<javax.servlet.AsyncListener,Request.AsyncListenerRegistration> getAsyncListeners()
public void addListener(javax.servlet.AsyncListener listener, javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)
javax.servlet.AsyncContext
AsyncListener
with the most recent
asynchronous cycle that was started by a call to one of the
ServletRequest.startAsync()
methods.
The given AsyncListener will receive an AsyncEvent
when
the asynchronous cycle completes successfully, times out, or results
in an error.
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
getSuppliedRequest
and
getSuppliedResponse
methods,
respectively, of the AsyncEvent
delivered to it. These objects
should not be read from or written to, respectively, at the time the
AsyncEvent is delivered, because additional wrapping may have
occurred since the given AsyncListener was registered, but may be used
in order to release any resources associated with them.
addListener
in interface javax.servlet.AsyncContext
listener
- the AsyncListener to be registeredservletRequest
- the ServletRequest that will be included
in the AsyncEventservletResponse
- the ServletResponse that will be included
in the AsyncEventpublic void addListener(javax.servlet.AsyncListener listener)
javax.servlet.AsyncContext
AsyncListener
with the most recent
asynchronous cycle that was started by a call to one of the
ServletRequest.startAsync()
methods.
The given AsyncListener will receive an AsyncEvent
when
the asynchronous cycle completes successfully, times out, or results
in an error.
AsyncListener instances will be notified in the order in which they were added.
addListener
in interface javax.servlet.AsyncContext
listener
- the AsyncListener to be registeredpublic long getTimeout()
javax.servlet.AsyncContext
This method returns the container's default timeout for
asynchronous operations, or the timeout value passed to the most
recent invocation of AsyncContext.setTimeout(long)
.
A timeout value of zero or less indicates no timeout.
getTimeout
in interface javax.servlet.AsyncContext
public void setTimeout(long timeout)
javax.servlet.AsyncContext
The timeout applies to this AsyncContext once the
container-initiated dispatch during which one of the
ServletRequest.startAsync()
methods was called has
returned to the container.
The timeout will expire if neither the AsyncContext.complete()
method
nor any of the dispatch methods are called. A timeout value of
zero or less indicates no timeout.
If AsyncContext.setTimeout(long)
is not called, then the container's
default timeout, which is available via a call to
AsyncContext.getTimeout()
, will apply.
setTimeout
in interface javax.servlet.AsyncContext
timeout
- the timeout in millisecondspublic <T extends javax.servlet.AsyncListener> T createListener(java.lang.Class<T> clazz) throws javax.servlet.ServletException
javax.servlet.AsyncContext
AsyncListener
class.
The returned AsyncListener instance may be further customized
before it is registered with this AsyncContext via a call to one of
the addListener
methods.
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.
createListener
in interface javax.servlet.AsyncContext
clazz
- the AsyncListener class to instantiate
javax.servlet.ServletException
- if the given clazz fails to be
instantiated
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |