Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.servlet

public Class WebappContext

extends Object
implements ServletContext
Class Inheritance
All Implemented Interfaces
jakarta.servlet.ServletContext
Static Imports
java.util.concurrent.TimeUnit.MINUTES, .TimeUnit.SECONDS

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.

Since
2.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
WebappContext.DispatchData

Internal class used as thread-local storage when doing path mapping during dispatch.

Field Summary

Modifier and TypeField and Description
private final ConcurrentMap<String, Object>
private final String
private final Map<String, String>
private final String
private static final Set<SessionTrackingMode>
protected boolean
private static final Map<WebappContext, HttpServer>
private DispatcherHelper
private final String
private final Set<EventListener>
private EventListener[]
private final FilterChainFactory
private final List<FilterMap>
filterMaps

The list of filter mappings for this application, in the order they were defined in the deployment descriptor.

protected final Map<String, FilterRegistration>
private static final Logger
private static final int
private static final int
private final Runnable
onDestroyListener

Destroy listener to be registered on ServletHandler to make sure we undeploy entire application when ServletHandler#destroy() is invoked.

private String
private String
private volatile String
private Set<ServletHandler>
protected final Map<String, ServletRegistration>
private SessionCookieConfig
sessionCookieConfig

Session cookie config

private SessionManager
pack-priv int
private Set<SessionTrackingMode>
protected final Map<String, FilterRegistration>
private ClassLoader

Constructor Summary

AccessConstructor and Description
protected
public
WebappContext(final String displayName)

Creates a simple WebappContext with the root being "/".

public
WebappContext(final String displayName, final String contextPath)

public
WebappContext(final String displayName, final String contextPath, final String basePath)

Method Summary

Modifier and TypeMethod and Description
public void
addContextInitParameter(final String name, final String value)

public FilterRegistration

Returns:

a FilterRegistration object that may be used to further configure the registered filter, or null if this WebappContext already contains a complete FilterRegistration for a filter with the given filterName
addFilter
(final String
the name of the filter
filterName
,
final Class<? extends Filter>
the class object from which the filter will be instantiated
filterClass
)

Implements jakarta.servlet.ServletContext.addFilter.

Adds the filter with the given name and class type to this servlet context.

public FilterRegistration

Returns:

a FilterRegistration object that may be used to further configure the given filter, or null if this WebappContext already contains a complete FilterRegistration for a filter with the given filterName or if the same filter instance has already been registered with this or another WebappContext in the same container
addFilter
(final String
the name of the filter
filterName
,
final Filter
the filter instance to register
filter
)

Implements jakarta.servlet.ServletContext.addFilter.

Registers the given filter instance with this WebappContext under the given filterName.

public FilterRegistration

Returns:

a FilterRegistration object that may be used to further configure the registered filter, or null if this WebappContext already contains a complete FilterRegistration for a filter with the given filterName
addFilter
(final String
the name of the filter
filterName
,
final String
the fully qualified class name of the filter
className
)

Implements jakarta.servlet.ServletContext.addFilter.

Adds the filter with the given name and class name to this servlet context.

protected void
addFilterMap(FilterMap
The filter mapping to be added
filterMap
,
boolean
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 context
isMatchAfter
)

Add a filter mapping to this Context.

public ServletRegistration.Dynamic
addJspFile(final String servletName, final String jspFile)

Implements jakarta.servlet.ServletContext.addJspFile.

Adds the servlet with the given jsp file to this servlet context.

public void
addListener(final Class<? extends EventListener> listenerClass)

Implements jakarta.servlet.ServletContext.addListener, jakarta.servlet.ServletContext.addListener.

Adds the given listener class to this WebappContext.

public void
addListener(String
the fully qualified class name of the listener
className
)

Implements jakarta.servlet.ServletContext.addListener, jakarta.servlet.ServletContext.addListener.

Adds the listener with the given class name to this WebappContext.

public <T extends EventListener> void
addListener(T eventListener)

Implements jakarta.servlet.ServletContext.addListener.

Adds the given listener to this ServletContext.

public ServletRegistration

Returns:

