Top Description Fields Methods
jakarta.servlet

public Interface AsyncContext

Known Direct Implementers
org.apache.catalina.core.AsyncContextImpl

Provides the context for asynchronous request handling
Since
Servlet 3.0

Field Summary

Modifier and TypeField and Description
public static final String
ASYNC_CONTEXT_PATH

The attribute name for the Context Path of the async request

public static final String
ASYNC_MAPPING

The attribute name for the Mapping of the async request

public static final String
ASYNC_PATH_INFO

The attribute name for the Path Info of the async request

public static final String
ASYNC_QUERY_STRING

The attribute name for the Query String of the async request

public static final String
ASYNC_REQUEST_URI

The attribute name for the URI of the async request

public static final String
ASYNC_SERVLET_PATH

The attribute name for the Servlet Path of the async request

Method Summary

Modifier and TypeMethod and Description
public void
addListener(AsyncListener
an AsyncListener that will be called with AsyncEvent objects
listener
)

Adds an event listener that will be called for different AsyncEvents fire

public void
addListener(AsyncListener
an AsyncListener that will be called with AsyncEvent objects
listener
,
ServletRequest
the ServletRequest that will be passed with the AsyncEvent
request
,
ServletResponse
the ServletResponse that will be passed with the AsyncEvent
response
)

Adds an event listener that will be called when different AsyncEvents fire

public void
complete()

Completes the async request processing and closes the response stream

public <
The type to create that extends AsyncListener
T extends AsyncListener
>
T

Returns:

the newly created AsyncListener object
createListener
(Class<T>
The class to instantiate to create the listener
clazz
)

Creates and returns an AsyncListener object

public void
public void
dispatch(String
The path to which the request/response should be dispatched relative to the ServletContext from which this async request was started.
path
)

public void
dispatch(ServletContext
The ServletContext to which the request/response should be dispatched.
context
,
String
The path to which the request/response should be dispatched relative to the specified ServletContext.
path
)

public ServletRequest

Returns:

a reference to the ServletRequest object
getRequest
()

public ServletResponse

Returns:

a reference to the ServletResponse object
getResponse
()

public long

Returns:

The timeout in milliseconds. 0 or less indicates no timeout.
getTimeout
()

Get the current timeout.

public boolean

Returns:

true if the Request and Response are the original ones
hasOriginalRequestAndResponse
()

public void
setTimeout(long
The timeout in milliseconds. 0 or less indicates no timeout.
timeout
)

Set the timeout.

public void
start(Runnable
a Runnable that the new thread will run
run
)

Starts a new thread to process the asynchronous request

Field Detail

ASYNC_CONTEXT_PATHback to summary
public static final String ASYNC_CONTEXT_PATH

The attribute name for the Context Path of the async request

ASYNC_MAPPINGback to summary
public static final String ASYNC_MAPPING

The attribute name for the Mapping of the async request

ASYNC_PATH_INFOback to summary
public static final String ASYNC_PATH_INFO

The attribute name for the Path Info of the async request

ASYNC_QUERY_STRINGback to summary
public static final String ASYNC_QUERY_STRING

The attribute name for the Query String of the async request

ASYNC_REQUEST_URIback to summary
public static final String ASYNC_REQUEST_URI

The attribute name for the URI of the async request

ASYNC_SERVLET_PATHback to summary
public static final String ASYNC_SERVLET_PATH

The attribute name for the Servlet Path of the async request

Method Detail

addListenerback to summary
public void addListener(AsyncListener listener)

Adds an event listener that will be called for different AsyncEvents fire

Parameters
listener:AsyncListener

an AsyncListener that will be called with AsyncEvent objects

addListenerback to summary
public void addListener(AsyncListener listener, ServletRequest request, ServletResponse response)

Adds an event listener that will be called when different AsyncEvents fire

Parameters
listener:AsyncListener

an AsyncListener that will be called with AsyncEvent objects

request:ServletRequest

the ServletRequest that will be passed with the AsyncEvent

response:ServletResponse

the ServletResponse that will be passed with the AsyncEvent

completeback to summary
public void complete()

Completes the async request processing and closes the response stream

createListenerback to summary
public <T extends AsyncListener> T createListener(Class<T> clazz) throws ServletException

Creates and returns an AsyncListener object

Parameters
<T>
The type to create that extends AsyncListener
clazz:Class<T>

The class to instantiate to create the listener

Returns:T

the newly created AsyncListener object

Exceptions
ServletException:
if the listener cannot be created
dispatchback to summary
public void dispatch()
Exceptions
IllegalStateException:
if this method is called when the request is not in asynchronous mode. The request is in asynchronous mode after jakarta.servlet.http.HttpServletRequest#startAsync() or jakarta.servlet.http.HttpServletRequest#startAsync(ServletRequest, ServletResponse) has been called and before complete() or any other dispatch() method has been called.
dispatchback to summary
public void dispatch(String path)
Parameters
path:String

The path to which the request/response should be dispatched relative to the ServletContext from which this async request was started.

Exceptions
IllegalStateException:
if this method is called when the request is not in asynchronous mode. The request is in asynchronous mode after jakarta.servlet.http.HttpServletRequest#startAsync() or jakarta.servlet.http.HttpServletRequest#startAsync(ServletRequest, ServletResponse) has been called and before complete() or any other dispatch() method has been called.
dispatchback to summary
public void dispatch(ServletContext context, String path)
Parameters
context:ServletContext

The ServletContext to which the request/response should be dispatched.

path:String

The path to which the request/response should be dispatched relative to the specified ServletContext.

Exceptions
IllegalStateException:
if this method is called when the request is not in asynchronous mode. The request is in asynchronous mode after jakarta.servlet.http.HttpServletRequest#startAsync() or jakarta.servlet.http.HttpServletRequest#startAsync(ServletRequest, ServletResponse) has been called and before complete() or any other dispatch() method has been called.
getRequestback to summary
public ServletRequest getRequest()
Returns:ServletRequest

a reference to the ServletRequest object

getResponseback to summary
public ServletResponse getResponse()
Returns:ServletResponse

a reference to the ServletResponse object

getTimeoutback to summary
public long getTimeout()

Get the current timeout.

Returns:long

The timeout in milliseconds. 0 or less indicates no timeout.

hasOriginalRequestAndResponseback to summary
public boolean hasOriginalRequestAndResponse()
Returns:boolean

true if the Request and Response are the original ones

setTimeoutback to summary
public void setTimeout(long timeout)

Set the timeout.

Parameters
timeout:long

The timeout in milliseconds. 0 or less indicates no timeout.

startback to summary
public void start(Runnable run)

Starts a new thread to process the asynchronous request

Parameters
run:Runnable

a Runnable that the new thread will run