|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.glassfish.grizzly.servlet.WebappContext
public class WebappContext
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.
| Field Summary | |
|---|---|
protected boolean |
deployed
|
| Constructor Summary | |
|---|---|
protected |
WebappContext()
|
|
WebappContext(String displayName)
Creates a simple WebappContext with the root being "/". |
|
WebappContext(String displayName,
String contextPath)
|
|
WebappContext(String displayName,
String contextPath,
String basePath)
|
| Method Summary | |
|---|---|
void |
addContextInitParameter(String name,
String value)
|
FilterRegistration |
addFilter(String filterName,
Class<? extends javax.servlet.Filter> filterClass)
Adds the filter with the given name and class type to this servlet context. |
FilterRegistration |
addFilter(String filterName,
javax.servlet.Filter filter)
Registers the given filter instance with this WebappContext under the given filterName. |
FilterRegistration |
addFilter(String filterName,
String className)
Adds the filter with the given name and class name to this servlet context. |
void |
addListener(Class<? extends EventListener> listener)
Adds the given listener class to this WebappContext. |
void |
addListener(String className)
Adds the listener with the given class name to this WebappContext. |
ServletRegistration |
addServlet(String servletName,
Class<? extends javax.servlet.Servlet> servletClass)
Adds the servlet with the given name and class type to this servlet context. |
ServletRegistration |
addServlet(String servletName,
javax.servlet.Servlet servlet)
Registers the given servlet instance with this WebappContext under the given servletName. |
ServletRegistration |
addServlet(String servletName,
String className)
Adds the servlet with the given name and class name to this servlet context. |
void |
clearContextInitParameters()
|
void |
deploy(HttpServer targetServer)
|
Object |
getAttribute(String name)
|
Enumeration |
getAttributeNames()
|
protected String |
getBasePath()
|
javax.servlet.ServletContext |
getContext(String uri)
|
String |
getContextPath()
|
protected EventListener[] |
getEventListeners()
|
FilterRegistration |
getFilterRegistration(String name)
Gets the FilterRegistration corresponding to the filter with the given filterName. |
Map<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. |
String |
getInitParameter(String name)
|
Enumeration |
getInitParameterNames()
|
int |
getMajorVersion()
|
String |
getMimeType(String file)
|
int |
getMinorVersion()
|
javax.servlet.RequestDispatcher |
getNamedDispatcher(String name)
|
String |
getRealPath(String path)
|
javax.servlet.RequestDispatcher |
getRequestDispatcher(String path)
|
URL |
getResource(String path)
|
InputStream |
getResourceAsStream(String path)
|
Set |
getResourcePaths(String path)
|
String |
getServerInfo()
|
javax.servlet.Servlet |
getServlet(String name)
Deprecated. |
String |
getServletContextName()
|
Enumeration |
getServletNames()
Deprecated. |
ServletRegistration |
getServletRegistration(String name)
Gets the ServletRegistration corresponding to the servlet with the given servletName. |
Map<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. |
Enumeration |
getServlets()
Deprecated. |
void |
log(Exception e,
String message)
Deprecated. |
void |
log(String message)
|
void |
log(String message,
Throwable throwable)
|
protected String |
normalize(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(String name)
|
void |
removeContextInitParameter(String name)
|
void |
setAttribute(String name,
Object value)
|
protected void |
setDispatcherHelper(DispatcherHelper dispatcherHelper)
|
void |
undeploy()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected boolean deployed
| Constructor Detail |
|---|
protected WebappContext()
public WebappContext(String displayName)
Creates a simple WebappContext with the root being "/".
displayName -
public WebappContext(String displayName,
String contextPath)
public WebappContext(String displayName,
String contextPath,
String basePath)
| Method Detail |
|---|
public void deploy(HttpServer targetServer)
targetServer - public void undeploy()
public void addContextInitParameter(String name,
String value)
name - value - public void removeContextInitParameter(String name)
name - public void clearContextInitParameters()
public FilterRegistration addFilter(String filterName,
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.
filterName - the name of the filterfilterClass - the class object from which the filter will be
instantiated
IllegalStateException - if this WebappContext has already
been initialized
public FilterRegistration addFilter(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.
filterName - the name of the filterfilter - the filter instance to register
IllegalStateException - if this WebappContext has already
been initialized
public FilterRegistration addFilter(String filterName,
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.
filterName - the name of the filterclassName - the fully qualified class name of the filter
IllegalStateException - if this WebappContext has already
been initialized
public ServletRegistration addServlet(String servletName,
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.
servletName - the name of the servletservletClass - the class object from which the servlet will be
instantiated
IllegalStateException - if this WebappContext has already
been initialized
public ServletRegistration addServlet(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.
servletName - the name of the servletservlet - the servlet instance to register
IllegalStateException - if this WebappContext has already
been initialized
IllegalArgumentException - if the given servlet instance
implements SingleThreadModel
public ServletRegistration addServlet(String servletName,
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.
servletName - the name of the servletclassName - the fully qualified class name of the servlet
IllegalStateException - if this WebappContext has already
been initializedpublic FilterRegistration getFilterRegistration(String name)
public Map<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.
public ServletRegistration getServletRegistration(String name)
public Map<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.
public void addListener(Class<? extends EventListener> listener)
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.
IllegalArgumentException - if the given listener is not
an instance of any of the above interfaces
IllegalStateException - if this WebappContext has already
been initializedpublic void addListener(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.
className - the fully qualified class name of the listener
IllegalArgumentException - if the class with the given name
does not implement any of the above interfaces
IllegalStateException - if this WebappContext has already
been initializedpublic String getContextPath()
getContextPath in interface javax.servlet.ServletContextpublic javax.servlet.ServletContext getContext(String uri)
getContext in interface javax.servlet.ServletContextpublic int getMajorVersion()
getMajorVersion in interface javax.servlet.ServletContextpublic int getMinorVersion()
getMinorVersion in interface javax.servlet.ServletContextpublic String getMimeType(String file)
getMimeType in interface javax.servlet.ServletContextpublic Set getResourcePaths(String path)
getResourcePaths in interface javax.servlet.ServletContext
public URL getResource(String path)
throws MalformedURLException
getResource in interface javax.servlet.ServletContextMalformedURLExceptionpublic InputStream getResourceAsStream(String path)
getResourceAsStream in interface javax.servlet.ServletContextpublic javax.servlet.RequestDispatcher getRequestDispatcher(String path)
getRequestDispatcher in interface javax.servlet.ServletContextpublic javax.servlet.RequestDispatcher getNamedDispatcher(String name)
getNamedDispatcher in interface javax.servlet.ServletContext
@Deprecated
public javax.servlet.Servlet getServlet(String name)
throws javax.servlet.ServletException
getServlet in interface javax.servlet.ServletContextjavax.servlet.ServletException@Deprecated public Enumeration getServlets()
getServlets in interface javax.servlet.ServletContext@Deprecated public Enumeration getServletNames()
getServletNames in interface javax.servlet.ServletContextpublic void log(String message)
log in interface javax.servlet.ServletContext
@Deprecated
public void log(Exception e,
String message)
log in interface javax.servlet.ServletContext
public void log(String message,
Throwable throwable)
log in interface javax.servlet.ServletContextpublic String getRealPath(String path)
getRealPath in interface javax.servlet.ServletContextpublic String getServerInfo()
getServerInfo in interface javax.servlet.ServletContextpublic String getInitParameter(String name)
getInitParameter in interface javax.servlet.ServletContextpublic Enumeration getInitParameterNames()
getInitParameterNames in interface javax.servlet.ServletContextpublic Object getAttribute(String name)
getAttribute in interface javax.servlet.ServletContextpublic Enumeration getAttributeNames()
getAttributeNames in interface javax.servlet.ServletContext
public void setAttribute(String name,
Object value)
setAttribute in interface javax.servlet.ServletContextpublic void removeAttribute(String name)
removeAttribute in interface javax.servlet.ServletContextpublic String getServletContextName()
getServletContextName in interface javax.servlet.ServletContextprotected String normalize(String path)
null instead.
path - Path to be normalizedprotected String getBasePath()
protected void setDispatcherHelper(DispatcherHelper dispatcherHelper)
dispatcherHelper - protected EventListener[] getEventListeners()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||