org.eclipse.jetty.servlet
Class ServletContextHandler.Context

java.lang.Object
  extended by org.eclipse.jetty.server.handler.ContextHandler.Context
      extended by org.eclipse.jetty.servlet.ServletContextHandler.Context
All Implemented Interfaces:
ServletContext
Direct Known Subclasses:
WebAppContext.Context
Enclosing class:
ServletContextHandler

public class ServletContextHandler.Context
extends ContextHandler.Context


Field Summary
 
Fields inherited from class org.eclipse.jetty.server.handler.ContextHandler.Context
_enabled, _majorVersion, _minorVersion
 
Fields inherited from interface javax.servlet.ServletContext
ORDERED_LIBS, TEMPDIR
 
Constructor Summary
ServletContextHandler.Context()
           
 
Method Summary
 FilterRegistration.Dynamic addFilter(java.lang.String filterName, java.lang.Class<? extends Filter> filterClass)
          Adds the filter with the given name and class type to this servlet context.
 FilterRegistration.Dynamic addFilter(java.lang.String filterName, Filter filter)
          Registers the given filter instance with this ServletContext under the given filterName.
 FilterRegistration.Dynamic addFilter(java.lang.String filterName, java.lang.String className)
          Adds the filter with the given name and class name to this servlet context.
 void addListener(java.lang.Class<? extends java.util.EventListener> listenerClass)
          Adds a listener of the given class type to this ServletContext.
 void addListener(java.lang.String className)
          Adds the listener with the given class name to this ServletContext.
<T extends java.util.EventListener>
void
addListener(T t)
          Adds the given listener to this ServletContext.
 ServletRegistration.Dynamic addServlet(java.lang.String servletName, java.lang.Class<? extends Servlet> servletClass)
          Adds the servlet with the given name and class type to this servlet context.
 ServletRegistration.Dynamic addServlet(java.lang.String servletName, Servlet servlet)
          Registers the given servlet instance with this ServletContext under the given servletName.
 ServletRegistration.Dynamic addServlet(java.lang.String servletName, java.lang.String className)
          Adds the servlet with the given name and class name to this servlet context.
<T extends Filter>
T
createFilter(java.lang.Class<T> c)
          Instantiates the given Filter class.
<T extends java.util.EventListener>
T
createListener(java.lang.Class<T> clazz)
          Instantiates the given EventListener class.
<T extends Servlet>
T
createServlet(java.lang.Class<T> c)
          Instantiates the given Servlet class.
 void declareRoles(java.lang.String... roleNames)
          Declares role names that are tested using isUserInRole.
 java.util.Set<SessionTrackingMode> getDefaultSessionTrackingModes()
          Gets the session tracking modes that are supported by default for this ServletContext.
 java.util.Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
          Gets the session tracking modes that are in effect for this ServletContext.
 FilterRegistration getFilterRegistration(java.lang.String filterName)
          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 ServletContext.
 JspConfigDescriptor 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.
 RequestDispatcher getNamedDispatcher(java.lang.String name)
          Returns a RequestDispatcher object that acts as a wrapper for the named servlet.
 ServletRegistration getServletRegistration(java.lang.String servletName)
          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 ServletContext.
 SessionCookieConfig getSessionCookieConfig()
          Gets the SessionCookieConfig object through which various properties of the session tracking cookies created on behalf of this ServletContext may be configured.
 boolean setInitParameter(java.lang.String name, java.lang.String value)
          Sets the context initialization parameter with the given name and value on this ServletContext.
 void setSessionTrackingModes(java.util.Set<SessionTrackingMode> sessionTrackingModes)
          Sets the session tracking modes that are to become effective for this ServletContext.
 
Methods inherited from class org.eclipse.jetty.server.handler.ContextHandler.Context
getAttribute, getAttributeNames, getClassLoader, getContext, getContextHandler, getContextPath, getEffectiveMajorVersion, getEffectiveMinorVersion, getInitParameter, getInitParameterNames, getMajorVersion, getMimeType, getMinorVersion, getRealPath, getRequestDispatcher, getResource, getResourceAsStream, getResourcePaths, getServerInfo, getServlet, getServletContextName, getServletNames, getServlets, isEnabled, log, log, log, removeAttribute, setAttribute, setEffectiveMajorVersion, setEffectiveMinorVersion, setEnabled, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServletContextHandler.Context

