Class DeferredDynamic
- java.lang.Object
-
- de.aristaflow.adept2.base.servletcontainer.demux.DeferredDynamic
-
- All Implemented Interfaces:
WrapSupportingDynamic,javax.servlet.Registration,javax.servlet.Registration.Dynamic,javax.servlet.ServletRegistration,javax.servlet.ServletRegistration.Dynamic
public class DeferredDynamic extends Object implements WrapSupportingDynamic
This class wraps a dynamically addedServletand allows to change initialisation parameters and URL patterns for the servlet. Since servlet registration is deferred (i. e. after the servlet context has already been initialised), this dynamic also initialises the servlet, i. e. performs servlet lifecycle tasks. Usually these tasks are handled by the servlet context of the servlet container.
-
-
Field Summary
Fields Modifier and Type Field Description protected DemuxServletdemuxServletThe demultiplexing servlet that is used for demultiplexing requests to the dynamically added servlets.protected booleaninitialisedWhether the servlet has been initialised.protected Map<String,String>initParamsThe parameters for the initialisation of the servlet of thisDeferredDynamic.protected StringroleTherunAsrole of thisServletRegistration.protected DynamicServletservletThe servlet thisDeferredDynamichandles and initialises.protected javax.servlet.ServletContextservletContextThe servlet context that creates thisDeferredDynamicfor initialising the servlet.
-
Constructor Summary
Constructors Constructor Description DeferredDynamic(DynamicServlet servlet, DemuxServlet demuxServlet, javax.servlet.ServletContext servletContext, Map<String,String> contextInitParams)Creates a newDeferredDynamicfor the designated servlet using the designated multiplexing servlet and having the designated (deferred) servlet context and init parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>addMapping(String... urlPatterns)protected voidcheckState()Checks the state by throwing anIllegalArgumentExceptionif the servlet has already been initialised.StringgetClassName()StringgetInitParameter(String name)Map<String,String>getInitParameters()Collection<String>getMappings()StringgetName()StringgetRunAsRole()javax.servlet.ServletgetServlet()Gets the servlet thisDynamicwraps.voidinit(String hierContext)Initialises the servlet of thisDeferredDynamic.voidremoveMappings()Remove all previously added URL mappings for this servlet.voidsetAsyncSupported(boolean isAsyncSupported)booleansetInitParameter(String name, String value)Set<String>setInitParameters(Map<String,String> initParameters)voidsetLoadOnStartup(int loadOnStartup)voidsetMultipartConfig(javax.servlet.MultipartConfigElement multipartConfig)voidsetRunAsRole(String roleName)Set<String>setServletSecurity(javax.servlet.ServletSecurityElement constraint)voidsetWrappingServletContext(javax.servlet.ServletContext wrapped, javax.servlet.ServletContext wrapper)Set the designated wrapping servlet context if thisDynamiccontains the designatedwrappedservlet context.
-
-
-
Field Detail
-
servlet
protected final DynamicServlet servlet
The servlet thisDeferredDynamichandles and initialises.
-
demuxServlet
protected final DemuxServlet demuxServlet
The demultiplexing servlet that is used for demultiplexing requests to the dynamically added servlets. This handles the mapping.
-
servletContext
protected javax.servlet.ServletContext servletContext
The servlet context that creates thisDeferredDynamicfor initialising the servlet.
-
initParams
protected final Map<String,String> initParams
The parameters for the initialisation of the servlet of thisDeferredDynamic. These are copied from the servlet context when creating thisDeferredDynamic(i. e. when adding the servlet to the servlet context). Before initialising the servlet, additional init parameters can be added.
-
role
protected String role
TherunAsrole of thisServletRegistration.
-
initialised
protected boolean initialised
Whether the servlet has been initialised. If so, all set methods cannot be called any more but lead to anIllegalStateException.
-
-
Constructor Detail
-
DeferredDynamic
public DeferredDynamic(DynamicServlet servlet, DemuxServlet demuxServlet, javax.servlet.ServletContext servletContext, Map<String,String> contextInitParams)
Creates a newDeferredDynamicfor the designated servlet using the designated multiplexing servlet and having the designated (deferred) servlet context and init parameters. The init parameters may be changed until the servlet is initialised.- Parameters:
servlet- The servlet which is added to the designated servlet context which is about to be initialised and which can be configured via the createdDeferredDynamic.demuxServlet- The demultiplexing servlet handling and forwarding incoming requests.servletContext- The context of the servlet.contextInitParams- The init parameters of the servlet context. These can be changed until the servlet is initialised.
-
-
Method Detail
-
addMapping
public Set<String> addMapping(String... urlPatterns)
- Specified by:
addMappingin interfacejavax.servlet.ServletRegistration
-
removeMappings
public void removeMappings()
Remove all previously added URL mappings for this servlet.
-
getMappings
public Collection<String> getMappings()
- Specified by:
getMappingsin interfacejavax.servlet.ServletRegistration
-
getRunAsRole
public String getRunAsRole()
- Specified by:
getRunAsRolein interfacejavax.servlet.ServletRegistration
-
getName
public String getName()
- Specified by:
getNamein interfacejavax.servlet.Registration
-
getClassName
public String getClassName()
- Specified by:
getClassNamein interfacejavax.servlet.Registration
-
setInitParameter
public boolean setInitParameter(String name, String value)
- Specified by:
setInitParameterin interfacejavax.servlet.Registration
-
getInitParameter
public String getInitParameter(String name)
- Specified by:
getInitParameterin interfacejavax.servlet.Registration
-
setInitParameters
public Set<String> setInitParameters(Map<String,String> initParameters)
- Specified by:
setInitParametersin interfacejavax.servlet.Registration
-
getInitParameters
public Map<String,String> getInitParameters()
- Specified by:
getInitParametersin interfacejavax.servlet.Registration
-
setAsyncSupported
public void setAsyncSupported(boolean isAsyncSupported)
- Specified by:
setAsyncSupportedin interfacejavax.servlet.Registration.Dynamic
-
setLoadOnStartup
public void setLoadOnStartup(int loadOnStartup)
- Specified by:
setLoadOnStartupin interfacejavax.servlet.ServletRegistration.Dynamic
-
setServletSecurity
public Set<String> setServletSecurity(javax.servlet.ServletSecurityElement constraint)
- Specified by:
setServletSecurityin interfacejavax.servlet.ServletRegistration.Dynamic
-
setMultipartConfig
public void setMultipartConfig(javax.servlet.MultipartConfigElement multipartConfig)
- Specified by:
setMultipartConfigin interfacejavax.servlet.ServletRegistration.Dynamic
-
setRunAsRole
public void setRunAsRole(String roleName)
- Specified by:
setRunAsRolein interfacejavax.servlet.ServletRegistration.Dynamic
-
setWrappingServletContext
public void setWrappingServletContext(javax.servlet.ServletContext wrapped, javax.servlet.ServletContext wrapper)Description copied from interface:WrapSupportingDynamicSet the designated wrapping servlet context if thisDynamiccontains the designatedwrappedservlet context.- Specified by:
setWrappingServletContextin interfaceWrapSupportingDynamic- Parameters:
wrapped- The wrapped servlet context thisDynamicmay contain.wrapper- The wrapping servlet context to replace the servlet context within thisDynamic.
-
getServlet
public javax.servlet.Servlet getServlet()
Gets the servlet thisDynamicwraps.- Returns:
- The servlet this
Dynamicwraps.
-
init
public void init(String hierContext) throws javax.servlet.ServletException
Initialises the servlet of thisDeferredDynamic. After this, the servlet is reachable and the set methods on thisDeferredDynamiccannot be called any more.- Parameters:
hierContext- The hierarchical context of the servlet with trailing "/".- Throws:
javax.servlet.ServletException- If initialisation of the servlet fails, aServletExceptionwill be thrown.
-
checkState
protected void checkState()
Checks the state by throwing anIllegalArgumentExceptionif the servlet has already been initialised. This prevents calling methods that change data that is relevant for initialising the servlet, e. g. init parameters.
-
-