Class DeferredServletContext
- All Implemented Interfaces:
DynamicServletContext,jakarta.servlet.ServletContext
This servlet context has a parent servlet context to which most of the methods are forwarded.
This excludes the handling of init parameters and servlets:
Init parameters added to this deferred servlet context will be merged with the init parameters of
the parent servlet context. Therefore one cannot add an init parameter that has already been set
for the parent servlet context.
Servlets can be added any time. The corresponding
DeferredDynamic allows for setting URL patterns as well as changing init parameters. Note
that as soon as a DeferredDynamic has been created, its init parameters will be a
snapshot of the init parameters of this (and the parent) servlet context. That is, changing the
init parameters in the servlet context will not affect the init parameters of the
DeferredDynamic and therefore of the ServletConfig.
This servlet context can be used in two ways:
- Instantiate it directly providing the parent servlet context:
DeferredServletContext(ServletContext).
This requires configuration in the init parameters of the parent servlet context. These are the mapping (e. g. servlet name and path) and whether the demultiplexing servlet should support asynchronism. The mapping has to end with/*to allow for the paths of sub servlets to be handled correctly. Async support will be required if any sub servlets should use async behaviour. The configuration is then used to instantiate and register the demultiplexing servlet. - Let the servlet container instantiate the demultiplexing servlet (e. g. via
web.xml).
In this case the demultiplexing servlet will instantiate the deferred servlet context (DeferredServletContext(ServletConfig, DemuxServlet)) providing its own servlet context as parent context. The URL mapping will be retrieved from the servlet context, i. e. theweb.xml.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DemuxServletThe demultiplexing servlet which forwards to the servlets added via this context.static final StringInit parameter name for the boolean value whether the demultiplexing servlet should be marked as async supported.static final StringInit parameter name for the URL mapping of the demultiplexing servlet.protected final StringThe path of this context, i.The parameters set at this context.protected final Map<String,DeferredDynamic> The servlets added dynamically via this context.protected final jakarta.servlet.ServletContextThe parent servlet context to which to delegate to.protected final StringThe servlet path, i.Fields inherited from interface jakarta.servlet.ServletContext
ORDERED_LIBS, TEMPDIR -
Constructor Summary
ConstructorsConstructorDescriptionDeferredServletContext(jakarta.servlet.ServletConfig config, DemuxServlet servlet) Creates a new servlet context for the designated demultiplexing servlet.DeferredServletContext(jakarta.servlet.ServletContext parentContext) Creates a new servlet context with the designated servlet context as parent. -
Method Summary
Modifier and TypeMethodDescriptionjakarta.servlet.FilterRegistration.Dynamicjakarta.servlet.FilterRegistration.Dynamicjakarta.servlet.FilterRegistration.Dynamicjakarta.servlet.ServletRegistration.DynamicaddJspFile(String servletName, String jspFile) voidaddListener(Class<? extends EventListener> listenerClass) voidaddListener(String className) <T extends EventListener>
voidaddListener(T t) addServlet(String servletName, jakarta.servlet.Servlet servlet) addServlet(String servletName, Class<? extends jakarta.servlet.Servlet> servletClass) addServlet(String servletName, String className) <T extends jakarta.servlet.Filter>
TcreateFilter(Class<T> clazz) <T extends EventListener>
TcreateListener(Class<T> clazz) <T extends jakarta.servlet.Servlet>
TcreateServlet(Class<T> clazz) voiddeclareRoles(String... roleNames) getAttribute(String name) jakarta.servlet.ServletContextgetContext(String uripath) Set<jakarta.servlet.SessionTrackingMode>intintSet<jakarta.servlet.SessionTrackingMode>jakarta.servlet.FilterRegistrationgetFilterRegistration(String filterName) getInitParameter(String name) This includes the init parameter names of the parent servlet context as well as the additional init parameter names set for this servlet context.Gets the current init parameters of this servlet context as well as the ones from the parent servlet context.jakarta.servlet.descriptor.JspConfigDescriptorintgetMimeType(String file) intjakarta.servlet.RequestDispatchergetNamedDispatcher(String name) getRealPath(String path) jakarta.servlet.RequestDispatchergetRequestDispatcher(String path) getResource(String path) getResourceAsStream(String path) getResourcePaths(String path) jakarta.servlet.ServletRegistrationgetServletRegistration(String servletName) jakarta.servlet.SessionCookieConfigintvoidvoidvoidremoveAttribute(String name) booleanremoveServlet(String servletName) Removes the servlet with the designated name.voidsetAttribute(String name, Object object) booleansetInitParameter(String name, String value) This will only set the designated init parameter if there is no init parameter of the same name.voidsetRequestCharacterEncoding(String encoding) voidsetResponseCharacterEncoding(String encoding) voidsetSessionTimeout(int sessionTimeout) voidsetSessionTrackingModes(Set<jakarta.servlet.SessionTrackingMode> sessionTrackingModes) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.servlet.ServletContext
setRequestCharacterEncoding, setResponseCharacterEncoding
-
Field Details
-
INIT_PARAM_DEMUX_SERVLET_MAPPING
Init parameter name for the URL mapping of the demultiplexing servlet.- See Also:
-
INIT_PARAM_DEMUX_SERVLET_ASYNC_SUPPORTED
Init parameter name for the boolean value whether the demultiplexing servlet should be marked as async supported. This is required in case dynamically addded servlets have/need async support.- See Also:
-
parentContext
protected final jakarta.servlet.ServletContext parentContextThe parent servlet context to which to delegate to. -
innerContextPath
The path of this context, i. e. the context for the inner servlets. This is the path of the outer servlet context combined with the servlet path, i. e. the mapping of the demultiplexing servlet. -
servletPath
The servlet path, i. e. the last part of theinnerContextPath. This is without leading and trailing slashes. It will be appended to the path before delegatinggetRealPath(String) -
demuxServlet
The demultiplexing servlet which forwards to the servlets added via this context. -
ownServlets
The servlets added dynamically via this context. -
ownInitParams
The parameters set at this context. This will be merged with the init parameters of the parent servlet context. The names of this and the parameters of the parent are disjoint.
-
-
Constructor Details
-
DeferredServletContext
public DeferredServletContext(jakarta.servlet.ServletContext parentContext) throws ConfigurationException Creates a new servlet context with the designated servlet context as parent. This will also retrieve the configuration for the URL pattern and async support from the init parameters (of the parent servlet context) and use this to instantiate and register the corresponding multiplexing servlet. The default for async support isfalse, the mapping has to be provided.- Parameters:
parentContext- The servlet context used as parent of the created servlet context.- Throws:
ConfigurationException- If the mapping is not defined or does not end with/*, aConfigurationExceptionwill be thrown.
-
DeferredServletContext
public DeferredServletContext(jakarta.servlet.ServletConfig config, DemuxServlet servlet) throws jakarta.servlet.ServletException Creates a new servlet context for the designated demultiplexing servlet. This constructor is called byServlet.init(ServletConfig)of the designated servlet. That is, the designated servlet is instantiated and handled by the servlet container.- Parameters:
config- The config of the designated servlet providing the outer servlet container as well as the servlet mapping.servlet- The demultiplexing servlet which forwards to the servlets added dynamically to this servlet context.- Throws:
jakarta.servlet.ServletException- If the mapping of the designated servlet does not exist (i. e. is not configured), aServletExceptionwill be thrown.
-
-
Method Details
-
getContextPath
- Specified by:
getContextPathin interfacejakarta.servlet.ServletContext
-
getContext
- Specified by:
getContextin interfacejakarta.servlet.ServletContext
-
getMajorVersion
public int getMajorVersion()- Specified by:
getMajorVersionin interfacejakarta.servlet.ServletContext
-
getMinorVersion
public int getMinorVersion()- Specified by:
getMinorVersionin interfacejakarta.servlet.ServletContext
-
getEffectiveMajorVersion
public int getEffectiveMajorVersion()- Specified by:
getEffectiveMajorVersionin interfacejakarta.servlet.ServletContext
-
getEffectiveMinorVersion
public int getEffectiveMinorVersion()- Specified by:
getEffectiveMinorVersionin interfacejakarta.servlet.ServletContext
-
getMimeType
- Specified by:
getMimeTypein interfacejakarta.servlet.ServletContext
-
getResourcePaths
- Specified by:
getResourcePathsin interfacejakarta.servlet.ServletContext
-
getResource
- Specified by:
getResourcein interfacejakarta.servlet.ServletContext- Throws:
MalformedURLException
-
getResourceAsStream
- Specified by:
getResourceAsStreamin interfacejakarta.servlet.ServletContext
-
getRequestDispatcher
- Specified by:
getRequestDispatcherin interfacejakarta.servlet.ServletContext
-
getNamedDispatcher
- Specified by:
getNamedDispatcherin interfacejakarta.servlet.ServletContext
-
log
- Specified by:
login interfacejakarta.servlet.ServletContext
-
log
- Specified by:
login interfacejakarta.servlet.ServletContext
-
getRealPath
- Specified by:
getRealPathin interfacejakarta.servlet.ServletContext
-
getServerInfo
- Specified by:
getServerInfoin interfacejakarta.servlet.ServletContext
-
getInitParameter
- Specified by:
getInitParameterin interfacejakarta.servlet.ServletContext
-
getInitParameterNames
This includes the init parameter names of the parent servlet context as well as the additional init parameter names set for this servlet context.- Specified by:
getInitParameterNamesin interfacejakarta.servlet.ServletContext
-
setInitParameter
This will only set the designated init parameter if there is no init parameter of the same name.- Specified by:
setInitParameterin interfacejakarta.servlet.ServletContext
-
getAttribute
- Specified by:
getAttributein interfacejakarta.servlet.ServletContext
-
getAttributeNames
- Specified by:
getAttributeNamesin interfacejakarta.servlet.ServletContext
-
setAttribute
- Specified by:
setAttributein interfacejakarta.servlet.ServletContext
-
removeAttribute
- Specified by:
removeAttributein interfacejakarta.servlet.ServletContext
-
getServletContextName
- Specified by:
getServletContextNamein interfacejakarta.servlet.ServletContext
-
addServlet
- Specified by:
addServletin interfacejakarta.servlet.ServletContext
-
addServlet
- Specified by:
addServletin interfacejakarta.servlet.ServletContext
-
addJspFile
- Specified by:
addJspFilein interfacejakarta.servlet.ServletContext
-
addServlet
public DeferredDynamic addServlet(String servletName, Class<? extends jakarta.servlet.Servlet> servletClass) - Specified by:
addServletin interfacejakarta.servlet.ServletContext
-
removeServlet
Description copied from interface:DynamicServletContextRemoves the servlet with the designated name.- Specified by:
removeServletin interfaceDynamicServletContext- Parameters:
servletName- The name of the servlet which to remove.- Returns:
- Whether a servlet of the designated name was registered and has been removed by this call.
-
createServlet
public <T extends jakarta.servlet.Servlet> T createServlet(Class<T> clazz) throws jakarta.servlet.ServletException - Specified by:
createServletin interfacejakarta.servlet.ServletContext- Throws:
jakarta.servlet.ServletException
-
getServletRegistration
- Specified by:
getServletRegistrationin interfacejakarta.servlet.ServletContext
-
getServletRegistrations
- Specified by:
getServletRegistrationsin interfacejakarta.servlet.ServletContext
-
addFilter
- Specified by:
addFilterin interfacejakarta.servlet.ServletContext
-
addFilter
public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, jakarta.servlet.Filter filter) - Specified by:
addFilterin interfacejakarta.servlet.ServletContext
-
addFilter
public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends jakarta.servlet.Filter> filterClass) - Specified by:
addFilterin interfacejakarta.servlet.ServletContext
-
createFilter
public <T extends jakarta.servlet.Filter> T createFilter(Class<T> clazz) throws jakarta.servlet.ServletException - Specified by:
createFilterin interfacejakarta.servlet.ServletContext- Throws:
jakarta.servlet.ServletException
-
getFilterRegistration
- Specified by:
getFilterRegistrationin interfacejakarta.servlet.ServletContext
-
getFilterRegistrations
- Specified by:
getFilterRegistrationsin interfacejakarta.servlet.ServletContext
-
getSessionCookieConfig
public jakarta.servlet.SessionCookieConfig getSessionCookieConfig()- Specified by:
getSessionCookieConfigin interfacejakarta.servlet.ServletContext
-
setSessionTrackingModes
- Specified by:
setSessionTrackingModesin interfacejakarta.servlet.ServletContext
-
getDefaultSessionTrackingModes
- Specified by:
getDefaultSessionTrackingModesin interfacejakarta.servlet.ServletContext
-
getEffectiveSessionTrackingModes
- Specified by:
getEffectiveSessionTrackingModesin interfacejakarta.servlet.ServletContext
-
addListener
- Specified by:
addListenerin interfacejakarta.servlet.ServletContext
-
addListener
- Specified by:
addListenerin interfacejakarta.servlet.ServletContext
-
addListener
- Specified by:
addListenerin interfacejakarta.servlet.ServletContext
-
createListener
public <T extends EventListener> T createListener(Class<T> clazz) throws jakarta.servlet.ServletException - Specified by:
createListenerin interfacejakarta.servlet.ServletContext- Throws:
jakarta.servlet.ServletException
-
getJspConfigDescriptor
public jakarta.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()- Specified by:
getJspConfigDescriptorin interfacejakarta.servlet.ServletContext
-
getClassLoader
- Specified by:
getClassLoaderin interfacejakarta.servlet.ServletContext
-
declareRoles
- Specified by:
declareRolesin interfacejakarta.servlet.ServletContext
-
getVirtualServerName
- Specified by:
getVirtualServerNamein interfacejakarta.servlet.ServletContext
-
getSessionTimeout
public int getSessionTimeout()- Specified by:
getSessionTimeoutin interfacejakarta.servlet.ServletContext
-
setSessionTimeout
public void setSessionTimeout(int sessionTimeout) - Specified by:
setSessionTimeoutin interfacejakarta.servlet.ServletContext
-
getRequestCharacterEncoding
- Specified by:
getRequestCharacterEncodingin interfacejakarta.servlet.ServletContext
-
setRequestCharacterEncoding
- Specified by:
setRequestCharacterEncodingin interfacejakarta.servlet.ServletContext
-
getResponseCharacterEncoding
- Specified by:
getResponseCharacterEncodingin interfacejakarta.servlet.ServletContext
-
setResponseCharacterEncoding
- Specified by:
setResponseCharacterEncodingin interfacejakarta.servlet.ServletContext
-
getInitParams
Gets the current init parameters of this servlet context as well as the ones from the parent servlet context.- Returns:
- The current init parameters of this servlet context as well as the ones from the parent servlet context.
-