public ServletContextHandler.Context()
Method Detail

getNamedDispatcher

public RequestDispatcher getNamedDispatcher(java.lang.String name)
Description copied from interface: ServletContext
Returns a RequestDispatcher object that acts as a wrapper for the named servlet.

Servlets (and JSP pages also) may be given names via server administration or via a web application deployment descriptor. A servlet instance can determine its name using ServletConfig.getServletName().

This method returns null if the ServletContext cannot return a RequestDispatcher for any reason.

Specified by:
getNamedDispatcher in interface ServletContext
Overrides:
getNamedDispatcher in class ContextHandler.Context
Parameters:
name - a String specifying the name of a servlet to wrap
Returns:
a RequestDispatcher object that acts as a wrapper for the named servlet, or null if the ServletContext cannot return a RequestDispatcher
See Also:
RequestDispatcher, ServletContext.getContext(java.lang.String), ServletConfig.getServletName()

addFilter

public FilterRegistration.Dynamic addFilter(java.lang.String filterName,
                                            java.lang.Class<? extends Filter> filterClass)
Description copied from interface: ServletContext
Adds the filter with the given name and class type to this servlet context.

The registered filter may be further configured via the returned FilterRegistration object.

If this ServletContext 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.

This method supports resource injection if the given filterClass represents a Managed Bean. See the Java EE platform and JSR 299 specifications for additional details about Managed Beans and resource injection.

Specified by:
addFilter in interface ServletContext
Overrides:
addFilter in class ContextHandler.Context
Parameters:
filterName - the name of the filter
filterClass - the class object from which the filter will be instantiated
Returns:
a FilterRegistration object that may be used to further configure the registered filter, or null if this ServletContext already contains a complete FilterRegistration for a filter with the given filterName
See Also:
ServletContext.addFilter(java.lang.String, java.lang.Class)

addFilter

public FilterRegistration.Dynamic addFilter(java.lang.String filterName,
                                            java.lang.String className)
Description copied from interface: ServletContext
Adds the filter with the given name and class name to this servlet context.

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 ServletContext.

If this ServletContext 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.

This method supports resource injection if the class with the given className represents a Managed Bean. See the Java EE platform and JSR 299 specifications for additional details about Managed Beans and resource injection.

Specified by:
addFilter in interface ServletContext
Overrides:
addFilter in class ContextHandler.Context
Parameters:
filterName - the name of the filter
className - the fully qualified class name of the filter
Returns:
a FilterRegistration object that may be used to further configure the registered filter, or null if this ServletContext already contains a complete FilterRegistration for a filter with the given filterName
See Also:
ServletContext.addFilter(java.lang.String, java.lang.String)

addFilter

public FilterRegistration.Dynamic addFilter(java.lang.String filterName,
                                            Filter filter)
Description copied from interface: ServletContext
Registers the given filter instance with this ServletContext under the given filterName.

The registered filter may be further configured via the returned FilterRegistration object.

If this ServletContext 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.

Specified by:
addFilter in interface ServletContext
Overrides:
addFilter in class ContextHandler.Context
Parameters:
filterName - the name of the filter
filter - the filter instance to register
Returns:
a FilterRegistration object that may be used to further configure the given filter, or null if this ServletContext 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 ServletContext in the same container
See Also:
ServletContext.addFilter(java.lang.String, javax.servlet.Filter)

addServlet

public ServletRegistration.Dynamic addServlet(java.lang.String servletName,
                                              java.lang.Class<? extends Servlet> servletClass)
Description copied from interface: ServletContext
Adds the servlet with the given name and class type to this servlet context.

The registered servlet may be further configured via the returned ServletRegistration object.

If this ServletContext 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.

This method introspects the given servletClass for the ServletSecurity, MultipartConfig, javax.annotation.security.RunAs, and javax.annotation.security.DeclareRoles annotations. In addition, this method supports resource injection if the given servletClass represents a Managed Bean. See the Java EE platform and JSR 299 specifications for additional details about Managed Beans and resource injection.

