@NotThreadSafe public class MockServletContext extends Object implements IServletContext310To400Migration
ServletContext interface.| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_SERVLET_CONTEXT_NAME |
static String |
DEFAULT_SERVLET_CONTEXT_PATH |
static int |
SERVLET_SPEC_MAJOR_VERSION |
static int |
SERVLET_SPEC_MINOR_VERSION |
| Modifier | Constructor and Description |
|---|---|
protected |
MockServletContext(String sContextPath,
String sResourceBasePath,
com.helger.commons.io.resourceprovider.IReadableResourceProvider aResourceLoader,
Map<String,String> aInitParams)
Create a new MockServletContext.
|
| Modifier and Type | Method and Description |
|---|---|
javax.servlet.FilterRegistration.Dynamic |
addFilter(String filterName,
Class<? extends javax.servlet.Filter> filterClass) |
javax.servlet.FilterRegistration.Dynamic |
addFilter(String filterName,
javax.servlet.Filter filter) |
javax.servlet.FilterRegistration.Dynamic |
addFilter(String filterName,
String className) |
void |
addInitParameter(String sName,
String sValue) |
void |
addListener(Class<? extends EventListener> listenerClass) |
void |
addListener(String className) |
<T extends EventListener> |
addListener(T t) |
javax.servlet.ServletRegistration.Dynamic |
addServlet(String servletName,
Class<? extends javax.servlet.Servlet> servletClass) |
javax.servlet.ServletRegistration.Dynamic |
addServlet(String servletName,
javax.servlet.Servlet servlet) |
javax.servlet.ServletRegistration.Dynamic |
addServlet(String servletName,
String className) |
static MockServletContext |
create()
Create a new
MockServletContext, using no base path and no context
path. |
static MockServletContext |
create(Map<String,String> aInitParams)
Create a new
MockServletContext, using no base path and no context
path using the provided initialization parameters. |
static MockServletContext |
create(String sContextPath)
Create a new
MockServletContext using no base path but the provided
context path. |
static MockServletContext |
create(String sContextPath,
Map<String,String> aInitParams)
Create a new
MockServletContext using the provided context path and
init parameters. |
static MockServletContext |
create(String sContextPath,
String sResourceBasePath)
Create a new
MockServletContext using the provided context path and
resource base oath. |
static MockServletContext |
create(String sContextPath,
String sResourceBasePath,
com.helger.commons.io.resourceprovider.IReadableResourceProvider aResourceLoader,
Map<String,String> aInitParams)
Create a new
MockServletContext with all possible parameters. |
<T extends javax.servlet.Filter> |
createFilter(Class<T> clazz) |
<T extends EventListener> |
createListener(Class<T> clazz) |
<T extends javax.servlet.Servlet> |
createServlet(Class<T> clazz) |
MockServletConfig |
createServletConfig(String sServletName)
Create a new
MockServletConfig object without servlet init
parameters. |
MockServletConfig |
createServletConfig(String sServletName,
Map<String,String> aServletInitParams)
Create a new
MockServletConfig object. |
void |
declareRoles(String... roleNames) |
Object |
getAttribute(String sName) |
Enumeration<String> |
getAttributeNames() |
ClassLoader |
getClassLoader() |
javax.servlet.ServletContext |
getContext(String sContextPath) |
String |
getContextPath() |
com.helger.commons.collection.impl.ICommonsSet<javax.servlet.SessionTrackingMode> |
getDefaultSessionTrackingModes() |
int |
getEffectiveMajorVersion() |
int |
getEffectiveMinorVersion() |
com.helger.commons.collection.impl.ICommonsSet<javax.servlet.SessionTrackingMode> |
getEffectiveSessionTrackingModes() |
javax.servlet.FilterRegistration |
getFilterRegistration(String filterName) |
com.helger.commons.collection.impl.ICommonsMap<String,? extends javax.servlet.FilterRegistration> |
getFilterRegistrations() |
String |
getInitParameter(String sName) |
Enumeration<String> |
getInitParameterNames() |
javax.servlet.descriptor.JspConfigDescriptor |
getJspConfigDescriptor() |
int |
getMajorVersion() |
String |
getMimeType(String sFilename) |
int |
getMinorVersion() |
javax.servlet.RequestDispatcher |
getNamedDispatcher(String sPath)
Deprecated.
|
String |
getRealPath(String sPath) |
javax.servlet.RequestDispatcher |
getRequestDispatcher(String sPath) |
URL |
getResource(String sPath) |
InputStream |
getResourceAsStream(String sPath) |
protected String |
getResourceLocation(String sPath)
Build a full resource location for the given path, prepending the resource
base path of this MockServletContext.
|
com.helger.commons.collection.impl.ICommonsSet<String> |
getResourcePaths(String sPath)
Deprecated.
|
String |
getServerInfo() |
javax.servlet.Servlet |
getServlet(String sName)
Deprecated.
|
String |
getServletContextName() |
Enumeration<String> |
getServletNames()
Deprecated.
|
MockServletPool |
getServletPool() |
javax.servlet.ServletRegistration |
getServletRegistration(String servletName) |
com.helger.commons.collection.impl.ICommonsMap<String,? extends javax.servlet.ServletRegistration> |
getServletRegistrations() |
Enumeration<javax.servlet.Servlet> |
getServlets()
Deprecated.
|
javax.servlet.SessionCookieConfig |
getSessionCookieConfig() |
String |
getVirtualServerName() |
protected void |
initListeners() |
void |
invalidate() |
MockHttpServletResponse |
invoke(javax.servlet.http.HttpServletRequest aHttpRequest) |
static boolean |
isReThrowListenerException() |
void |
log(Exception ex,
String sMessage)
Deprecated.
|
void |
log(String sMessage) |
void |
log(String sMessage,
Throwable ex) |
void |
registerContext(String sContextPath,
javax.servlet.ServletContext aContext) |
void |
removeAttribute(String sName) |
void |
setAttribute(String sName,
Object aValue) |
void |
setContextPath(String sContextPath) |
boolean |
setInitParameter(String sName,
String sValue) |
static void |
setReThrowListenerException(boolean bReThrowListenerException) |
void |
setServletContextName(String sServletContextName) |
void |
setSessionTrackingModes(Set<javax.servlet.SessionTrackingMode> sessionTrackingModes) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddJspFile, getRequestCharacterEncoding, getResponseCharacterEncoding, getSessionTimeout, setRequestCharacterEncoding, setResponseCharacterEncoding, setSessionTimeoutpublic static final int SERVLET_SPEC_MAJOR_VERSION
public static final int SERVLET_SPEC_MINOR_VERSION
public static final String DEFAULT_SERVLET_CONTEXT_NAME
public static final String DEFAULT_SERVLET_CONTEXT_PATH
protected MockServletContext(@Nullable String sContextPath, @Nullable String sResourceBasePath, @Nullable com.helger.commons.io.resourceprovider.IReadableResourceProvider aResourceLoader, @Nullable Map<String,String> aInitParams)
sContextPath - The context path to usesResourceBasePath - the WAR root directory (should not end with a slash)aResourceLoader - the IReadableResourceProvider to use (or null for the default)aInitParams - Optional map with initialization parameterspublic static boolean isReThrowListenerException()
true if runtime exceptions from context listeners
should be propagated to the outside or if they should be logged and
processing should continue. Default is false.public static void setReThrowListenerException(boolean bReThrowListenerException)
bReThrowListenerException - true to re-throw listener exceptions (on context inited
and destroyed)@OverrideOnDemand protected void initListeners()
@Nonnull protected String getResourceLocation(@Nonnull String sPath)
sPath - the path as specified@Nonnull public String getContextPath()
getContextPath in interface javax.servlet.ServletContextpublic void registerContext(@Nonnull String sContextPath, @Nonnull javax.servlet.ServletContext aContext)
@Nullable public javax.servlet.ServletContext getContext(@Nullable String sContextPath)
getContext in interface javax.servlet.ServletContext@Nonnegative public int getMajorVersion()
getMajorVersion in interface javax.servlet.ServletContext@Nonnegative public int getMinorVersion()
getMinorVersion in interface javax.servlet.ServletContext@Nullable public String getMimeType(@Nonnull String sFilename)
getMimeType in interface javax.servlet.ServletContext@UnsupportedOperation @Deprecated public com.helger.commons.collection.impl.ICommonsSet<String> getResourcePaths(String sPath)
getResourcePaths in interface javax.servlet.ServletContext@Nullable public URL getResource(@Nonnull String sPath) throws MalformedURLException
getResource in interface javax.servlet.ServletContextMalformedURLException@Nullable public InputStream getResourceAsStream(@Nonnull String sPath)
getResourceAsStream in interface javax.servlet.ServletContext@Nonnull public javax.servlet.RequestDispatcher getRequestDispatcher(@Nonnull String sPath)
getRequestDispatcher in interface javax.servlet.ServletContext@Nullable @Deprecated public javax.servlet.RequestDispatcher getNamedDispatcher(@Nullable String sPath)
getNamedDispatcher in interface javax.servlet.ServletContext@Deprecated public javax.servlet.Servlet getServlet(@Nullable String sName)
getServlet in interface javax.servlet.ServletContext@Deprecated @Nonnull public Enumeration<javax.servlet.Servlet> getServlets()
getServlets in interface javax.servlet.ServletContext@Deprecated @Nonnull public Enumeration<String> getServletNames()
getServletNames in interface javax.servlet.ServletContextpublic void log(@Nullable String sMessage)
log in interface javax.servlet.ServletContext@Deprecated public void log(@Nullable Exception ex, @Nullable String sMessage)
log in interface javax.servlet.ServletContextpublic void log(@Nullable String sMessage, @Nullable Throwable ex)
log in interface javax.servlet.ServletContext@Nonnull public String getRealPath(@Nonnull String sPath)
getRealPath in interface javax.servlet.ServletContext@Nonnull @Nonempty public String getServerInfo()
getServerInfo in interface javax.servlet.ServletContext@Nullable public String getInitParameter(@Nonnull String sName)
getInitParameter in interface javax.servlet.ServletContext@Nonnull public Enumeration<String> getInitParameterNames()
getInitParameterNames in interface javax.servlet.ServletContext@Nullable public Object getAttribute(@Nonnull String sName)
getAttribute in interface javax.servlet.ServletContext@Nonnull public Enumeration<String> getAttributeNames()
getAttributeNames in interface javax.servlet.ServletContextpublic final void setAttribute(@Nonnull String sName, @Nullable Object aValue)
setAttribute in interface javax.servlet.ServletContextpublic void removeAttribute(@Nonnull String sName)
removeAttribute in interface javax.servlet.ServletContext@Nullable public String getServletContextName()
getServletContextName in interface javax.servlet.ServletContext@Nonnull public MockServletConfig createServletConfig(@Nonnull @Nonempty String sServletName)
MockServletConfig object without servlet init
parameters.sServletName - Name of the servlet. May neither be null nor empty.MockServletConfig object for this servlet context.@Nonnull public MockServletConfig createServletConfig(@Nonnull @Nonempty String sServletName, @Nullable Map<String,String> aServletInitParams)
MockServletConfig object.sServletName - Name of the servlet. May neither be null nor empty.aServletInitParams - The map with all servlet init parameters. May be null
or empty.MockServletConfig object for this servlet context.@Nonnull public MockServletPool getServletPool()
@Nullable public MockHttpServletResponse invoke(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
public void invalidate()
public int getEffectiveMajorVersion()
getEffectiveMajorVersion in interface javax.servlet.ServletContextpublic int getEffectiveMinorVersion()
getEffectiveMinorVersion in interface javax.servlet.ServletContextpublic boolean setInitParameter(String sName, String sValue)
setInitParameter in interface javax.servlet.ServletContext@UnsupportedOperation public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, String className)
addServlet in interface javax.servlet.ServletContext@UnsupportedOperation public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, javax.servlet.Servlet servlet)
addServlet in interface javax.servlet.ServletContext@UnsupportedOperation public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends javax.servlet.Servlet> servletClass)
addServlet in interface javax.servlet.ServletContext@UnsupportedOperation public <T extends javax.servlet.Servlet> T createServlet(Class<T> clazz) throws javax.servlet.ServletException
createServlet in interface javax.servlet.ServletContextjavax.servlet.ServletException@UnsupportedOperation public javax.servlet.ServletRegistration getServletRegistration(String servletName)
getServletRegistration in interface javax.servlet.ServletContext@UnsupportedOperation public com.helger.commons.collection.impl.ICommonsMap<String,? extends javax.servlet.ServletRegistration> getServletRegistrations()
getServletRegistrations in interface javax.servlet.ServletContext@UnsupportedOperation public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, String className)
addFilter in interface javax.servlet.ServletContext@UnsupportedOperation public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, javax.servlet.Filter filter)
addFilter in interface javax.servlet.ServletContext@UnsupportedOperation public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends javax.servlet.Filter> filterClass)
addFilter in interface javax.servlet.ServletContext@UnsupportedOperation public <T extends javax.servlet.Filter> T createFilter(Class<T> clazz) throws javax.servlet.ServletException
createFilter in interface javax.servlet.ServletContextjavax.servlet.ServletException@UnsupportedOperation public javax.servlet.FilterRegistration getFilterRegistration(String filterName)
getFilterRegistration in interface javax.servlet.ServletContext@UnsupportedOperation public com.helger.commons.collection.impl.ICommonsMap<String,? extends javax.servlet.FilterRegistration> getFilterRegistrations()
getFilterRegistrations in interface javax.servlet.ServletContext@UnsupportedOperation public javax.servlet.SessionCookieConfig getSessionCookieConfig()
getSessionCookieConfig in interface javax.servlet.ServletContext@UnsupportedOperation public void setSessionTrackingModes(Set<javax.servlet.SessionTrackingMode> sessionTrackingModes)
setSessionTrackingModes in interface javax.servlet.ServletContext@UnsupportedOperation public com.helger.commons.collection.impl.ICommonsSet<javax.servlet.SessionTrackingMode> getDefaultSessionTrackingModes()
getDefaultSessionTrackingModes in interface javax.servlet.ServletContext@UnsupportedOperation public com.helger.commons.collection.impl.ICommonsSet<javax.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes()
getEffectiveSessionTrackingModes in interface javax.servlet.ServletContext@UnsupportedOperation public void addListener(String className)
addListener in interface javax.servlet.ServletContext@UnsupportedOperation public <T extends EventListener> void addListener(T t)
addListener in interface javax.servlet.ServletContext@UnsupportedOperation public void addListener(Class<? extends EventListener> listenerClass)
addListener in interface javax.servlet.ServletContext@UnsupportedOperation public <T extends EventListener> T createListener(Class<T> clazz) throws javax.servlet.ServletException
createListener in interface javax.servlet.ServletContextjavax.servlet.ServletException@UnsupportedOperation public javax.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()
getJspConfigDescriptor in interface javax.servlet.ServletContextpublic ClassLoader getClassLoader()
getClassLoader in interface javax.servlet.ServletContext@UnsupportedOperation public void declareRoles(String... roleNames)
declareRoles in interface javax.servlet.ServletContextpublic String getVirtualServerName()
getVirtualServerName in interface IServletContext300To310MigrationgetVirtualServerName in interface javax.servlet.ServletContext@Nonnull public static MockServletContext create()
MockServletContext, using no base path and no context
path. The initialization listeners are triggered automatically.MockServletContext@Nonnull public static MockServletContext create(@Nullable Map<String,String> aInitParams)
MockServletContext, using no base path and no context
path using the provided initialization parameters. The initialization
listeners are triggered automatically.aInitParams - The init parameter. May be null.MockServletContext@Nonnull public static MockServletContext create(@Nullable String sContextPath)
MockServletContext using no base path but the provided
context path. The initialization listeners are triggered automatically.sContextPath - The context path to use. May be null.MockServletContext@Nonnull public static MockServletContext create(@Nullable String sContextPath, @Nullable Map<String,String> aInitParams)
MockServletContext using the provided context path and
init parameters. The initialization listeners are triggered automatically.sContextPath - Context path to use. May be null.aInitParams - The init parameter. May be null.MockServletContext@Nonnull public static MockServletContext create(@Nullable String sContextPath, @Nullable String sResourceBasePath)
MockServletContext using the provided context path and
resource base oath. The initialization listeners are triggered
automatically.sContextPath - The context path to use. May be null.sResourceBasePath - the WAR root directory (should not end with a slash). May be
null.MockServletContext@Nonnull public static MockServletContext create(@Nullable String sContextPath, @Nullable String sResourceBasePath, @Nullable com.helger.commons.io.resourceprovider.IReadableResourceProvider aResourceLoader, @Nullable Map<String,String> aInitParams)
MockServletContext with all possible parameters.sContextPath - The context path to use. May be null.sResourceBasePath - the WAR root directory (should not end with a slash). May be
null.aResourceLoader - the IReadableResourceProvider to use. May be null.aInitParams - Optional map with initialization parameters. May be
null.MockServletContextCopyright © 2016–2019 Philip Helger. All rights reserved.