public class MockServletContext
extends java.lang.Object
implements javax.servlet.ServletContext
ServletContext
interface.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
TEMP_DIR_CONTEXT_ATTRIBUTE |
Constructor and Description |
---|
MockServletContext()
Create a new
MockServletContext , using no base path (i.e. |
MockServletContext(java.lang.String resourceBasePath)
Create a new
MockServletContext using the supplied resource base path. |
Modifier and Type | Method and Description |
---|---|
javax.servlet.FilterRegistration.Dynamic |
addFilter(java.lang.String filterName,
java.lang.Class<? extends javax.servlet.Filter> filterClass) |
javax.servlet.FilterRegistration.Dynamic |
addFilter(java.lang.String filterName,
javax.servlet.Filter filter) |
javax.servlet.FilterRegistration.Dynamic |
addFilter(java.lang.String filterName,
java.lang.String className) |
void |
addInitParameter(java.lang.String name,
java.lang.String value) |
void |
addListener(java.lang.Class<? extends java.util.EventListener> listenerClass) |
void |
addListener(java.lang.String className) |
<T extends java.util.EventListener> |
addListener(T t) |
javax.servlet.ServletRegistration.Dynamic |
addServlet(java.lang.String servletName,
java.lang.Class<? extends javax.servlet.Servlet> servletClass) |
javax.servlet.ServletRegistration.Dynamic |
addServlet(java.lang.String servletName,
javax.servlet.Servlet servlet) |
javax.servlet.ServletRegistration.Dynamic |
addServlet(java.lang.String servletName,
java.lang.String className) |
<T extends javax.servlet.Filter> |
createFilter(java.lang.Class<T> c) |
<T extends java.util.EventListener> |
createListener(java.lang.Class<T> c) |
<T extends javax.servlet.Servlet> |
createServlet(java.lang.Class<T> c) |
void |
declareRoles(java.lang.String... roleNames) |
java.lang.Object |
getAttribute(java.lang.String name) |
java.util.Enumeration<java.lang.String> |
getAttributeNames() |
java.lang.ClassLoader |
getClassLoader() |
javax.servlet.ServletContext |
getContext(java.lang.String contextPath) |
java.lang.String |
getContextPath() |
java.util.Set<java.lang.String> |
getDeclaredRoles() |
java.lang.String |
getDefaultServletName()
Get the name of the default
Servlet . |
java.util.Set<javax.servlet.SessionTrackingMode> |
getDefaultSessionTrackingModes() |
int |
getEffectiveMajorVersion() |
int |
getEffectiveMinorVersion() |
java.util.Set<javax.servlet.SessionTrackingMode> |
getEffectiveSessionTrackingModes() |
javax.servlet.FilterRegistration |
getFilterRegistration(java.lang.String filterName)
This method always returns
null . |
java.util.Map<java.lang.String,? extends javax.servlet.FilterRegistration> |
getFilterRegistrations()
This method always returns an empty map.
|
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 filePath)
This method uses the default
FileTypeMap
from the Java Activation Framework to resolve MIME types. |
int |
getMinorVersion() |
javax.servlet.RequestDispatcher |
getNamedDispatcher(java.lang.String path) |
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) |
protected java.lang.String |
getResourceLocation(java.lang.String path)
Build a full resource location for the given path, prepending the resource
base path of this
MockServletContext . |
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() |
java.util.Enumeration<java.lang.String> |
getServletNames()
Deprecated.
|
javax.servlet.ServletRegistration |
getServletRegistration(java.lang.String servletName)
This method always returns
null . |
java.util.Map<java.lang.String,? extends javax.servlet.ServletRegistration> |
getServletRegistrations()
This method always returns an empty map.
|
java.util.Enumeration<javax.servlet.Servlet> |
getServlets()
Deprecated.
|
javax.servlet.SessionCookieConfig |
getSessionCookieConfig() |
java.lang.String |
getVirtualServerName() |
void |
log(java.lang.Exception ex,
java.lang.String message)
Deprecated.
|
void |
log(java.lang.String message) |
void |
log(java.lang.String message,
java.lang.Throwable ex) |
void |
registerContext(java.lang.String contextPath,
javax.servlet.ServletContext context) |
void |
registerNamedDispatcher(java.lang.String name,
javax.servlet.RequestDispatcher requestDispatcher)
Register a
RequestDispatcher (typically a MockRequestDispatcher )
that acts as a wrapper for the named Servlet. |
void |
removeAttribute(java.lang.String name) |
void |
setAttribute(java.lang.String name,
java.lang.Object value) |
void |
setContextPath(java.lang.String contextPath) |
void |
setDefaultServletName(java.lang.String defaultServletName)
Set the name of the default
Servlet . |
void |
setEffectiveMajorVersion(int effectiveMajorVersion) |
void |
setEffectiveMinorVersion(int effectiveMinorVersion) |
boolean |
setInitParameter(java.lang.String name,
java.lang.String value) |
void |
setMajorVersion(int majorVersion) |
void |
setMinorVersion(int minorVersion) |
void |
setServletContextName(java.lang.String servletContextName) |
void |
setSessionTrackingModes(java.util.Set<javax.servlet.SessionTrackingMode> sessionTrackingModes) |
void |
unregisterNamedDispatcher(java.lang.String name)
Unregister the
RequestDispatcher with the given name. |
public static final java.lang.String TEMP_DIR_CONTEXT_ATTRIBUTE
public MockServletContext()
MockServletContext
, using no base path (i.e. the classpath root as WAR root).public MockServletContext(java.lang.String resourceBasePath)
MockServletContext
using the supplied resource base path.
Registers a MockRequestDispatcher
for the Servlet named 'default'.
resourceBasePath
- the root directory of the WAR (should not end with a slash)registerNamedDispatcher(java.lang.String, javax.servlet.RequestDispatcher)
protected java.lang.String getResourceLocation(java.lang.String path)
MockServletContext
.path
- the path as specifiedpublic void setContextPath(java.lang.String contextPath)
public java.lang.String getContextPath()
getContextPath
in interface javax.servlet.ServletContext
public void registerContext(java.lang.String contextPath, javax.servlet.ServletContext context)
public javax.servlet.ServletContext getContext(java.lang.String contextPath)
getContext
in interface javax.servlet.ServletContext
public void setMajorVersion(int majorVersion)
public int getMajorVersion()
getMajorVersion
in interface javax.servlet.ServletContext
public void setMinorVersion(int minorVersion)
public int getMinorVersion()
getMinorVersion
in interface javax.servlet.ServletContext
public void setEffectiveMajorVersion(int effectiveMajorVersion)
public int getEffectiveMajorVersion()
getEffectiveMajorVersion
in interface javax.servlet.ServletContext
public void setEffectiveMinorVersion(int effectiveMinorVersion)
public int getEffectiveMinorVersion()
getEffectiveMinorVersion
in interface javax.servlet.ServletContext
public java.lang.String getMimeType(java.lang.String filePath)
FileTypeMap
from the Java Activation Framework to resolve MIME types.
The Java Activation Framework returns "application/octet-stream"
if the MIME type is unknown (i.e., it never returns null
). Thus, in
order to honor the ServletContext.getMimeType(String)
contract,
this method returns null
if the MIME type is
"application/octet-stream"
.
MockServletContext
does not provide a direct mechanism for
setting a custom MIME type; however, if the default FileTypeMap
is an instance of javax.activation.MimetypesFileTypeMap
, a custom
MIME type named text/enigma
can be registered for a custom
.puzzle
file extension in the following manner:
MimetypesFileTypeMap mimetypesFileTypeMap = (MimetypesFileTypeMap) FileTypeMap.getDefaultFileTypeMap(); mimetypesFileTypeMap.addMimeTypes("text/enigma puzzle");
getMimeType
in interface javax.servlet.ServletContext
public java.util.Set<java.lang.String> getResourcePaths(java.lang.String path)
getResourcePaths
in interface javax.servlet.ServletContext
public java.net.URL getResource(java.lang.String path) throws java.net.MalformedURLException
getResource
in interface javax.servlet.ServletContext
java.net.MalformedURLException
public java.io.InputStream getResourceAsStream(java.lang.String path)
getResourceAsStream
in interface javax.servlet.ServletContext
public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
getRequestDispatcher
in interface javax.servlet.ServletContext
public javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String path)
getNamedDispatcher
in interface javax.servlet.ServletContext
public void registerNamedDispatcher(java.lang.String name, javax.servlet.RequestDispatcher requestDispatcher)
RequestDispatcher
(typically a MockRequestDispatcher
)
that acts as a wrapper for the named Servlet.name
- the name of the wrapped ServletrequestDispatcher
- the dispatcher that wraps the named ServletgetNamedDispatcher(java.lang.String)
,
unregisterNamedDispatcher(java.lang.String)
public void unregisterNamedDispatcher(java.lang.String name)
RequestDispatcher
with the given name.name
- the name of the dispatcher to unregistergetNamedDispatcher(java.lang.String)
,
registerNamedDispatcher(java.lang.String, javax.servlet.RequestDispatcher)
public java.lang.String getDefaultServletName()
Servlet
.
Defaults to 'default'.
setDefaultServletName(java.lang.String)
public void setDefaultServletName(java.lang.String defaultServletName)
Servlet
.
Also unregisters
the current default
RequestDispatcher
and replaces
it with a MockRequestDispatcher
for the provided
defaultServletName
.
defaultServletName
- the name of the default Servlet
;
never null
or emptygetDefaultServletName()
@Deprecated public javax.servlet.Servlet getServlet(java.lang.String name)
getServlet
in interface javax.servlet.ServletContext
@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.ServletContext
public void log(java.lang.String message)
log
in interface javax.servlet.ServletContext
@Deprecated public void log(java.lang.Exception ex, java.lang.String message)
log
in interface javax.servlet.ServletContext
public void log(java.lang.String message, java.lang.Throwable ex)
log
in interface javax.servlet.ServletContext
public java.lang.String getRealPath(java.lang.String path)
getRealPath
in interface javax.servlet.ServletContext
public java.lang.String getServerInfo()
getServerInfo
in interface javax.servlet.ServletContext
public java.lang.String getInitParameter(java.lang.String name)
getInitParameter
in interface javax.servlet.ServletContext
public java.util.Enumeration<java.lang.String> getInitParameterNames()
getInitParameterNames
in interface javax.servlet.ServletContext
public boolean setInitParameter(java.lang.String name, java.lang.String value)
setInitParameter
in interface javax.servlet.ServletContext
public void addInitParameter(java.lang.String name, java.lang.String value)
public java.lang.Object getAttribute(java.lang.String name)
getAttribute
in interface javax.servlet.ServletContext
public java.util.Enumeration<java.lang.String> getAttributeNames()
getAttributeNames
in interface javax.servlet.ServletContext
public void setAttribute(java.lang.String name, java.lang.Object value)
setAttribute
in interface javax.servlet.ServletContext
public void removeAttribute(java.lang.String name)
removeAttribute
in interface javax.servlet.ServletContext
public void setServletContextName(java.lang.String servletContextName)
public java.lang.String getServletContextName()
getServletContextName
in interface javax.servlet.ServletContext
public java.lang.ClassLoader getClassLoader()
getClassLoader
in interface javax.servlet.ServletContext
public void declareRoles(java.lang.String... roleNames)
declareRoles
in interface javax.servlet.ServletContext
public java.util.Set<java.lang.String> getDeclaredRoles()
public void setSessionTrackingModes(java.util.Set<javax.servlet.SessionTrackingMode> sessionTrackingModes) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
setSessionTrackingModes
in interface javax.servlet.ServletContext
java.lang.IllegalStateException
java.lang.IllegalArgumentException
public java.util.Set<javax.servlet.SessionTrackingMode> getDefaultSessionTrackingModes()
getDefaultSessionTrackingModes
in interface javax.servlet.ServletContext
public java.util.Set<javax.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes()
getEffectiveSessionTrackingModes
in interface javax.servlet.ServletContext
public javax.servlet.SessionCookieConfig getSessionCookieConfig()
getSessionCookieConfig
in interface javax.servlet.ServletContext
public javax.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()
getJspConfigDescriptor
in interface javax.servlet.ServletContext
public javax.servlet.ServletRegistration.Dynamic addServlet(java.lang.String servletName, java.lang.String className)
addServlet
in interface javax.servlet.ServletContext
public javax.servlet.ServletRegistration.Dynamic addServlet(java.lang.String servletName, javax.servlet.Servlet servlet)
addServlet
in interface javax.servlet.ServletContext
public javax.servlet.ServletRegistration.Dynamic addServlet(java.lang.String servletName, java.lang.Class<? extends javax.servlet.Servlet> servletClass)
addServlet
in interface javax.servlet.ServletContext
public <T extends javax.servlet.Servlet> T createServlet(java.lang.Class<T> c) throws javax.servlet.ServletException
createServlet
in interface javax.servlet.ServletContext
javax.servlet.ServletException
public javax.servlet.ServletRegistration getServletRegistration(java.lang.String servletName)
null
.getServletRegistration
in interface javax.servlet.ServletContext
ServletContext.getServletRegistration(java.lang.String)
public java.util.Map<java.lang.String,? extends javax.servlet.ServletRegistration> getServletRegistrations()
getServletRegistrations
in interface javax.servlet.ServletContext
ServletContext.getServletRegistrations()
public javax.servlet.FilterRegistration.Dynamic addFilter(java.lang.String filterName, java.lang.String className)
addFilter
in interface javax.servlet.ServletContext
public javax.servlet.FilterRegistration.Dynamic addFilter(java.lang.String filterName, javax.servlet.Filter filter)
addFilter
in interface javax.servlet.ServletContext
public javax.servlet.FilterRegistration.Dynamic addFilter(java.lang.String filterName, java.lang.Class<? extends javax.servlet.Filter> filterClass)
addFilter
in interface javax.servlet.ServletContext
public <T extends javax.servlet.Filter> T createFilter(java.lang.Class<T> c) throws javax.servlet.ServletException
createFilter
in interface javax.servlet.ServletContext
javax.servlet.ServletException
public javax.servlet.FilterRegistration getFilterRegistration(java.lang.String filterName)
null
.getFilterRegistration
in interface javax.servlet.ServletContext
ServletContext.getFilterRegistration(java.lang.String)
public java.util.Map<java.lang.String,? extends javax.servlet.FilterRegistration> getFilterRegistrations()
getFilterRegistrations
in interface javax.servlet.ServletContext
ServletContext.getFilterRegistrations()
public void addListener(java.lang.Class<? extends java.util.EventListener> listenerClass)
addListener
in interface javax.servlet.ServletContext
public void addListener(java.lang.String className)
addListener
in interface javax.servlet.ServletContext
public <T extends java.util.EventListener> void addListener(T t)
addListener
in interface javax.servlet.ServletContext
public <T extends java.util.EventListener> T createListener(java.lang.Class<T> c) throws javax.servlet.ServletException
createListener
in interface javax.servlet.ServletContext
javax.servlet.ServletException
public java.lang.String getVirtualServerName()
getVirtualServerName
in interface javax.servlet.ServletContext
Copyright © 2001-2018 Jalios SA. All Rights Reserved.