a ServletRegistration object that may be used to further configure the registered servlet, or null if this WebappContext already contains a complete ServletRegistration for the given servletName
addServlet
(final String
the name of the servlet
servletName
,
final Class<? extends Servlet>
the class object from which the servlet will be instantiated
servletClass
)

Implements jakarta.servlet.ServletContext.addServlet.

Adds the servlet with the given name and class type to this servlet context.

public ServletRegistration

Returns:

a ServletRegistration object that may be used to further configure the given servlet, or null if this WebappContext already contains a complete ServletRegistration for a servlet with the given servletName or if the same servlet instance has already been registered with this or another WebappContext in the same container
addServlet
(final String
the name of the servlet
servletName
,
final Servlet
the servlet instance to register
servlet
)

Implements jakarta.servlet.ServletContext.addServlet.

Registers the given servlet instance with this WebappContext under the given servletName.

public ServletRegistration

Returns:

a ServletRegistration object that may be used to further configure the registered servlet, or null if this WebappContext already contains a complete ServletRegistration for a servlet with the given servletName
addServlet
(final String
the name of the servlet
servletName
,
final String
the fully qualified class name of the servlet
className
)

Implements jakarta.servlet.ServletContext.addServlet.

Adds the servlet with the given name and class name to this servlet context.

private void
checkUnusualURLPattern(String urlPattern)

Check for unusual but valid <url-pattern>s.

public void
private void
private void
protected EventListener

Returns:

the new EventListener instance
createEventListenerInstance
(Class<? extends EventListener> eventListenerClass)

Instantiates the given EventListener class.

protected EventListener

Returns:

the new EventListener instance
createEventListenerInstance
(String eventListenerClassname)

Instantiates the given EventListener class.

public <T extends Filter> T
createFilter(Class<T> clazz)

Implements jakarta.servlet.ServletContext.createFilter.

Instantiates the given Filter class.

private FilterConfigImpl
protected Filter

Returns:

the new Filter instance
createFilterInstance
(final FilterRegistration registration)

Instantiates the given Filter class.

protected Filter

Returns:

the new Filter instance
createFilterInstance
(Class<? extends Filter> filterClass)

Instantiates the given Filter class.

public <T extends HttpUpgradeHandler> T

Returns:

a new T instance
createHttpUpgradeHandlerInstance
(Class<T> clazz)

Instantiates the given HttpUpgradeHandler class.

public <T extends EventListener> T
createListener(Class<T> clazz)

Implements jakarta.servlet.ServletContext.createListener.

Instantiates the given EventListener class.

public <T extends Servlet> T
createServlet(Class<T> clazz)

Implements jakarta.servlet.ServletContext.createServlet.

Instantiates the given Servlet class.

private ServletConfigImpl
protected Servlet

Returns:

the new Servlet instance
createServletInstance
(final ServletRegistration registration)

Instantiates the given Servlet class.

protected Servlet

Returns:

the new Servlet instance
createServletInstance
(Class<? extends Servlet> servletClass)

Instantiates the given Servlet class.

public void
declareRoles(String... roleNames)

Implements jakarta.servlet.ServletContext.declareRoles.

Declares role names that are tested using isUserInRole.

public synchronized void
deploy(final HttpServer targetServer)

protected void
private void
public Object
getAttribute(String name)

Implements jakarta.servlet.ServletContext.getAttribute.

Returns the servlet container attribute with the given name, or null if there is no attribute by that name.

public Enumeration<String>
getAttributeNames()

Implements jakarta.servlet.ServletContext.getAttributeNames.

Returns an Enumeration containing the attribute names available within this ServletContext.

protected String
public ClassLoader
getClassLoader()

Implements jakarta.servlet.ServletContext.getClassLoader.

Gets the class loader of the web application represented by this ServletContext.

public ServletContext
getContext(String uri)

Implements jakarta.servlet.ServletContext.getContext.

Returns a ServletContext object that corresponds to a specified URL on the server.

public String
getContextPath()

Implements jakarta.servlet.ServletContext.getContextPath.

Returns the context path of the web application.

public Set<SessionTrackingMode>
getDefaultSessionTrackingModes()

