Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.servlet

pack-priv final Class ApplicationDispatcher

extends Object
implements RequestDispatcher
Class Inheritance
All Implemented Interfaces
jakarta.servlet.RequestDispatcher
Static Imports
jakarta.servlet.DispatcherType.INCLUDE

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.
Authors
Craig R. McClanahan, Bongjae Chang

Nested and Inner Type Summary

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

Used to pass state when the request dispatcher is used.

Field Summary

Modifier and TypeField and Description
private Boolean
crossContextFlag

is this dispatch cross context

public static final String
private static final Logger
private String
name

The servlet name for a named dispatcher.

private String
pathInfo

The extra path information for this RequestDispatcher.

private String
queryString

The query string parameters for this RequestDispatcher.

private String
requestURI

The request URI for this RequestDispatcher.

private String
servletPath

The servlet path for this RequestDispatcher.

private ServletHandler
wrapper

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

Constructor Summary

AccessConstructor and Description
public
ApplicationDispatcher(ServletHandler
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
,
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 static void
public void
dispatch(ServletRequest
The request to be forwarded
request
,
ServletResponse
The response to be forwarded
response
,
DispatcherType
The type of dispatch to be performed
dispatcherType
)

Dispatches the given request and response to the resource for which this dispatcher was acquired.

private void
doDispatch(ServletRequest request, ServletResponse response, DispatcherType dispatcherType)

private void
private void
doInvoke(ServletRequest
The servlet request we are processing
request
,
ServletResponse
The servlet response we are creating
response
,
boolean
true if the request dispatch is crossing context boundaries, false otherwise
crossContext
,
ApplicationDispatcher.State
the state of this ApplicationDispatcher
state
)

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

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

Implements jakarta.servlet.RequestDispatcher.forward.

Forwards the given request and response to the resource for which this dispatcher was acquired.

private String

Returns:

The combined path with pathInfo appended to servletInfo
getCombinedPath
()

Combines 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 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

crossContextFlagback to summary
private Boolean crossContextFlag

is this dispatch cross context

LAST_DISPATCH_REQUEST_PATH_ATTRback to summary
public static final String LAST_DISPATCH_REQUEST_PATH_ATTR
LOGGERback to summary
private static final Logger LOGGER
nameback to summary
private String name

The servlet name for a named dispatcher.

pathInfoback to summary
private String pathInfo

The extra path information for this RequestDispatcher.

queryStringback to summary
private String queryString

The query string parameters for this RequestDispatcher.

requestURIback to summary
private String requestURI

The request URI for this RequestDispatcher.

servletPathback to summary
private String servletPath

The servlet path for this RequestDispatcher.

wrapperback to summary
private ServletHandler wrapper

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

Constructor Detail

ApplicationDispatcherback to summary
public ApplicationDispatcher(ServletHandler wrapper, String requestURI, String servletPath, String pathInfo, String queryString, 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:ServletHandler

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)

name:String

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

Method Detail

closeResponseback to summary
private static void closeResponse(ServletResponse response)
dispatchback to summary
public void dispatch(ServletRequest request, ServletResponse response, DispatcherType dispatcherType) throws ServletException, IOException

Dispatches the given request and response to the resource for which this dispatcher was acquired.

Any runtime exceptions, IOException, or ServletException thrown by the target will be propagated to the caller.

Parameters
request:ServletRequest

The request to be forwarded

response:ServletResponse

The response to be forwarded

dispatcherType:DispatcherType

The type of dispatch to be performed

Annotations
@SuppressWarnings:unchecked
Exceptions
ServletException:
if a servlet exception occurs
IOException:
if an input/output error occurs
IllegalArgumentException:
if the dispatcher type is different from FORWARD, ERROR, and ASYNC
doDispatchback to summary
private void doDispatch(ServletRequest request, ServletResponse response, DispatcherType dispatcherType) throws ServletException, IOException
doIncludeback to summary
private void doInclude(ServletRequest request, ServletResponse response) throws ServletException, IOException
doInvokeback to summary
private void doInvoke(ServletRequest request, ServletResponse response, boolean crossContext, 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

crossContext:boolean

true if the request dispatch is crossing context boundaries, false otherwise

state:ApplicationDispatcher.State

the state of this ApplicationDispatcher

Exceptions
IOException:
if an input/output error occurs
ServletException:
if a servlet error occurs
forwardback to summary
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException

Implements jakarta.servlet.RequestDispatcher.forward.

Forwards the given request and response to the resource for which this dispatcher was acquired.

Any runtime exceptions, IOException, or ServletException thrown by the target will be propagated to the caller.

Parameters
request:ServletRequest

The request to be forwarded

response:ServletResponse

The 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()

Combines 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
@SuppressWarnings:unchecked
@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

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.glassfish.grizzly.servlet back to summary

private Class ApplicationDispatcher.PrivilegedDispatch

extends Object
implements PrivilegedExceptionAction<Void>
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.servlet.ApplicationDispatcher.PrivilegedDispatch
All Implemented Interfaces
java.security.PrivilegedExceptionAction

Field Summary

Modifier and TypeField and Description
private final DispatcherType
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

dispatcherTypeback to summary
private final DispatcherType dispatcherType
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, DispatcherType dispatcherType)

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.

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.glassfish.grizzly.servlet back to summary

private Class ApplicationDispatcher.PrivilegedInclude

extends Object
implements PrivilegedExceptionAction<Void>
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.servlet.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.

Annotations
@Override
org.glassfish.grizzly.servlet 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 final DispatcherType
dispatcherType

The type of dispatch we are performing

pack-priv HttpServletRequest
hrequest

Outermost HttpServletRequest in the chain

pack-priv HttpServletResponse
hresponse

Outermost HttpServletResponse in the chain

pack-priv ServletRequest
outerRequest

Outermost request that will be passed on to the invoked servlet

pack-priv ServletResponse
outerResponse

Outermost response that will be passed on to the invoked servlet.

pack-priv ServletRequest
wrapRequest

Request wrapper we have created and installed (if any).

pack-priv ServletResponse
wrapResponse

Response wrapper we have created and installed (if any).

Constructor Summary

AccessConstructor and Description
pack-priv
State(ServletRequest request, ServletResponse response, DispatcherType dispatcherType)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dispatcherTypeback to summary
pack-priv final DispatcherType dispatcherType

The type of dispatch we are performing

hrequestback to summary
pack-priv HttpServletRequest hrequest

Outermost HttpServletRequest in the chain

hresponseback to summary
pack-priv HttpServletResponse hresponse

Outermost HttpServletResponse in the chain

outerRequestback to summary
pack-priv ServletRequest outerRequest

Outermost request that will be passed on to the invoked servlet

outerResponseback to summary
pack-priv ServletResponse outerResponse

Outermost response that will be passed on to the invoked servlet.

wrapRequestback to summary
pack-priv ServletRequest wrapRequest

Request wrapper we have created and installed (if any).

wrapResponseback to summary
pack-priv ServletResponse wrapResponse

Response wrapper we have created and installed (if any).

Constructor Detail

Stateback to summary
pack-priv State(ServletRequest request, ServletResponse response, DispatcherType dispatcherType)