Specified by:
addServlet in interface ServletContext
Overrides:
addServlet in class ContextHandler.Context
Parameters:
servletName - the name of the servlet
servletClass - the class object from which the servlet will be instantiated
Returns:
a ServletRegistration object that may be used to further configure the registered servlet, or null if this ServletContext already contains a complete ServletRegistration for the given servletName
See Also:
ServletContext.addServlet(java.lang.String, java.lang.Class)

addServlet

public ServletRegistration.Dynamic addServlet(java.lang.String servletName,
                                              java.lang.String className)
Description copied from interface: ServletContext
Adds the servlet with the given name and class name to this servlet context.

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 ServletContext.

If this ServletContext 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.

This method introspects the class with the given className for the ServletSecurity, MultipartConfig, javax.annotation.security.RunAs, and javax.annotation.security.DeclareRoles annotations. In addition, this method supports resource injection if the class with the given className represents a Managed Bean. See the Java EE platform and JSR 299 specifications for additional details about Managed Beans and resource injection.

Specified by:
addServlet in interface ServletContext
Overrides:
addServlet in class ContextHandler.Context
Parameters:
servletName - the name of the servlet
className - the fully qualified class name of the servlet
Returns:
a ServletRegistration object that may be used to further configure the registered servlet, or null if this ServletContext already contains a complete ServletRegistration for a servlet with the given servletName
See Also:
ServletContext.addServlet(java.lang.String, java.lang.String)

addServlet

public ServletRegistration.Dynamic addServlet(java.lang.String servletName,
                                              Servlet servlet)
Description copied from interface: ServletContext
Registers the given servlet instance with this ServletContext under the given servletName.

The registered servlet may be further configured via the returned ServletRegistration object.

If this ServletContext 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.

Specified by:
addServlet in interface ServletContext
Overrides:
addServlet in class ContextHandler.Context
Parameters:
servletName - the name of the servlet
servlet - the servlet instance to register
Returns:
a ServletRegistration object that may be used to further configure the given servlet, or null if this ServletContext 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 ServletContext in the same container

setInitParameter

public boolean setInitParameter(java.lang.String name,
                                java.lang.String value)
Description copied from interface: ServletContext
Sets the context initialization parameter with the given name and value on this ServletContext.

Specified by:
setInitParameter in interface ServletContext
Overrides:
setInitParameter in class ContextHandler.Context
Parameters:
name - the name of the context initialization parameter to set
value - the value of the context initialization parameter to set
Returns:
true if the context initialization parameter with the given name and value was set successfully on this ServletContext, and false if it was not set because this ServletContext already contains a context initialization parameter with a matching name

createFilter

public <T extends Filter> T createFilter(java.lang.Class<T> c)
                              throws ServletException
Description copied from interface: ServletContext
Instantiates the given Filter class.

The returned Filter instance may be further customized before it is registered with this ServletContext via a call to ServletContext.addFilter(String,Filter).

The given Filter class must define a zero argument constructor, which is used to instantiate it.

This method supports resource injection if the given clazz represents a Managed Bean. See the Java EE platform and JSR 299 specifications for additional details about Managed Beans and resource injection.

Specified by:
createFilter in interface ServletContext
Overrides:
createFilter in class ContextHandler.Context
Parameters:
c - the Filter class to instantiate
Returns:
the new Filter instance
Throws:
ServletException - if the given clazz fails to be instantiated

createServlet

public <T extends Servlet> T createServlet(java.lang.Class<T> c)
                                throws ServletException
Description copied from interface: ServletContext
Instantiates the given Servlet class.

The returned Servlet instance may be further customized before it is registered with this ServletContext via a call to ServletContext.addServlet(String,Servlet).

The given Servlet class must define a zero argument constructor, which is used to instantiate it.

This method introspects the given clazz for the following annotations: ServletSecurity, MultipartConfig, javax.annotation.security.RunAs, and javax.annotation.security.DeclareRoles. In addition, this method supports resource injection if the given clazz represents a Managed Bean. See the Java EE platform and JSR 299 specifications for additional details about Managed Beans and resource injection.

