Class DeferredServletContext
- java.lang.Object
-
- de.aristaflow.adept2.base.servletcontainer.demux.DeferredServletContext
-
- All Implemented Interfaces:
DynamicServletContext
,Serializable
,javax.servlet.ServletContext
public class DeferredServletContext extends Object implements DynamicServletContext, Serializable
This servlet context provides the means for adding servlets after the parent servlet context has already been initialised. It is closely coupled to the corresponding servlet implementation which demultiplexes incoming requests to all servlets added to this context.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 correspondingDeferredDynamic
allows for setting URL patterns as well as changing init parameters. Note that as soon as aDeferredDynamic
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 theDeferredDynamic
and therefore of theServletConfig
.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
.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected DemuxServlet
demuxServlet
The demultiplexing servlet which forwards to the servlets added via this context.static String
INIT_PARAM_DEMUX_SERVLET_ASYNC_SUPPORTED
Init parameter name for the boolean value whether the demultiplexing servlet should be marked as async supported.static String
INIT_PARAM_DEMUX_SERVLET_MAPPING
Init parameter name for the URL mapping of the demultiplexing servlet.protected String
innerContextPath
The path of this context, i. e. the context for the inner servlets.protected Map<String,String>
ownInitParams
The parameters set at this context.protected Map<String,DeferredDynamic>
ownServlets
The servlets added dynamically via this context.protected javax.servlet.ServletContext
parentContext
The parent servlet context to which to delegate to.protected String
servletPath
The servlet path, i. e. the last part of theinnerContextPath
.
-
Constructor Summary
Constructors Constructor Description DeferredServletContext(javax.servlet.ServletConfig config, DemuxServlet servlet)
Creates a new servlet context for the designated demultiplexing servlet.DeferredServletContext(javax.servlet.ServletContext parentContext)
Creates a new servlet context with the designated servlet context as parent.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.servlet.FilterRegistration.Dynamic
addFilter(String filterName, Class<? extends javax.servlet.Filter> filterClass)
javax.servlet.FilterRegistration.Dynamic
addFilter(String filterName, String className)
javax.servlet.FilterRegistration.Dynamic
addFilter(String filterName, javax.servlet.Filter filter)
javax.servlet.ServletRegistration.Dynamic
addJspFile(String servletName, String jspFile)
void
addListener(Class<? extends EventListener> listenerClass)
void
addListener(String className)
<T extends EventListener>
voidaddListener(T t)
DeferredDynamic
addServlet(String servletName, Class<? extends javax.servlet.Servlet> servletClass)
DeferredDynamic
addServlet(String servletName, String className)
DeferredDynamic
addServlet(String servletName, javax.servlet.Servlet servlet)
<T extends javax.servlet.Filter>
TcreateFilter(Class<T> clazz)
<T extends EventListener>
TcreateListener(Class<T> clazz)
<T extends javax.servlet.Servlet>
TcreateServlet(Class<T> clazz)
void
declareRoles(String... roleNames)
Object
getAttribute(String name)
Enumeration<String>
getAttributeNames()
ClassLoader
getClassLoader()
javax.servlet.ServletContext
getContext(String uripath)
String
getContextPath()
Set<javax.servlet.SessionTrackingMode>
getDefaultSessionTrackingModes()
int
getEffectiveMajorVersion()
int
getEffectiveMinorVersion()
Set<javax.servlet.SessionTrackingMode>
getEffectiveSessionTrackingModes()
javax.servlet.FilterRegistration
getFilterRegistration(String filterName)
Map<String,? extends javax.servlet.FilterRegistration>
getFilterRegistrations()
String
getInitParameter(String name)
Enumeration<String>
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.protected Map<String,String>
getInitParams()
Gets the current init parameters of this servlet context as well as the ones from the parent servlet context.javax.servlet.descriptor.JspConfigDescriptor
getJspConfigDescriptor()
int
getMajorVersion()
String
getMimeType(String file)
int
getMinorVersion()
javax.servlet.RequestDispatcher
getNamedDispatcher(String name)
String
getRealPath(String path)
String
getRequestCharacterEncoding()
javax.servlet.RequestDispatcher
getRequestDispatcher(String path)
URL
getResource(String path)
InputStream
getResourceAsStream(String path)
Set<String>
getResourcePaths(String path)
String
getResponseCharacterEncoding()
String
getServerInfo()
javax.servlet.Servlet
getServlet(String name)
String
getServletContextName()
Enumeration<String>
getServletNames()
javax.servlet.ServletRegistration
getServletRegistration(String servletName)
Map<String,? extends javax.servlet.ServletRegistration>
getServletRegistrations()
Enumeration<javax.servlet.Servlet>
getServlets()
javax.servlet.SessionCookieConfig
getSessionCookieConfig()
int
getSessionTimeout()
String
getVirtualServerName()
void
log(Exception exception, String msg)
void
log(String msg)
void
log(String message, Throwable throwable)
void
removeAttribute(String name)
boolean
removeServlet(String servletName)
Removes the servlet with the designated name.void
setAttribute(String name, Object object)
boolean
setInitParameter(String name, String value)
This will only set the designated init parameter if there is no init parameter of the same name.void
setRequestCharacterEncoding(String encoding)
void
setResponseCharacterEncoding(String encoding)
void
setSessionTimeout(int sessionTimeout)
void
setSessionTrackingModes(Set<javax.servlet.SessionTrackingMode> sessionTrackingModes)
-
-
-
Field Detail
-
INIT_PARAM_DEMUX_SERVLET_MAPPING
public static final String INIT_PARAM_DEMUX_SERVLET_MAPPING
Init parameter name for the URL mapping of the demultiplexing servlet.- See Also:
- Constant Field Values
-
INIT_PARAM_DEMUX_SERVLET_ASYNC_SUPPORTED
public static final String 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:
- Constant Field Values
-
parentContext
protected final javax.servlet.ServletContext parentContext
The parent servlet context to which to delegate to.
-
innerContextPath
protected final String 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
protected final String 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
protected final DemuxServlet demuxServlet
The demultiplexing servlet which forwards to the servlets added via this context.
-
ownServlets
protected final Map<String,DeferredDynamic> ownServlets
The servlets added dynamically via this context.
-
-
Constructor Detail
-
DeferredServletContext
public DeferredServletContext(javax.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/*
, aConfigurationException
will be thrown.
-
DeferredServletContext
public DeferredServletContext(javax.servlet.ServletConfig config, DemuxServlet servlet) throws javax.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:
javax.servlet.ServletException
- If the mapping of the designated servlet does not exist (i. e. is not configured), aServletException
will be thrown.
-
-
Method Detail
-
getContextPath
public String getContextPath()
- Specified by:
getContextPath
in interfacejavax.servlet.ServletContext
-
getContext
public javax.servlet.ServletContext getContext(String uripath)
- Specified by:
getContext
in interfacejavax.servlet.ServletContext
-
getMajorVersion
public int getMajorVersion()
- Specified by:
getMajorVersion
in interfacejavax.servlet.ServletContext
-
getMinorVersion
public int getMinorVersion()
- Specified by:
getMinorVersion
in interfacejavax.servlet.ServletContext
-
getEffectiveMajorVersion
public int getEffectiveMajorVersion()
- Specified by:
getEffectiveMajorVersion
in interfacejavax.servlet.ServletContext
-
getEffectiveMinorVersion
public int getEffectiveMinorVersion()
- Specified by:
getEffectiveMinorVersion
in interfacejavax.servlet.ServletContext
-
getMimeType
public String getMimeType(String file)
- Specified by:
getMimeType
in interfacejavax.servlet.ServletContext
-
getResourcePaths
public Set<String> getResourcePaths(String path)
- Specified by:
getResourcePaths
in interfacejavax.servlet.ServletContext
-
getResource
public URL getResource(String path) throws MalformedURLException
- Specified by:
getResource
in interfacejavax.servlet.ServletContext
- Throws:
MalformedURLException
-
getResourceAsStream
public InputStream getResourceAsStream(String path)
- Specified by:
getResourceAsStream
in interfacejavax.servlet.ServletContext
-
getRequestDispatcher
public javax.servlet.RequestDispatcher getRequestDispatcher(String path)
- Specified by:
getRequestDispatcher
in interfacejavax.servlet.ServletContext
-
getNamedDispatcher
public javax.servlet.RequestDispatcher getNamedDispatcher(String name)
- Specified by:
getNamedDispatcher
in interfacejavax.servlet.ServletContext
-
getServlet
public javax.servlet.Servlet getServlet(String name) throws javax.servlet.ServletException
- Specified by:
getServlet
in interfacejavax.servlet.ServletContext
- Throws:
javax.servlet.ServletException
-
getServlets
public Enumeration<javax.servlet.Servlet> getServlets()
- Specified by:
getServlets
in interfacejavax.servlet.ServletContext
-
getServletNames
public Enumeration<String> getServletNames()
- Specified by:
getServletNames
in interfacejavax.servlet.ServletContext
-
log
public void log(String msg)
- Specified by:
log
in interfacejavax.servlet.ServletContext
-
log
public void log(Exception exception, String msg)
- Specified by:
log
in interfacejavax.servlet.ServletContext
-
log
public void log(String message, Throwable throwable)
- Specified by:
log
in interfacejavax.servlet.ServletContext
-
getRealPath
public String getRealPath(String path)
- Specified by:
getRealPath
in interfacejavax.servlet.ServletContext
-
getServerInfo
public String getServerInfo()
- Specified by:
getServerInfo
in interfacejavax.servlet.ServletContext
-
getInitParameter
public String getInitParameter(String name)
- Specified by:
getInitParameter
in interfacejavax.servlet.ServletContext
-
getInitParameterNames
public Enumeration<String> 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:
getInitParameterNames
in interfacejavax.servlet.ServletContext
-
setInitParameter
public boolean setInitParameter(String name, String value)
This will only set the designated init parameter if there is no init parameter of the same name.- Specified by:
setInitParameter
in interfacejavax.servlet.ServletContext
-
getAttribute
public Object getAttribute(String name)
- Specified by:
getAttribute
in interfacejavax.servlet.ServletContext
-
getAttributeNames
public Enumeration<String> getAttributeNames()
- Specified by:
getAttributeNames
in interfacejavax.servlet.ServletContext
-
setAttribute
public void setAttribute(String name, Object object)
- Specified by:
setAttribute
in interfacejavax.servlet.ServletContext
-
removeAttribute
public void removeAttribute(String name)
- Specified by:
removeAttribute
in interfacejavax.servlet.ServletContext
-
getServletContextName
public String getServletContextName()
- Specified by:
getServletContextName
in interfacejavax.servlet.ServletContext
-
addServlet
public DeferredDynamic addServlet(String servletName, String className)
- Specified by:
addServlet
in interfacejavax.servlet.ServletContext
-
addServlet
public DeferredDynamic addServlet(String servletName, javax.servlet.Servlet servlet)
- Specified by:
addServlet
in interfacejavax.servlet.ServletContext
-
addJspFile
public javax.servlet.ServletRegistration.Dynamic addJspFile(String servletName, String jspFile)
- Specified by:
addJspFile
in interfacejavax.servlet.ServletContext
-
addServlet
public DeferredDynamic addServlet(String servletName, Class<? extends javax.servlet.Servlet> servletClass)
- Specified by:
addServlet
in interfacejavax.servlet.ServletContext
-
removeServlet
public boolean removeServlet(String servletName)
Description copied from interface:DynamicServletContext
Removes the servlet with the designated name.- Specified by:
removeServlet
in 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 javax.servlet.Servlet> T createServlet(Class<T> clazz) throws javax.servlet.ServletException
- Specified by:
createServlet
in interfacejavax.servlet.ServletContext
- Throws:
javax.servlet.ServletException
-
getServletRegistration
public javax.servlet.ServletRegistration getServletRegistration(String servletName)
- Specified by:
getServletRegistration
in interfacejavax.servlet.ServletContext
-
getServletRegistrations
public Map<String,? extends javax.servlet.ServletRegistration> getServletRegistrations()
- Specified by:
getServletRegistrations
in interfacejavax.servlet.ServletContext
-
addFilter
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, String className)
- Specified by:
addFilter
in interfacejavax.servlet.ServletContext
-
addFilter
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, javax.servlet.Filter filter)
- Specified by:
addFilter
in interfacejavax.servlet.ServletContext
-
addFilter
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends javax.servlet.Filter> filterClass)
- Specified by:
addFilter
in interfacejavax.servlet.ServletContext
-
createFilter
public <T extends javax.servlet.Filter> T createFilter(Class<T> clazz) throws javax.servlet.ServletException
- Specified by:
createFilter
in interfacejavax.servlet.ServletContext
- Throws:
javax.servlet.ServletException
-
getFilterRegistration
public javax.servlet.FilterRegistration getFilterRegistration(String filterName)
- Specified by:
getFilterRegistration
in interfacejavax.servlet.ServletContext
-
getFilterRegistrations
public Map<String,? extends javax.servlet.FilterRegistration> getFilterRegistrations()
- Specified by:
getFilterRegistrations
in interfacejavax.servlet.ServletContext
-
getSessionCookieConfig
public javax.servlet.SessionCookieConfig getSessionCookieConfig()
- Specified by:
getSessionCookieConfig
in interfacejavax.servlet.ServletContext
-
setSessionTrackingModes
public void setSessionTrackingModes(Set<javax.servlet.SessionTrackingMode> sessionTrackingModes)
- Specified by:
setSessionTrackingModes
in interfacejavax.servlet.ServletContext
-
getDefaultSessionTrackingModes
public Set<javax.servlet.SessionTrackingMode> getDefaultSessionTrackingModes()
- Specified by:
getDefaultSessionTrackingModes
in interfacejavax.servlet.ServletContext
-
getEffectiveSessionTrackingModes
public Set<javax.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes()
- Specified by:
getEffectiveSessionTrackingModes
in interfacejavax.servlet.ServletContext
-
addListener
public void addListener(String className)
- Specified by:
addListener
in interfacejavax.servlet.ServletContext
-
addListener
public <T extends EventListener> void addListener(T t)
- Specified by:
addListener
in interfacejavax.servlet.ServletContext
-
addListener
public void addListener(Class<? extends EventListener> listenerClass)
- Specified by:
addListener
in interfacejavax.servlet.ServletContext
-
createListener
public <T extends EventListener> T createListener(Class<T> clazz) throws javax.servlet.ServletException
- Specified by:
createListener
in interfacejavax.servlet.ServletContext
- Throws:
javax.servlet.ServletException
-
getJspConfigDescriptor
public javax.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()
- Specified by:
getJspConfigDescriptor
in interfacejavax.servlet.ServletContext
-
getClassLoader
public ClassLoader getClassLoader()
- Specified by:
getClassLoader
in interfacejavax.servlet.ServletContext
-
declareRoles
public void declareRoles(String... roleNames)
- Specified by:
declareRoles
in interfacejavax.servlet.ServletContext
-
getVirtualServerName
public String getVirtualServerName()
- Specified by:
getVirtualServerName
in interfacejavax.servlet.ServletContext
-
getSessionTimeout
public int getSessionTimeout()
- Specified by:
getSessionTimeout
in interfacejavax.servlet.ServletContext
-
setSessionTimeout
public void setSessionTimeout(int sessionTimeout)
- Specified by:
setSessionTimeout
in interfacejavax.servlet.ServletContext
-
getRequestCharacterEncoding
public String getRequestCharacterEncoding()
- Specified by:
getRequestCharacterEncoding
in interfacejavax.servlet.ServletContext
-
setRequestCharacterEncoding
public void setRequestCharacterEncoding(String encoding)
- Specified by:
setRequestCharacterEncoding
in interfacejavax.servlet.ServletContext
-
getResponseCharacterEncoding
public String getResponseCharacterEncoding()
- Specified by:
getResponseCharacterEncoding
in interfacejavax.servlet.ServletContext
-
setResponseCharacterEncoding
public void setResponseCharacterEncoding(String encoding)
- Specified by:
setResponseCharacterEncoding
in interfacejavax.servlet.ServletContext
-
-