public class WebappContext
extends java.lang.Object
implements javax.servlet.ServletContext
This class acts as the foundation for registering listeners, servlets, and filters in an embedded environment.
Additionally, this class implements the the requirements set forth by the
Servlet 2.5 specification of ServletContext, however, it also exposes
the dynamic registration API of Servlet 3.0.
TODO: Provide code examples once the api firms up a bit.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
deployed |
protected java.util.Map<java.lang.String,FilterRegistration> |
filterRegistrations |
protected java.util.Map<java.lang.String,ServletRegistration> |
servletRegistrations |
protected java.util.Map<java.lang.String,FilterRegistration> |
unmodifiableFilterRegistrations |
| Modifier | Constructor and Description |
|---|---|
protected |
WebappContext() |
|
WebappContext(java.lang.String displayName)
Creates a simple
WebappContext with the root being "/". |
|
WebappContext(java.lang.String displayName,
java.lang.String contextPath) |
|
WebappContext(java.lang.String displayName,
java.lang.String contextPath,
java.lang.String basePath) |
| Modifier and Type | Method and Description |
|---|---|
void |
addContextInitParameter(java.lang.String name,
java.lang.String value) |
FilterRegistration |
addFilter(java.lang.String filterName,
java.lang.Class<? extends javax.servlet.Filter> filterClass)
Adds the filter with the given name and class type to this servlet
context.
|
FilterRegistration |
addFilter(java.lang.String filterName,
javax.servlet.Filter filter)
Registers the given filter instance with this WebappContext
under the given filterName.
|
FilterRegistration |
addFilter(java.lang.String filterName,
java.lang.String className)
Adds the filter with the given name and class name to this servlet
context.
|
protected void |
addFilterMap(FilterMap filterMap,
boolean isMatchAfter)
Add a filter mapping to this Context.
|
void |
addListener(java.lang.Class<? extends java.util.EventListener> listenerClass)
Adds the given listener class to this WebappContext.
|
void |
addListener(java.lang.String className)
Adds the listener with the given class name to this WebappContext.
|
<T extends java.util.EventListener> |
addListener(T eventListener) |
ServletRegistration |
addServlet(java.lang.String servletName,
java.lang.Class<? extends javax.servlet.Servlet> servletClass)
Adds the servlet with the given name and class type to this servlet
context.
|
ServletRegistration |
addServlet(java.lang.String servletName,
javax.servlet.Servlet servlet)
Registers the given servlet instance with this WebappContext
under the given servletName.
|
ServletRegistration |
addServlet(java.lang.String servletName,
java.lang.String className)
Adds the servlet with the given name and class name to this servlet
context.
|
void |
clearContextInitParameters() |
protected java.util.EventListener |
createEventListenerInstance(java.lang.Class<? extends java.util.EventListener> eventListenerClass)
Instantiates the given EventListener class.
|
protected java.util.EventListener |
createEventListenerInstance(java.lang.String eventListenerClassname)
Instantiates the given EventListener class.
|
<T extends javax.servlet.Filter> |
createFilter(java.lang.Class<T> clazz) |
protected javax.servlet.Filter |
createFilterInstance(java.lang.Class<? extends javax.servlet.Filter> filterClass)
Instantiates the given Filter class.
|
protected javax.servlet.Filter |
createFilterInstance(FilterRegistration registration)
Instantiates the given Filter class.
|
<T extends javax.servlet.http.HttpUpgradeHandler> |
createHttpUpgradeHandlerInstance(java.lang.Class<T> clazz)
Instantiates the given HttpUpgradeHandler class.
|
<T extends java.util.EventListener> |
createListener(java.lang.Class<T> clazz) |
<T extends javax.servlet.Servlet> |
createServlet(java.lang.Class<T> clazz) |
protected javax.servlet.Servlet |
createServletInstance(java.lang.Class<? extends javax.servlet.Servlet> servletClass)
Instantiates the given Servlet class.
|
protected javax.servlet.Servlet |
createServletInstance(ServletRegistration registration)
Instantiates the given Servlet class.
|
void |
declareRoles(java.lang.String... roleNames) |
void |
deploy(HttpServer targetServer) |
protected void |
destroyFilters() |
java.lang.Object |
getAttribute(java.lang.String name) |
java.util.Enumeration<java.lang.String> |
getAttributeNames() |
protected java.lang.String |
getBasePath() |
java.lang.ClassLoader |
getClassLoader() |
javax.servlet.ServletContext |
getContext(java.lang.String uri) |
java.lang.String |
getContextPath() |
java.util.Set<javax.servlet.SessionTrackingMode> |
getDefaultSessionTrackingModes() |
int |
getEffectiveMajorVersion() |
int |
getEffectiveMinorVersion() |
java.util.Set<javax.servlet.SessionTrackingMode> |
getEffectiveSessionTrackingModes() |
protected java.util.EventListener[] |
getEventListeners() |
protected FilterChainFactory |
getFilterChainFactory() |
protected java.util.List<FilterMap> |
getFilterMaps() |
FilterRegistration |
getFilterRegistration(java.lang.String name)
Gets the FilterRegistration corresponding to the filter with the
given filterName.
|
java.util.Map<java.lang.String,? extends FilterRegistration> |
getFilterRegistrations()
Gets a (possibly empty) Map of the FilterRegistration
objects (keyed by filter name) corresponding to all filters
registered with this WebappContext.
|
java.lang.String |
getInitParameter(java.lang.String name) |
java.util.Enumeration<java.lang.String> |
getInitParameterNames() |
javax.servlet.descriptor.JspConfigDescriptor |
getJspConfigDescriptor() |
int |
getMajorVersion() |
java.lang.String |
getMimeType(java.lang.String file) |
int |
getMinorVersion() |
javax.servlet.RequestDispatcher |
getNamedDispatcher(java.lang.String name) |
java.lang.String |
getRealPath(java.lang.String path) |
javax.servlet.RequestDispatcher |
getRequestDispatcher(java.lang.String path) |
java.net.URL |
getResource(java.lang.String path) |
java.io.InputStream |
getResourceAsStream(java.lang.String path) |
java.util.Set<java.lang.String> |
getResourcePaths(java.lang.String path) |
java.lang.String |
getServerInfo() |
javax.servlet.Servlet |
getServlet(java.lang.String name)
Deprecated.
|
java.lang.String |
getServletContextName() |
protected java.util.Collection<java.lang.String> |
getServletNameFilterMappings(java.lang.String filterName)
Gets the current servlet name mappings of the Filter with
the given name.
|
java.util.Enumeration<java.lang.String> |
getServletNames()
Deprecated.
|
ServletRegistration |
getServletRegistration(java.lang.String name)
Gets the ServletRegistration corresponding to the servlet with the
given servletName.
|
java.util.Map<java.lang.String,? extends ServletRegistration> |
getServletRegistrations()
Gets a (possibly empty) Map of the ServletRegistration
objects (keyed by servlet name) corresponding to all servlets
registered with this WebappContext.
|
java.util.Enumeration<javax.servlet.Servlet> |
getServlets()
Deprecated.
|
javax.servlet.SessionCookieConfig |
getSessionCookieConfig() |
protected java.util.Collection<java.lang.String> |
getUrlPatternFilterMappings(java.lang.String filterName)
Gets the current URL pattern mappings of the Filter with the given
name.
|
java.lang.String |
getVirtualServerName() |
void |
log(java.lang.Exception e,
java.lang.String message)
Deprecated.
|
void |
log(java.lang.String message) |
void |
log(java.lang.String message,
java.lang.Throwable throwable) |
protected java.lang.String |
normalize(java.lang.String path)
Return a context-relative path, beginning with a "/", that represents
the canonical version of the specified path after ".." and "." elements
are resolved out.
|
void |
removeAttribute(java.lang.String name) |
void |
removeContextInitParameter(java.lang.String name) |
protected void |
removeFilterMaps()
Removes any filter mappings from this Context.
|
void |
setAttribute(java.lang.String name,
java.lang.Object value) |
protected void |
setDispatcherHelper(DispatcherHelper dispatcherHelper) |
boolean |
setInitParameter(java.lang.String name,
java.lang.String value) |
void |
setSessionTrackingModes(java.util.Set<javax.servlet.SessionTrackingMode> sessionTrackingModes) |
void |
undeploy() |
protected void |
unregisterAllFilters() |
protected void |
unregisterFilter(javax.servlet.Filter f) |
protected boolean |
validateURLPattern(java.lang.String urlPattern)
Validate the syntax of a proposed
<url-pattern>
for conformance with specification requirements. |
protected final java.util.Map<java.lang.String,ServletRegistration> servletRegistrations
protected final java.util.Map<java.lang.String,FilterRegistration> filterRegistrations
protected final java.util.Map<java.lang.String,FilterRegistration> unmodifiableFilterRegistrations
protected boolean deployed
protected WebappContext()
public WebappContext(java.lang.String displayName)
Creates a simple WebappContext with the root being "/".
displayName - public WebappContext(java.lang.String displayName,
java.lang.String contextPath)
public WebappContext(java.lang.String displayName,
java.lang.String contextPath,
java.lang.String basePath)
public void deploy(HttpServer targetServer)
targetServer - public void undeploy()
public void addContextInitParameter(java.lang.String name,
java.lang.String value)
name - value - public void removeContextInitParameter(java.lang.String name)
name - public void clearContextInitParameters()
public FilterRegistration addFilter(java.lang.String filterName, java.lang.Class<? extends javax.servlet.Filter> filterClass)
The registered filter may be further configured via the returned
FilterRegistration object.
If this WebappContext already contains a preliminary FilterRegistration for a filter with the given filterName, it will be completed (by assigning the name of the given filterClass to it) and returned.
addFilter in interface javax.servlet.ServletContextfilterName - the name of the filterfilterClass - the class object from which the filter will be
instantiatedjava.lang.IllegalStateException - if this WebappContext has already
been initializedpublic FilterRegistration addFilter(java.lang.String filterName, javax.servlet.Filter filter)
The registered filter may be further configured via the returned
FilterRegistration object.
If this WebappContext already contains a preliminary FilterRegistration for a filter with the given filterName, it will be completed (by assigning the class name of the given filter instance to it) and returned.
addFilter in interface javax.servlet.ServletContextfilterName - the name of the filterfilter - the filter instance to registerjava.lang.IllegalStateException - if this WebappContext has already
been initializedpublic FilterRegistration addFilter(java.lang.String filterName, java.lang.String className)
The registered filter may be further configured via the returned
FilterRegistration object.
The specified className will be loaded using the classloader associated with the application represented by this WebappContext.
If this WebappContext already contains a preliminary FilterRegistration for a filter with the given filterName, it will be completed (by assigning the given className to it) and returned.
addFilter in interface javax.servlet.ServletContextfilterName - the name of the filterclassName - the fully qualified class name of the filterjava.lang.IllegalStateException - if this WebappContext has already
been initializedpublic ServletRegistration addServlet(java.lang.String servletName, java.lang.Class<? extends javax.servlet.Servlet> servletClass)
The registered servlet may be further configured via the returned
ServletRegistration object.
If this WebappContext already contains a preliminary ServletRegistration for a servlet with the given servletName, it will be completed (by assigning the name of the given servletClass to it) and returned.
addServlet in interface javax.servlet.ServletContextservletName - the name of the servletservletClass - the class object from which the servlet will be
instantiatedjava.lang.IllegalStateException - if this WebappContext has already
been initializedpublic ServletRegistration addServlet(java.lang.String servletName, javax.servlet.Servlet servlet)
The registered servlet may be further configured via the returned
ServletRegistration object.
If this WebappContext already contains a preliminary ServletRegistration for a servlet with the given servletName, it will be completed (by assigning the class name of the given servlet instance to it) and returned.
addServlet in interface javax.servlet.ServletContextservletName - the name of the servletservlet - the servlet instance to registerjava.lang.IllegalStateException - if this WebappContext has already
been initializedjava.lang.IllegalArgumentException - if the given servlet instance
implements SingleThreadModelpublic ServletRegistration addServlet(java.lang.String servletName, java.lang.String className)
The registered servlet may be further configured via the returned
ServletRegistration object.
The specified className will be loaded using the classloader associated with the application represented by this WebappContext.
If this WebappContext already contains a preliminary ServletRegistration for a servlet with the given servletName, it will be completed (by assigning the given className to it) and returned.
addServlet in interface javax.servlet.ServletContextservletName - the name of the servletclassName - the fully qualified class name of the servletjava.lang.IllegalStateException - if this WebappContext has already
been initializedpublic FilterRegistration getFilterRegistration(java.lang.String name)
getFilterRegistration in interface javax.servlet.ServletContextpublic java.util.Map<java.lang.String,? extends FilterRegistration> getFilterRegistrations()
The returned Map includes the FilterRegistration objects corresponding to all declared and annotated filters, as well as the FilterRegistration objects corresponding to all filters that have been added via one of the addFilter methods.
Any changes to the returned Map must not affect this WebappContext.
getFilterRegistrations in interface javax.servlet.ServletContextpublic ServletRegistration getServletRegistration(java.lang.String name)
getServletRegistration in interface javax.servlet.ServletContextpublic java.util.Map<java.lang.String,? extends ServletRegistration> getServletRegistrations()
The returned Map includes the ServletRegistration objects corresponding to all declared and annotated servlets, as well as the ServletRegistration objects corresponding to all servlets that have been added via one of the addServlet methods.
If permitted, any changes to the returned Map must not affect this WebappContext.
getServletRegistrations in interface javax.servlet.ServletContextpublic void addListener(java.lang.Class<? extends java.util.EventListener> listenerClass)
The given listener must be an instance of one or more of the following interfaces:
ServletContextAttributeListener
ServletRequestListener
ServletRequestAttributeListener
HttpSessionListener
HttpSessionAttributeListener
If the given listener is an instance of a listener interface whose
invocation order corresponds to the declaration order (i.e., if it
is an instance of ServletRequestListener,
ServletContextListener, or
HttpSessionListener),
then the listener will be added to the end of the ordered list of
listeners of that interface.
addListener in interface javax.servlet.ServletContextjava.lang.IllegalArgumentException - if the given listener is not
an instance of any of the above interfacesjava.lang.IllegalStateException - if this WebappContext has already
been initializedpublic void addListener(java.lang.String className)
The class with the given name will be loaded using the classloader associated with the application represented by this WebappContext, and must implement one or more of the following interfaces:
ServletContextAttributeListener
ServletRequestListener
ServletRequestAttributeListener
HttpSessionListener
HttpSessionAttributeListener
As part of this method call, the container must load the class with the specified class name to ensure that it implements one of the required interfaces.
If the class with the given name implements a listener interface
whose invocation order corresponds to the declaration order (i.e.,
if it implements ServletRequestListener,
ServletContextListener, or
HttpSessionListener),
then the new listener will be added to the end of the ordered list of
listeners of that interface.
addListener in interface javax.servlet.ServletContextclassName - the fully qualified class name of the listenerjava.lang.IllegalArgumentException - if the class with the given name
does not implement any of the above interfacesjava.lang.IllegalStateException - if this WebappContext has already
been initializedpublic <T extends java.util.EventListener> void addListener(T eventListener)
addListener in interface javax.servlet.ServletContextpublic <T extends javax.servlet.Servlet> T createServlet(java.lang.Class<T> clazz)
throws javax.servlet.ServletException
createServlet in interface javax.servlet.ServletContextjavax.servlet.ServletExceptionpublic <T extends javax.servlet.Filter> T createFilter(java.lang.Class<T> clazz)
throws javax.servlet.ServletException
createFilter in interface javax.servlet.ServletContextjavax.servlet.ServletExceptionpublic <T extends java.util.EventListener> T createListener(java.lang.Class<T> clazz)
throws javax.servlet.ServletException
createListener in interface javax.servlet.ServletContextjavax.servlet.ServletExceptionpublic void declareRoles(java.lang.String... roleNames)
declareRoles in interface javax.servlet.ServletContextpublic java.lang.String getContextPath()
getContextPath in interface javax.servlet.ServletContextpublic javax.servlet.ServletContext getContext(java.lang.String uri)
getContext in interface javax.servlet.ServletContextpublic int getMajorVersion()
getMajorVersion in interface javax.servlet.ServletContextpublic int getMinorVersion()
getMinorVersion in interface javax.servlet.ServletContextpublic int getEffectiveMajorVersion()
getEffectiveMajorVersion in interface javax.servlet.ServletContextpublic int getEffectiveMinorVersion()
getEffectiveMinorVersion in interface javax.servlet.ServletContextpublic java.lang.String getMimeType(java.lang.String file)
getMimeType in interface javax.servlet.ServletContextpublic java.util.Set<java.lang.String> getResourcePaths(java.lang.String path)
getResourcePaths in interface javax.servlet.ServletContextpublic java.net.URL getResource(java.lang.String path)
throws java.net.MalformedURLException
getResource in interface javax.servlet.ServletContextjava.net.MalformedURLExceptionpublic java.io.InputStream getResourceAsStream(java.lang.String path)
getResourceAsStream in interface javax.servlet.ServletContextpublic javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
getRequestDispatcher in interface javax.servlet.ServletContextpublic javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String name)
getNamedDispatcher in interface javax.servlet.ServletContext@Deprecated
public javax.servlet.Servlet getServlet(java.lang.String name)
throws javax.servlet.ServletException
getServlet in interface javax.servlet.ServletContextjavax.servlet.ServletException@Deprecated public java.util.Enumeration<javax.servlet.Servlet> getServlets()
getServlets in interface javax.servlet.ServletContext@Deprecated public java.util.Enumeration<java.lang.String> getServletNames()
getServletNames in interface javax.servlet.ServletContextpublic void log(java.lang.String message)
log in interface javax.servlet.ServletContext@Deprecated
public void log(java.lang.Exception e,
java.lang.String message)
log in interface javax.servlet.ServletContextpublic void log(java.lang.String message,
java.lang.Throwable throwable)
log in interface javax.servlet.ServletContextpublic java.lang.String getRealPath(java.lang.String path)
getRealPath in interface javax.servlet.ServletContextpublic java.lang.String getVirtualServerName()
getVirtualServerName in interface javax.servlet.ServletContextpublic java.lang.String getServerInfo()
getServerInfo in interface javax.servlet.ServletContextpublic java.lang.String getInitParameter(java.lang.String name)
getInitParameter in interface javax.servlet.ServletContextpublic java.util.Enumeration<java.lang.String> getInitParameterNames()
getInitParameterNames in interface javax.servlet.ServletContextpublic boolean setInitParameter(java.lang.String name,
java.lang.String value)
setInitParameter in interface javax.servlet.ServletContextpublic java.lang.Object getAttribute(java.lang.String name)
getAttribute in interface javax.servlet.ServletContextpublic java.util.Enumeration<java.lang.String> getAttributeNames()
getAttributeNames in interface javax.servlet.ServletContextpublic void setAttribute(java.lang.String name,
java.lang.Object value)
setAttribute in interface javax.servlet.ServletContextpublic void removeAttribute(java.lang.String name)
removeAttribute in interface javax.servlet.ServletContextpublic java.lang.String getServletContextName()
getServletContextName in interface javax.servlet.ServletContextpublic javax.servlet.SessionCookieConfig getSessionCookieConfig()
getSessionCookieConfig in interface javax.servlet.ServletContextpublic void setSessionTrackingModes(java.util.Set<javax.servlet.SessionTrackingMode> sessionTrackingModes)
setSessionTrackingModes in interface javax.servlet.ServletContextpublic java.util.Set<javax.servlet.SessionTrackingMode> getDefaultSessionTrackingModes()
getDefaultSessionTrackingModes in interface javax.servlet.ServletContextpublic java.util.Set<javax.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes()
getEffectiveSessionTrackingModes in interface javax.servlet.ServletContextpublic javax.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()
getJspConfigDescriptor in interface javax.servlet.ServletContextpublic java.lang.ClassLoader getClassLoader()
getClassLoader in interface javax.servlet.ServletContextprotected java.lang.String normalize(java.lang.String path)
null instead.path - Path to be normalizedprotected java.lang.String getBasePath()
protected void setDispatcherHelper(DispatcherHelper dispatcherHelper)
dispatcherHelper - protected java.util.EventListener[] getEventListeners()
protected void addFilterMap(FilterMap filterMap, boolean isMatchAfter)
filterMap - The filter mapping to be addedisMatchAfter - true if the given filter mapping should be matched
against requests after any declared filter mappings of this servlet
context, and false if it is supposed to be matched before any declared
filter mappings of this servlet contextjava.lang.IllegalArgumentException - if the specified filter name
does not match an existing filter definition, or the filter mapping
is malformedprotected java.util.List<FilterMap> getFilterMaps()
protected void removeFilterMaps()
protected java.util.Collection<java.lang.String> getServletNameFilterMappings(java.lang.String filterName)
protected java.util.Collection<java.lang.String> getUrlPatternFilterMappings(java.lang.String filterName)
protected FilterChainFactory getFilterChainFactory()
protected void unregisterFilter(javax.servlet.Filter f)
protected void unregisterAllFilters()
protected void destroyFilters()
protected javax.servlet.Servlet createServletInstance(ServletRegistration registration) throws java.lang.Exception
java.lang.Exceptionprotected javax.servlet.Servlet createServletInstance(java.lang.Class<? extends javax.servlet.Servlet> servletClass)
throws java.lang.Exception
java.lang.Exceptionprotected javax.servlet.Filter createFilterInstance(FilterRegistration registration) throws java.lang.Exception
java.lang.Exceptionprotected javax.servlet.Filter createFilterInstance(java.lang.Class<? extends javax.servlet.Filter> filterClass)
throws java.lang.Exception
java.lang.Exceptionprotected java.util.EventListener createEventListenerInstance(java.lang.Class<? extends java.util.EventListener> eventListenerClass)
throws java.lang.Exception
java.lang.Exceptionprotected java.util.EventListener createEventListenerInstance(java.lang.String eventListenerClassname)
throws java.lang.Exception
java.lang.Exceptionpublic <T extends javax.servlet.http.HttpUpgradeHandler> T createHttpUpgradeHandlerInstance(java.lang.Class<T> clazz)
throws java.lang.Exception
T - clazz - java.lang.Exceptionprotected boolean validateURLPattern(java.lang.String urlPattern)
<url-pattern>
for conformance with specification requirements.urlPattern - URL pattern to be validatedCopyright © 2014 Oracle Corporation. All Rights Reserved.