Specified by:
createServlet in interface ServletContext
Overrides:
createServlet in class ContextHandler.Context
Parameters:
c - the Servlet class to instantiate
Returns:
the new Servlet instance
Throws:
ServletException - if the given clazz fails to be instantiated

getDefaultSessionTrackingModes

public java.util.Set<SessionTrackingMode> getDefaultSessionTrackingModes()
Description copied from interface: ServletContext
Gets the session tracking modes that are supported by default for this ServletContext.

Specified by:
getDefaultSessionTrackingModes in interface ServletContext
Overrides:
getDefaultSessionTrackingModes in class ContextHandler.Context
Returns:
set of the session tracking modes supported by default for this ServletContext

getEffectiveSessionTrackingModes

public java.util.Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
Description copied from interface: ServletContext
Gets the session tracking modes that are in effect for this ServletContext.

The session tracking modes in effect are those provided to setSessionTrackingModes.

By default, the session tracking modes returned by getDefaultSessionTrackingModes are in effect.

Specified by:
getEffectiveSessionTrackingModes in interface ServletContext
Overrides:
getEffectiveSessionTrackingModes in class ContextHandler.Context
Returns:
set of the session tracking modes in effect for this ServletContext

getFilterRegistration

public FilterRegistration getFilterRegistration(java.lang.String filterName)
Description copied from interface: ServletContext
Gets the FilterRegistration corresponding to the filter with the given filterName.

Specified by:
getFilterRegistration in interface ServletContext
Overrides:
getFilterRegistration in class ContextHandler.Context
Returns:
the (complete or preliminary) FilterRegistration for the filter with the given filterName, or null if no FilterRegistration exists under that name

getFilterRegistrations

public java.util.Map<java.lang.String,? extends FilterRegistration> getFilterRegistrations()
Description copied from interface: ServletContext
Gets a (possibly empty) Map of the FilterRegistration objects (keyed by filter name) corresponding to all filters registered with this ServletContext.

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 ServletContext.

Specified by:
getFilterRegistrations in interface ServletContext
Overrides:
getFilterRegistrations in class ContextHandler.Context
Returns:
Map of the (complete and preliminary) FilterRegistration objects corresponding to all filters currently registered with this ServletContext

getServletRegistration

public ServletRegistration getServletRegistration(java.lang.String servletName)
Description copied from interface: ServletContext
Gets the ServletRegistration corresponding to the servlet with the given servletName.

Specified by:
getServletRegistration in interface ServletContext
Overrides:
getServletRegistration in class ContextHandler.Context
Returns:
the (complete or preliminary) ServletRegistration for the servlet with the given servletName, or null if no ServletRegistration exists under that name

getServletRegistrations

public java.util.Map<java.lang.String,? extends ServletRegistration> getServletRegistrations()
Description copied from interface: ServletContext
Gets a (possibly empty) Map of the ServletRegistration objects (keyed by servlet name) corresponding to all servlets registered with this ServletContext.

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.

Any changes to the returned Map must not affect this ServletContext.

Specified by:
getServletRegistrations in interface ServletContext
Overrides:
getServletRegistrations in class ContextHandler.Context
Returns:
Map of the (complete and preliminary) ServletRegistration objects corresponding to all servlets currently registered with this ServletContext

getSessionCookieConfig

public SessionCookieConfig getSessionCookieConfig()
Description copied from interface: ServletContext
Gets the SessionCookieConfig object through which various properties of the session tracking cookies created on behalf of this ServletContext may be configured.

Repeated invocations of this method will return the same SessionCookieConfig instance.

Specified by:
getSessionCookieConfig in interface ServletContext
Overrides:
getSessionCookieConfig in class ContextHandler.Context
Returns:
the SessionCookieConfig object through which various properties of the session tracking cookies created on behalf of this ServletContext may be configured

setSessionTrackingModes

public void setSessionTrackingModes(java.util.Set<SessionTrackingMode> sessionTrackingModes)
Description copied from interface: ServletContext
Sets the session tracking modes that are to become effective for this ServletContext.

The given sessionTrackingModes replaces any session tracking modes set by a previous invocation of this method on this ServletContext.

