Top Description Inners Fields Constructors Methods
org.apache.catalina.core

pack-priv final Class ApplicationDispatcher

extends Object
implements AsyncDispatcher, RequestDispatcher
Class Inheritance
All Implemented Interfaces
jakarta.servlet.RequestDispatcher, org.apache.catalina.AsyncDispatcher
Imports
java.io.IOException, .PrintWriter, java.security.AccessController, .PrivilegedActionException, .PrivilegedExceptionAction, jakarta.servlet.AsyncContext, .DispatcherType, .RequestDispatcher, .Servlet, .ServletException, .ServletOutputStream, .ServletRequest, .ServletRequestWrapper, .ServletResponse, .ServletResponseWrapper, .UnavailableException, jakarta.servlet.http.HttpServletMapping, .HttpServletRequest, .HttpServletResponse, org.apache.catalina.AsyncDispatcher, .Context, .Globals, .Wrapper, org.apache.catalina.connector.Request, .RequestFacade, .Response, .ResponseFacade, org.apache.coyote.BadRequestException, org.apache.tomcat.util.ExceptionUtils, org.apache.tomcat.util.res.StringManager

Standard implementation of RequestDispatcher that allows a request to be forwarded to a different resource to create the ultimate response, or to include the output of another resource in the response from this resource. This implementation allows application level servlets to wrap the request and/or response objects that are passed on to the called resource, as long as the wrapping classes extend jakarta.servlet.ServletRequestWrapper and jakarta.servlet.ServletResponseWrapper.
Author
Craig R. McClanahan

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
protected class
protected class
private static class
ApplicationDispatcher.State

Used to pass state when the request dispatcher is used.

Field Summary

Modifier and TypeField and Description
private final Context
context

The Context this RequestDispatcher is associated with.

private final HttpServletMapping
mapping

The mapping for this RequestDispatcher.

private final String
name

The servlet name for a named dispatcher.

private final String
pathInfo

The extra path information for this RequestDispatcher.

private final String
queryString

The query string parameters for this RequestDispatcher.

private final String
requestURI

The request URI for this RequestDispatcher.

private final String
servletPath

The servlet path for this RequestDispatcher.

private static final StringManager
sm

The StringManager for this package.

private final Wrapper
wrapper

The Wrapper associated with the resource that will be forwarded to or included.

Constructor Summary

AccessConstructor and Description
pack-priv
ApplicationDispatcher(Wrapper
The Wrapper associated with the resource that will be forwarded to or included (required)
wrapper
,
String
The request URI to this resource (if any)
requestURI
,
String
The revised servlet path to this resource (if any)
servletPath
,
String
The revised extra path information to this resource (if any)
pathInfo
,
String
Query string parameters included with this request (if any)
queryString
,
HttpServletMapping
The mapping for this resource (if any)
mapping
,
String
Servlet name (if a named dispatcher was created) else null
name
)

Construct a new instance of this class, configured according to the specified parameters.

Method Summary

Modifier and TypeMethod and Description
private void
public void
dispatch(ServletRequest
The request object to pass to the dispatch target
request
,
ServletResponse
The response object to pass to the dispatch target
response
)

Implements org.apache.catalina.AsyncDispatcher.dispatch.

Perform an asynchronous dispatch.

private void
private void
private void
public void
forward(ServletRequest
The servlet request to be forwarded
request
,
ServletResponse
The servlet response to be forwarded
response
)

Implements jakarta.servlet.RequestDispatcher.forward.

Forward this request and response to another resource for processing.

private String

Returns:

The combined path with pathInfo appended to servletInfo
getCombinedPath
()

Combine the servletPath and the pathInfo.

public void
include(ServletRequest
The servlet request that is including this one
request
,
ServletResponse
The servlet response to be appended to
response
)

Implements jakarta.servlet.RequestDispatcher.include.

Include the response from another resource in the current response.

private void
invoke(ServletRequest
The servlet request we are processing
request
,
ServletResponse
The servlet response we are creating
response
,
ApplicationDispatcher.State state)

