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 correspondingDeferredDynamicallows for setting URL patterns as well as changing init parameters. Note that as soon as aDeferredDynamichas 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 theDeferredDynamicand 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 DemuxServletdemuxServletThe demultiplexing servlet which forwards to the servlets added via this context.static StringINIT_PARAM_DEMUX_SERVLET_ASYNC_SUPPORTEDInit parameter name for the boolean value whether the demultiplexing servlet should be marked as async supported.static StringINIT_PARAM_DEMUX_SERVLET_MAPPINGInit parameter name for the URL mapping of the demultiplexing servlet.protected StringinnerContextPathThe path of this context, i.protected Map<String,String>ownInitParamsThe parameters set at this context.protected Map<String,DeferredDynamic>ownServletsThe servlets added dynamically via this context.protected javax.servlet.ServletContextparentContextThe parent servlet context to which to delegate to.protected StringservletPathThe servlet path, i.
-
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.DynamicaddFilter(String filterName, Class<? extends javax.servlet.Filter> filterClass)javax.servlet.FilterRegistration.DynamicaddFilter(String filterName, String className)javax.servlet.FilterRegistration.DynamicaddFilter(String filterName, javax.servlet.Filter filter)javax.servlet.ServletRegistration.DynamicaddJspFile(String servletName, String jspFile)voidaddListener(Class<? extends EventListener> listenerClass)voidaddListener(String className)<T extends EventListener>
voidaddListener(T t)DeferredDynamicaddServlet(String servletName, Class<? extends javax.servlet.Servlet> servletClass)DeferredDynamicaddServlet(String servletName, String className)DeferredDynamicaddServlet(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)voiddeclareRoles(String... roleNames)ObjectgetAttribute(String name)Enumeration<String>getAttributeNames()ClassLoadergetClassLoader()javax.servlet.ServletContextgetContext(String uripath)StringgetContextPath()Set<javax.servlet.SessionTrackingMode>getDefaultSessionTrackingModes()intgetEffectiveMajorVersion()intgetEffectiveMinorVersion()Set<javax.servlet.SessionTrackingMode>getEffectiveSessionTrackingModes()javax.servlet.FilterRegistrationgetFilterRegistration(String filterName)Map<String,? extends javax.servlet.FilterRegistration>getFilterRegistrations()StringgetInitParameter(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.JspConfigDescriptorgetJspConfigDescriptor()intgetMajorVersion()StringgetMimeType(String file)intgetMinorVersion()javax.servlet.RequestDispatchergetNamedDispatcher(String name)StringgetRealPath(String path)StringgetRequestCharacterEncoding()javax.servlet.RequestDispatchergetRequestDispatcher(String path)URLgetResource(String path)InputStreamgetResourceAsStream(String path)Set<String>getResourcePaths(String path)StringgetResponseCharacterEncoding()StringgetServerInfo()javax.servlet.ServletgetServlet(String name)StringgetServletContextName()Enumeration<String>getServletNames()javax.servlet.ServletRegistrationgetServletRegistration(String servletName)Map<String,? extends javax.servlet.ServletRegistration>getServletRegistrations()Enumeration<javax.servlet.Servlet>getServlets()javax.servlet.SessionCookieConfiggetSessionCookieConfig()intgetSessionTimeout()StringgetVirtualServerName()voidlog(Exception exception, String msg)voidlog(String msg)voidlog(String message, Throwable throwable)voidremoveAttribute(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<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 ConfigurationExceptionCreates 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(javax.servlet.ServletConfig config, DemuxServlet servlet) throws javax.servlet.ServletExceptionCreates 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), aServletExceptionwill be thrown.
-
-
Method Detail
-
getContextPath
public String getContextPath()
- Specified by:
getContextPathin interfacejavax.servlet.ServletContext
-
getContext
public javax.servlet.ServletContext getContext(String uripath)
- Specified by:
getContextin interfacejavax.servlet.ServletContext
-
getMajorVersion
public int getMajorVersion()
- Specified by:
getMajorVersionin interfacejavax.servlet.ServletContext
-
getMinorVersion
public int getMinorVersion()
- Specified by:
getMinorVersionin interfacejavax.servlet.ServletContext
-
getEffectiveMajorVersion
public int getEffectiveMajorVersion()
- Specified by:
getEffectiveMajorVersionin interfacejavax.servlet.ServletContext
-
getEffectiveMinorVersion
public int getEffectiveMinorVersion()
- Specified by:
getEffectiveMinorVersionin interfacejavax.servlet.ServletContext
-
getMimeType
public String getMimeType(String file)
- Specified by:
getMimeTypein interfacejavax.servlet.ServletContext
-
getResourcePaths
public Set<String> getResourcePaths(String path)
- Specified by:
getResourcePathsin interfacejavax.servlet.ServletContext
-
getResource
public URL getResource(String path) throws MalformedURLException
- Specified by:
getResourcein interfacejavax.servlet.ServletContext- Throws:
MalformedURLException
-
getResourceAsStream
public InputStream getResourceAsStream(String path)
- Specified by:
getResourceAsStreamin interfacejavax.servlet.ServletContext
-
getRequestDispatcher
public javax.servlet.RequestDispatcher getRequestDispatcher(String path)
- Specified by:
getRequestDispatcherin interfacejavax.servlet.ServletContext
-
getNamedDispatcher
public javax.servlet.RequestDispatcher getNamedDispatcher(String name)
- Specified by:
getNamedDispatcherin interfacejavax.servlet.ServletContext
-
getServlet
public javax.servlet.Servlet getServlet(String name) throws javax.servlet.ServletException
- Specified by:
getServletin interfacejavax.servlet.ServletContext- Throws:
javax.servlet.ServletException
-
getServlets
public Enumeration<javax.servlet.Servlet> getServlets()
- Specified by:
getServletsin interfacejavax.servlet.ServletContext
-
getServletNames
public Enumeration<String> getServletNames()
- Specified by:
getServletNamesin interfacejavax.servlet.ServletContext
-
log
public void log(String msg)
- Specified by:
login interfacejavax.servlet.ServletContext
-
log
public void log(Exception exception, String msg)
- Specified by:
login interfacejavax.servlet.ServletContext
-
log
public void log(String message, Throwable throwable)
- Specified by:
login interfacejavax.servlet.ServletContext
-
getRealPath
public String getRealPath(String path)
- Specified by:
getRealPathin interfacejavax.servlet.ServletContext
-
getServerInfo
public String getServerInfo()
- Specified by:
getServerInfoin interfacejavax.servlet.ServletContext
-
getInitParameter
public String getInitParameter(String name)
- Specified by:
getInitParameterin 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:
getInitParameterNamesin 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:
setInitParameterin interfacejavax.servlet.ServletContext
-
getAttribute
public Object getAttribute(String name)
- Specified by:
getAttributein interfacejavax.servlet.ServletContext
-
getAttributeNames
public Enumeration<String> getAttributeNames()
- Specified by:
getAttributeNamesin interfacejavax.servlet.ServletContext
-
setAttribute
public void setAttribute(String name, Object object)
- Specified by:
setAttributein interfacejavax.servlet.ServletContext
-
removeAttribute
public void removeAttribute(String name)
- Specified by:
removeAttributein interfacejavax.servlet.ServletContext
-
getServletContextName
public String getServletContextName()
- Specified by:
getServletContextNamein interfacejavax.servlet.ServletContext
-
addServlet
public DeferredDynamic addServlet(String servletName, String className)
- Specified by:
addServletin interfacejavax.servlet.ServletContext
-
addServlet
public DeferredDynamic addServlet(String servletName, javax.servlet.Servlet servlet)
- Specified by:
addServletin interfacejavax.servlet.ServletContext
-
addJspFile
public javax.servlet.ServletRegistration.Dynamic addJspFile(String servletName, String jspFile)
- Specified by:
addJspFilein interfacejavax.servlet.ServletContext
-
addServlet
public DeferredDynamic addServlet(String servletName, Class<? extends javax.servlet.Servlet> servletClass)
- Specified by:
addServletin interfacejavax.servlet.ServletContext
-
removeServlet
public boolean removeServlet(String servletName)
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 javax.servlet.Servlet> T createServlet(Class<T> clazz) throws javax.servlet.ServletException
- Specified by:
createServletin interfacejavax.servlet.ServletContext- Throws:
javax.servlet.ServletException
-
getServletRegistration
public javax.servlet.ServletRegistration getServletRegistration(String servletName)
- Specified by:
getServletRegistrationin interfacejavax.servlet.ServletContext
-
getServletRegistrations
public Map<String,? extends javax.servlet.ServletRegistration> getServletRegistrations()
- Specified by:
getServletRegistrationsin interfacejavax.servlet.ServletContext
-
addFilter
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, String className)
- Specified by:
addFilterin interfacejavax.servlet.ServletContext
-
addFilter
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, javax.servlet.Filter filter)
- Specified by:
addFilterin interfacejavax.servlet.ServletContext
-
addFilter
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends javax.servlet.Filter> filterClass)
- Specified by:
addFilterin interfacejavax.servlet.ServletContext
-
createFilter
public <T extends javax.servlet.Filter> T createFilter(Class<T> clazz) throws javax.servlet.ServletException
- Specified by:
createFilterin interfacejavax.servlet.ServletContext- Throws:
javax.servlet.ServletException
-
getFilterRegistration
public javax.servlet.FilterRegistration getFilterRegistration(String filterName)
- Specified by:
getFilterRegistrationin interfacejavax.servlet.ServletContext
-
getFilterRegistrations
public Map<String,? extends javax.servlet.FilterRegistration> getFilterRegistrations()
- Specified by:
getFilterRegistrationsin interfacejavax.servlet.ServletContext
-
getSessionCookieConfig
public javax.servlet.SessionCookieConfig getSessionCookieConfig()
- Specified by:
getSessionCookieConfigin interfacejavax.servlet.ServletContext
-
setSessionTrackingModes
public void setSessionTrackingModes(Set<javax.servlet.SessionTrackingMode> sessionTrackingModes)
- Specified by:
setSessionTrackingModesin interfacejavax.servlet.ServletContext
-
getDefaultSessionTrackingModes
public Set<javax.servlet.SessionTrackingMode> getDefaultSessionTrackingModes()
- Specified by:
getDefaultSessionTrackingModesin interfacejavax.servlet.ServletContext
-
getEffectiveSessionTrackingModes
public Set<javax.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes()
- Specified by:
getEffectiveSessionTrackingModesin interfacejavax.servlet.ServletContext
-
addListener
public void addListener(String className)
- Specified by:
addListenerin interfacejavax.servlet.ServletContext
-
addListener
public <T extends EventListener> void addListener(T t)
- Specified by:
addListenerin interfacejavax.servlet.ServletContext
-
addListener
public void addListener(Class<? extends EventListener> listenerClass)
- Specified by:
addListenerin interfacejavax.servlet.ServletContext
-
createListener
public <T extends EventListener> T createListener(Class<T> clazz) throws javax.servlet.ServletException
- Specified by:
createListenerin interfacejavax.servlet.ServletContext- Throws:
javax.servlet.ServletException
-
getJspConfigDescriptor
public javax.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()
- Specified by:
getJspConfigDescriptorin interfacejavax.servlet.ServletContext
-
getClassLoader
public ClassLoader getClassLoader()
- Specified by:
getClassLoaderin interfacejavax.servlet.ServletContext
-
declareRoles
public void declareRoles(String... roleNames)
- Specified by:
declareRolesin interfacejavax.servlet.ServletContext
-
getVirtualServerName
public String getVirtualServerName()
- Specified by:
getVirtualServerNamein interfacejavax.servlet.ServletContext
-
getSessionTimeout
public int getSessionTimeout()
- Specified by:
getSessionTimeoutin interfacejavax.servlet.ServletContext
-
setSessionTimeout
public void setSessionTimeout(int sessionTimeout)
- Specified by:
setSessionTimeoutin interfacejavax.servlet.ServletContext
-
getRequestCharacterEncoding
public String getRequestCharacterEncoding()
- Specified by:
getRequestCharacterEncodingin interfacejavax.servlet.ServletContext
-
setRequestCharacterEncoding
public void setRequestCharacterEncoding(String encoding)
- Specified by:
setRequestCharacterEncodingin interfacejavax.servlet.ServletContext
-
getResponseCharacterEncoding
public String getResponseCharacterEncoding()
- Specified by:
getResponseCharacterEncodingin interfacejavax.servlet.ServletContext
-
setResponseCharacterEncoding
public void setResponseCharacterEncoding(String encoding)
- Specified by:
setResponseCharacterEncodingin interfacejavax.servlet.ServletContext
-
-