Specified by:
setSessionTrackingModes in interface ServletContext
Overrides:
setSessionTrackingModes in class ContextHandler.Context
Parameters:
sessionTrackingModes - the set of session tracking modes to become effective for this ServletContext

addListener

public void addListener(java.lang.String className)
Description copied from interface: ServletContext
Adds the listener with the given class name to this ServletContext.

The class with the given name will be loaded using the classloader associated with the application represented by this ServletContext, and must implement one or more of the following interfaces:

If this ServletContext was passed to ServletContainerInitializer.onStartup(java.util.Set>, javax.servlet.ServletContext), then the class with the given name may also implement ServletContextListener, in addition to the interfaces listed above.

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.

This method supports resource injection if the class with the given className represents a Managed Bean. See the Java EE platform and JSR 299 specifications for additional details about Managed Beans and resource injection.

Specified by:
addListener in interface ServletContext
Overrides:
addListener in class ContextHandler.Context
Parameters:
className - the fully qualified class name of the listener

addListener

public <T extends java.util.EventListener> void addListener(T t)
Description copied from interface: ServletContext
Adds the given listener to this ServletContext.

The given listener must be an instance of one or more of the following interfaces:

If this ServletContext was passed to ServletContainerInitializer.onStartup(java.util.Set>, javax.servlet.ServletContext), then the given listener may also be an instance of ServletContextListener, in addition to the interfaces listed above.

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.

Specified by:
addListener in interface ServletContext
Overrides:
addListener in class ContextHandler.Context
Parameters:
t - the listener to be added

addListener

public void addListener(java.lang.Class<? extends java.util.EventListener> listenerClass)
Description copied from interface: ServletContext
Adds a listener of the given class type to this ServletContext.

The given listenerClass must implement one or more of the following interfaces:

If this ServletContext was passed to ServletContainerInitializer.onStartup(java.util.Set>, javax.servlet.ServletContext), then the given listenerClass may also implement ServletContextListener, in addition to the interfaces listed above.

If the given listenerClass 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.

This method supports resource injection if the given listenerClass represents a Managed Bean. See the Java EE platform and JSR 299 specifications for additional details about Managed Beans and resource injection.

Specified by:
addListener in interface ServletContext
Overrides:
addListener in class ContextHandler.Context
Parameters:
listenerClass - the listener class to be instantiated

createListener

public <T extends java.util.EventListener> T createListener(java.lang.Class<T> clazz)
                                                 throws ServletException
Description copied from interface: ServletContext
Instantiates the given EventListener class.

The specified EventListener class must implement at least one of the ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener, HttpSessionListener, or HttpSessionAttributeListener interfaces.

The returned EventListener instance may be further customized before it is registered with this ServletContext via a call to ServletContext.addListener(EventListener).

The given EventListener class must define a zero argument constructor, which is used to instantiate it.

This method supports resource injection if the given clazz represents a Managed Bean. See the Java EE platform and JSR 299 specifications for additional details about Managed Beans and resource injection.

Specified by:
createListener in interface ServletContext
Overrides:
createListener in class ContextHandler.Context
Parameters:
clazz - the EventListener class to instantiate
Returns:
the new EventListener instance
Throws:
ServletException - if the given clazz fails to be instantiated

getJspConfigDescriptor

public JspConfigDescriptor getJspConfigDescriptor()
Description copied from interface: ServletContext
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.

Specified by:
getJspConfigDescriptor in interface ServletContext
Overrides:
getJspConfigDescriptor in class ContextHandler.Context
Returns:
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, or null if no such configuration exists
See Also:
JspConfigDescriptor

declareRoles

public void declareRoles(java.lang.String... roleNames)
Description copied from interface: ServletContext
Declares role names that are tested using isUserInRole.

Roles that are implicitly declared as a result of their use within the setServletSecurity or setRunAsRole methods of the ServletRegistration interface need not be declared.

Specified by:
declareRoles in interface ServletContext
Overrides:
declareRoles in class ContextHandler.Context
Parameters:
roleNames - the role names being declared


Copyright © 1995-2010 Mort Bay Consulting. All Rights Reserved.