Ask the resource represented by this RequestDispatcher to process the associated request, and create (or append to) the associated response.

private void
processRequest(ServletRequest
The servlet request we are processing
request
,
ServletResponse
The servlet response we are creating
response
,
ApplicationDispatcher.State
The RD state
state
)

Prepare the request based on the filter configuration.

private void
private void
unwrapRequest(ApplicationDispatcher.State state)

Unwrap the request if we have wrapped it.

private void
unwrapResponse(ApplicationDispatcher.State state)

Unwrap the response if we have wrapped it.

private ServletRequest
wrapRequest(ApplicationDispatcher.State state)

Create and return a request wrapper that has been inserted in the appropriate spot in the request chain.

private ServletResponse
wrapResponse(ApplicationDispatcher.State state)

Create and return a response wrapper that has been inserted in the appropriate spot in the response chain.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
private final Context context

The Context this RequestDispatcher is associated with.

mappingback to summary
private final HttpServletMapping mapping

The mapping for this RequestDispatcher.

nameback to summary
private final String name

The servlet name for a named dispatcher.

pathInfoback to summary
private final String pathInfo

The extra path information for this RequestDispatcher.

queryStringback to summary
private final String queryString

The query string parameters for this RequestDispatcher.

requestURIback to summary
private final String requestURI

The request URI for this RequestDispatcher.

servletPathback to summary
private final String servletPath

The servlet path for this RequestDispatcher.

smback to summary
private static final StringManager sm

The StringManager for this package.

wrapperback to summary
private final Wrapper wrapper

The Wrapper associated with the resource that will be forwarded to or included.

Constructor Detail

ApplicationDispatcherback to summary
pack-priv ApplicationDispatcher(Wrapper wrapper, String requestURI, String servletPath, String pathInfo, String queryString, HttpServletMapping mapping, String name)

Construct a new instance of this class, configured according to the specified parameters. If both servletPath and pathInfo are null, it will be assumed that this RequestDispatcher was acquired by name, rather than by path.

Parameters
wrapper:Wrapper

The Wrapper associated with the resource that will be forwarded to or included (required)

requestURI:String

The request URI to this resource (if any)

servletPath:String

The revised servlet path to this resource (if any)

pathInfo:String

The revised extra path information to this resource (if any)

queryString:String

Query string parameters included with this request (if any)

mapping:HttpServletMapping

The mapping for this resource (if any)

name:String

Servlet name (if a named dispatcher was created) else null

Method Detail

checkSameObjectsback to summary
private void checkSameObjects(ServletRequest appRequest, ServletResponse appResponse) throws ServletException
dispatchback to summary
public void dispatch(ServletRequest request, ServletResponse response) throws ServletException, IOException

Implements org.apache.catalina.AsyncDispatcher.dispatch.

Doc from org.apache.catalina.AsyncDispatcher.dispatch.

Perform an asynchronous dispatch. The method does not check if the request is in an appropriate state for this; it is the caller's responsibility to check this.

Parameters
request:ServletRequest

The request object to pass to the dispatch target

response:ServletResponse

The response object to pass to the dispatch target

Annotations
@Override
Exceptions
ServletException:
if thrown by the dispatch target
IOException:
if an I/O error occurs while processing the dispatch
doDispatchback to summary
private void doDispatch(ServletRequest request, ServletResponse response) throws ServletException, IOException
doForwardback to summary
private void doForward(ServletRequest request, ServletResponse response) throws ServletException, IOException
doIncludeback to summary
private void doInclude(ServletRequest request, ServletResponse response) throws ServletException, IOException
forwardback to summary
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException

Implements jakarta.servlet.RequestDispatcher.forward.

Forward this request and response to another resource for processing. Any runtime exception, IOException, or ServletException thrown by the called servlet will be propagated to the caller.

Parameters
request:ServletRequest

The servlet request to be forwarded

response:ServletResponse

The servlet response to be forwarded

