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 addedServlet
and 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 DemuxServlet
demuxServlet
The demultiplexing servlet that is used for demultiplexing requests to the dynamically added servlets.protected boolean
initialised
Whether the servlet has been initialised.protected Map<String,String>
initParams
The parameters for the initialisation of the servlet of thisDeferredDynamic
.protected String
role
TherunAs
role of thisServletRegistration
.protected DynamicServlet
servlet
The servlet thisDeferredDynamic
handles and initialises.protected javax.servlet.ServletContext
servletContext
The servlet context that creates thisDeferredDynamic
for initialising the servlet.
-
Constructor Summary
Constructors Constructor Description DeferredDynamic(DynamicServlet servlet, DemuxServlet demuxServlet, javax.servlet.ServletContext servletContext, Map<String,String> contextInitParams)
Creates a newDeferredDynamic
for 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 void
checkState()
Checks the state by throwing anIllegalArgumentException
if the servlet has already been initialised.String
getClassName()
String
getInitParameter(String name)
Map<String,String>
getInitParameters()
Collection<String>
getMappings()
String
getName()
String
getRunAsRole()
javax.servlet.Servlet
getServlet()
Gets the servlet thisDynamic
wraps.void
init(String hierContext)
Initialises the servlet of thisDeferredDynamic
.void
removeMappings()
Remove all previously added URL mappings for this servlet.void
setAsyncSupported(boolean isAsyncSupported)
boolean
setInitParameter(String name, String value)
Set<String>
setInitParameters(Map<String,String> initParameters)
void
setLoadOnStartup(int loadOnStartup)
void
setMultipartConfig(javax.servlet.MultipartConfigElement multipartConfig)
void
setRunAsRole(String roleName)
Set<String>
setServletSecurity(javax.servlet.ServletSecurityElement constraint)
void
setWrappingServletContext(javax.servlet.ServletContext wrapped, javax.servlet.ServletContext wrapper)
Set the designated wrapping servlet context if thisDynamic
contains the designatedwrapped
servlet context.
-
-
-
Field Detail
-
servlet
protected final DynamicServlet servlet
The servlet thisDeferredDynamic
handles 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 thisDeferredDynamic
for 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
TherunAs
role 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 newDeferredDynamic
for 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:
addMapping
in interfacejavax.servlet.ServletRegistration
-
removeMappings
public void removeMappings()
Remove all previously added URL mappings for this servlet.
-
getMappings
public Collection<String> getMappings()
- Specified by:
getMappings
in interfacejavax.servlet.ServletRegistration
-
getRunAsRole
public String getRunAsRole()
- Specified by:
getRunAsRole
in interfacejavax.servlet.ServletRegistration
-
getName
public String getName()
- Specified by:
getName
in interfacejavax.servlet.Registration
-
getClassName
public String getClassName()
- Specified by:
getClassName
in interfacejavax.servlet.Registration
-
setInitParameter
public boolean setInitParameter(String name, String value)
- Specified by:
setInitParameter
in interfacejavax.servlet.Registration
-
getInitParameter
public String getInitParameter(String name)
- Specified by:
getInitParameter
in interfacejavax.servlet.Registration
-
setInitParameters
public Set<String> setInitParameters(Map<String,String> initParameters)
- Specified by:
setInitParameters
in interfacejavax.servlet.Registration
-
getInitParameters
public Map<String,String> getInitParameters()
- Specified by:
getInitParameters
in interfacejavax.servlet.Registration
-
setAsyncSupported
public void setAsyncSupported(boolean isAsyncSupported)
- Specified by:
setAsyncSupported
in interfacejavax.servlet.Registration.Dynamic
-
setLoadOnStartup
public void setLoadOnStartup(int loadOnStartup)
- Specified by:
setLoadOnStartup
in interfacejavax.servlet.ServletRegistration.Dynamic
-
setServletSecurity
public Set<String> setServletSecurity(javax.servlet.ServletSecurityElement constraint)
- Specified by:
setServletSecurity
in interfacejavax.servlet.ServletRegistration.Dynamic
-
setMultipartConfig
public void setMultipartConfig(javax.servlet.MultipartConfigElement multipartConfig)
- Specified by:
setMultipartConfig
in interfacejavax.servlet.ServletRegistration.Dynamic
-
setRunAsRole
public void setRunAsRole(String roleName)
- Specified by:
setRunAsRole
in interfacejavax.servlet.ServletRegistration.Dynamic
-
setWrappingServletContext
public void setWrappingServletContext(javax.servlet.ServletContext wrapped, javax.servlet.ServletContext wrapper)
Description copied from interface:WrapSupportingDynamic
Set the designated wrapping servlet context if thisDynamic
contains the designatedwrapped
servlet context.- Specified by:
setWrappingServletContext
in interfaceWrapSupportingDynamic
- Parameters:
wrapped
- The wrapped servlet context thisDynamic
may contain.wrapper
- The wrapping servlet context to replace the servlet context within thisDynamic
.
-
getServlet
public javax.servlet.Servlet getServlet()
Gets the servlet thisDynamic
wraps.- Returns:
- The servlet this
Dynamic
wraps.
-
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 thisDeferredDynamic
cannot be called any more.- Parameters:
hierContext
- The hierarchical context of the servlet with trailing "/".- Throws:
javax.servlet.ServletException
- If initialisation of the servlet fails, aServletException
will be thrown.
-
checkState
protected void checkState()
Checks the state by throwing anIllegalArgumentException
if the servlet has already been initialised. This prevents calling methods that change data that is relevant for initialising the servlet, e. g. init parameters.
-
-