Implements jakarta.servlet.ServletContext.getDefaultSessionTrackingModes.

Gets the session tracking modes that are supported by default for this ServletContext.

public int
getEffectiveMajorVersion()

Implements jakarta.servlet.ServletContext.getEffectiveMajorVersion.

Gets the major version of the Servlet specification that the application represented by this ServletContext is based on.

public int
getEffectiveMinorVersion()

Implements jakarta.servlet.ServletContext.getEffectiveMinorVersion.

Gets the minor version of the Servlet specification that the application represented by this ServletContext is based on.

public Set<SessionTrackingMode>
getEffectiveSessionTrackingModes()

Implements jakarta.servlet.ServletContext.getEffectiveSessionTrackingModes.

Gets the session tracking modes that are in effect for this ServletContext.

protected EventListener[]
protected FilterChainFactory
protected List<FilterMap>
public FilterRegistration

Returns:

the (complete or preliminary) FilterRegistration for the filter with the given filterName, or null if no FilterRegistration exists under that name
getFilterRegistration
(final String name)

Implements jakarta.servlet.ServletContext.getFilterRegistration.

Gets the FilterRegistration corresponding to the filter with the given filterName.

public Map<String, ? extends FilterRegistration>

Returns:

Map of the (complete and preliminary) FilterRegistration objects corresponding to all filters currently registered with this WebappContext
getFilterRegistrations
()

Implements jakarta.servlet.ServletContext.getFilterRegistrations.

Gets a (possibly empty) Map of the FilterRegistration objects (keyed by filter name) corresponding to all filters registered with this WebappContext.

public String
getInitParameter(String name)

Implements jakarta.servlet.ServletContext.getInitParameter.

Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.

public Enumeration<String>
getInitParameterNames()

Implements jakarta.servlet.ServletContext.getInitParameterNames.

Returns the names of the context's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the context has no initialization parameters.

public JspConfigDescriptor
getJspConfigDescriptor()

Implements jakarta.servlet.ServletContext.getJspConfigDescriptor.

Gets the <jsp-config> related configuration that was aggregated from the web.xml and web-fragment.xml descriptor files of the web application represented by this ServletContext.

public int
getMajorVersion()

Implements jakarta.servlet.ServletContext.getMajorVersion.

Returns the major version of Jakarta Servlet specification that this container supports.

public String
getMimeType(String file)

Implements jakarta.servlet.ServletContext.getMimeType.

Returns the MIME type of the specified file, or null if the MIME type is not known.

public int
getMinorVersion()

Implements jakarta.servlet.ServletContext.getMinorVersion.

Returns the minor version of Jakarta Servlet specification that this container supports.

public RequestDispatcher
getNamedDispatcher(String name)

Implements jakarta.servlet.ServletContext.getNamedDispatcher.

Returns a RequestDispatcher object that acts as a wrapper for the named servlet.

public String
getRealPath(String path)

Implements jakarta.servlet.ServletContext.getRealPath.

Gets the real path corresponding to the given virtual path.

public String
getRequestCharacterEncoding()

Implements jakarta.servlet.ServletContext.getRequestCharacterEncoding.

Gets the request character encoding that are supported by default for this ServletContext.

public RequestDispatcher
getRequestDispatcher(String path)

Implements jakarta.servlet.ServletContext.getRequestDispatcher.

Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.

public URL
getResource(String path)

Implements jakarta.servlet.ServletContext.getResource.

Returns a URL to the resource that is mapped to the given path.

public InputStream
getResourceAsStream(String path)

Implements jakarta.servlet.ServletContext.getResourceAsStream.

Returns the resource located at the named path as an InputStream object.

public Set<String>
getResourcePaths(String path)

Implements jakarta.servlet.ServletContext.getResourcePaths.

Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument.

public String
getResponseCharacterEncoding()

Implements jakarta.servlet.ServletContext.getResponseCharacterEncoding.

Gets the response character encoding that are supported by default for this ServletContext.

public String
getServerInfo()

Implements jakarta.servlet.ServletContext.getServerInfo.