Annotations
@Override
Exceptions
ServletException:
if a servlet exception occurs
IOException:
if an input/output error occurs
getCombinedPathback to summary
private String getCombinedPath()

Combine the servletPath and the pathInfo. If pathInfo is null it is ignored. If servletPath is null then null is returned.

Returns:String

The combined path with pathInfo appended to servletInfo

includeback to summary
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException

Implements jakarta.servlet.RequestDispatcher.include.

Include the response from another resource in the current response. Any runtime exception, IOException, or ServletException thrown by the called servlet will be propagated to the caller.

Parameters
request:ServletRequest

The servlet request that is including this one

response:ServletResponse

The servlet response to be appended to

Annotations
@Override
Exceptions
ServletException:
if a servlet exception occurs
IOException:
if an input/output error occurs
invokeback to summary
private void invoke(ServletRequest request, ServletResponse response, ApplicationDispatcher.State state) throws IOException, ServletException

Ask the resource represented by this RequestDispatcher to process the associated request, and create (or append to) the associated response.

Implementation Note

This implementation assumes that no filters are applied to a forwarded or included resource, because they were already done for the original request.

Parameters
request:ServletRequest

The servlet request we are processing

response:ServletResponse

The servlet response we are creating

Exceptions
IOException:
if an input/output error occurs
ServletException:
if a servlet error occurs
processRequestback to summary
private void processRequest(ServletRequest request, ServletResponse response, ApplicationDispatcher.State state) throws IOException, ServletException

Prepare the request based on the filter configuration.

Parameters
request:ServletRequest

The servlet request we are processing

response:ServletResponse

The servlet response we are creating

state:ApplicationDispatcher.State

The RD state

Exceptions
IOException:
if an input/output error occurs
ServletException:
if a servlet error occurs
recycleRequestWrapperback to summary
private void recycleRequestWrapper(ApplicationDispatcher.State state)
unwrapRequestback to summary
private void unwrapRequest(ApplicationDispatcher.State state)

Unwrap the request if we have wrapped it.

unwrapResponseback to summary
private void unwrapResponse(ApplicationDispatcher.State state)

Unwrap the response if we have wrapped it.

wrapRequestback to summary
private ServletRequest wrapRequest(ApplicationDispatcher.State state)

Create and return a request wrapper that has been inserted in the appropriate spot in the request chain.

wrapResponseback to summary
private ServletResponse wrapResponse(ApplicationDispatcher.State state)

Create and return a response wrapper that has been inserted in the appropriate spot in the response chain.

org.apache.catalina.core back to summary

protected Class ApplicationDispatcher.PrivilegedDispatch

extends Object
implements PrivilegedExceptionAction<Void>
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.core.ApplicationDispatcher.PrivilegedDispatch
All Implemented Interfaces
java.security.PrivilegedExceptionAction

Field Summary

Modifier and TypeField and Description
private final ServletRequest
private final ServletResponse

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Void
run()

Implements java.security.PrivilegedExceptionAction.run.

Performs the computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

requestback to summary
private final ServletRequest request
responseback to summary
private final ServletResponse response

Constructor Detail

PrivilegedDispatchback to summary
pack-priv PrivilegedDispatch(ServletRequest request, ServletResponse response)

Method Detail

runback to summary
public Void run() throws ServletException, IOException

Implements java.security.PrivilegedExceptionAction.run.

Doc from java.security.PrivilegedExceptionAction.run.

Performs the computation. This method will be called by AccessController.doPrivileged after enabling privileges.

Returns:Void

a class-dependent value that may represent the results of the computation. Each class that implements PrivilegedExceptionAction should document what (if anything) this value represents.

Annotations
@Override
org.apache.catalina.core back to summary

protected Class ApplicationDispatcher.PrivilegedForward

extends Object
implements PrivilegedExceptionAction<Void>
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.core.ApplicationDispatcher.PrivilegedForward
All Implemented Interfaces
java.security.PrivilegedExceptionAction

Field Summary

Modifier and TypeField and Description
private final ServletRequest
private final ServletResponse

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Void
run()

Implements java.security.PrivilegedExceptionAction.run.

Performs the computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

requestback to summary
private final ServletRequest request
responseback to summary
private final ServletResponse response

Constructor Detail

PrivilegedForwardback to summary
pack-priv PrivilegedForward(ServletRequest request, ServletResponse response)

Method Detail

runback to summary
public Void run() throws Exception

Implements java.security.PrivilegedExceptionAction.run.

Doc from java.security.PrivilegedExceptionAction.run.

Performs the computation. This method will be called by AccessController.doPrivileged after enabling privileges.

Returns:Void

a class-dependent value that may represent the results of the computation. Each class that implements PrivilegedExceptionAction should document what (if anything) this value represents.

Annotations
@Override
Exceptions
Exception:
an exceptional condition has occurred. Each class that implements PrivilegedExceptionAction should document the exceptions that its run method can throw.
org.apache.catalina.core back to summary

protected Class ApplicationDispatcher.PrivilegedInclude

extends Object
implements PrivilegedExceptionAction<Void>
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.core.ApplicationDispatcher.PrivilegedInclude
All Implemented Interfaces
java.security.PrivilegedExceptionAction

Field Summary

Modifier and TypeField and Description
private final ServletRequest
private final ServletResponse

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Void
run()

Implements java.security.PrivilegedExceptionAction.run.

Performs the computation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

requestback to summary
private final ServletRequest request
responseback to summary
private final ServletResponse response

Constructor Detail

PrivilegedIncludeback to summary
pack-priv PrivilegedInclude(ServletRequest request, ServletResponse response)

Method Detail

runback to summary
public Void run() throws ServletException, IOException

Implements java.security.PrivilegedExceptionAction.run.

Doc from java.security.PrivilegedExceptionAction.run.

Performs the computation. This method will be called by AccessController.doPrivileged after enabling privileges.

Returns:Void

a class-dependent value that may represent the results of the computation. Each class that implements PrivilegedExceptionAction should document what (if anything) this value represents.

Annotations
@Override
org.apache.catalina.core back to summary

private Class ApplicationDispatcher.State

extends Object
Class Inheritance

Used to pass state when the request dispatcher is used. Using instance variables causes threading issues and state is too complex to pass and return single ServletRequest or ServletResponse objects.

Field Summary

Modifier and TypeField and Description
pack-priv HttpServletRequest
hrequest

Outermost HttpServletRequest in the chain

pack-priv HttpServletResponse
hresponse

Outermost HttpServletResponse in the chain

pack-priv boolean
including

Are we performing an include() instead of a forward()?

pack-priv ServletRequest
outerRequest

The outermost request that will be passed on to the invoked servlet.

pack-priv ServletResponse
outerResponse

The outermost response that will be passed on to the invoked servlet.

pack-priv ServletRequest
wrapRequest

The request wrapper we have created and installed (if any).

pack-priv ServletResponse
wrapResponse

The response wrapper we have created and installed (if any).

Constructor Summary

AccessConstructor and Description
pack-priv
State(ServletRequest request, ServletResponse response, boolean including)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

hrequestback to summary
pack-priv HttpServletRequest hrequest

Outermost HttpServletRequest in the chain

hresponseback to summary
pack-priv HttpServletResponse hresponse

Outermost HttpServletResponse in the chain

includingback to summary
pack-priv boolean including

Are we performing an include() instead of a forward()?

outerRequestback to summary
pack-priv ServletRequest outerRequest

The outermost request that will be passed on to the invoked servlet.

outerResponseback to summary
pack-priv ServletResponse outerResponse

The outermost response that will be passed on to the invoked servlet.

wrapRequestback to summary
pack-priv ServletRequest wrapRequest

The request wrapper we have created and installed (if any).

wrapResponseback to summary
pack-priv ServletResponse wrapResponse

The response wrapper we have created and installed (if any).

Constructor Detail

Stateback to summary
pack-priv State(ServletRequest request, ServletResponse response, boolean including)