Returns the name and version of the servlet container on which the servlet is running.

public String
getServletContextName()

Implements jakarta.servlet.ServletContext.getServletContextName.

Returns the name of this web application corresponding to this ServletContext as specified in the deployment descriptor for this web application by the display-name element.

protected Collection<String>
getServletNameFilterMappings(String filterName)

Gets the current servlet name mappings of the Filter with the given name.

public ServletRegistration

Returns:

the (complete or preliminary) ServletRegistration for the servlet with the given servletName, or null if no ServletRegistration exists under that name
getServletRegistration
(final String name)

Implements jakarta.servlet.ServletContext.getServletRegistration.

Gets the ServletRegistration corresponding to the servlet with the given servletName.

public Map<String, ? extends ServletRegistration>

Returns:

Map of the (complete and preliminary) ServletRegistration objects corresponding to all servlets currently registered with this WebappContext
getServletRegistrations
()

Implements jakarta.servlet.ServletContext.getServletRegistrations.

Gets a (possibly empty) Map of the ServletRegistration objects (keyed by servlet name) corresponding to all servlets registered with this WebappContext.

public SessionCookieConfig
getSessionCookieConfig()

Implements jakarta.servlet.ServletContext.getSessionCookieConfig.

Gets the SessionCookieConfig object through which various properties of the session tracking cookies created on behalf of this ServletContext may be configured.

public int
getSessionTimeout()

Implements jakarta.servlet.ServletContext.getSessionTimeout.

Gets the session timeout in minutes that are supported by default for this ServletContext.

protected Collection<String>
getUrlPatternFilterMappings(String filterName)

Gets the current URL pattern mappings of the Filter with the given name.

public String
getVirtualServerName()

Implements jakarta.servlet.ServletContext.getVirtualServerName.

Returns the configuration name of the logical host on which the ServletContext is deployed.

private void
private void
private void
initServlets(final HttpServer server)

public void
log(String message)

Implements jakarta.servlet.ServletContext.log.

Writes the specified message to a servlet log file, usually an event log.

public void
log(String message, Throwable throwable)

Implements jakarta.servlet.ServletContext.log.

Writes an explanatory message and a stack trace for a given Throwable exception to the servlet log file.

protected String
normalize(String
Path to be normalized
path
)

Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path after ".." and "." elements are resolved out.

private void
public void
removeAttribute(String name)

Implements jakarta.servlet.ServletContext.removeAttribute.

Removes the attribute with the given name from this ServletContext.

public void
protected void
removeFilterMaps()

Removes any filter mappings from this Context.

public void
setAttribute(String name, Object value)

Implements jakarta.servlet.ServletContext.setAttribute.

Binds an object to a given attribute name in this ServletContext.

protected void
public boolean
setInitParameter(String name, String value)

Implements jakarta.servlet.ServletContext.setInitParameter.

Sets the context initialization parameter with the given name and value on this ServletContext.

public void
setRequestCharacterEncoding(final String requestEncoding)

Implements jakarta.servlet.ServletContext.setRequestCharacterEncoding.

Sets the request character encoding for this ServletContext.

public void
setResponseCharacterEncoding(final String responseEncoding)

Implements jakarta.servlet.ServletContext.setResponseCharacterEncoding.

Sets the response character encoding for this ServletContext.

public void
setServerInfo(final String
the string to be sent with the response.
serverInfo
)

Set the value of the Server header to be sent in the response.

public void
setSessionManager(SessionManager
an implementation of SessionManager
sessionManager
)

Sets the SessionManager that should be used by this WebappContext.

public void
setSessionTimeout(final int sessionTimeout)

Implements jakarta.servlet.ServletContext.setSessionTimeout.

Sets the session timeout in minutes for this ServletContext.

public void
setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes)

Implements jakarta.servlet.ServletContext.setSessionTrackingModes.

Sets the session tracking modes that are to become effective for this ServletContext.

public synchronized void
protected void
protected void
private static String
protected boolean
validateURLPattern(String
URL pattern to be validated
urlPattern
)

Validate the syntax of a proposed <url-pattern> for conformance with specification requirements.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait