Class BaseResourceServletContext
java.lang.Object
de.aristaflow.adept2.base.servletcontainer.dynamic.BaseResourceServletContext
- All Implemented Interfaces:
jakarta.servlet.ServletContext
A wrapping servlet context that loads resources relative to a provided class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final jakarta.servlet.ServletContextThe servlet context to which to delegate to.static final StringThe protocol for a file.static final StringThe protocol for a Jar-file.protected final Class<?>The class relative to which we try to load resources.protected final URLThe URL that is the base of our loader (class) .protected final LoggerThe logger for logging exception messages and important proceed information.Fields inherited from interface jakarta.servlet.ServletContext
ORDERED_LIBS, TEMPDIR -
Constructor Summary
ConstructorsConstructorDescriptionBaseResourceServletContext(jakarta.servlet.ServletContext context, Class<?> loader, Logger logger) -
Method Summary
Modifier and TypeMethodDescriptionjakarta.servlet.FilterRegistration.Dynamicjakarta.servlet.FilterRegistration.Dynamicjakarta.servlet.FilterRegistration.Dynamicjakarta.servlet.ServletRegistration.DynamicaddJspFile(String servletName, String jspFile) voidaddListener(Class<? extends EventListener> listenerClass) voidaddListener(String className) <T extends EventListener>
voidaddListener(T t) jakarta.servlet.ServletRegistration.DynamicaddServlet(String servletName, jakarta.servlet.Servlet servlet) jakarta.servlet.ServletRegistration.DynamicaddServlet(String servletName, Class<? extends jakarta.servlet.Servlet> servletClass) jakarta.servlet.ServletRegistration.DynamicaddServlet(String servletName, String className) <T extends jakarta.servlet.Filter>
TcreateFilter(Class<T> clazz) <T extends EventListener>
TcreateListener(Class<T> clazz) <T extends jakarta.servlet.Servlet>
TcreateServlet(Class<T> clazz) voiddeclareRoles(String... roleNames) getAttribute(String name) getChildren(String entryPath, JarFile file) Gets the children for the designated path in the designated jar-file.jakarta.servlet.ServletContextgetContext(String uripath) Set<jakarta.servlet.SessionTrackingMode>intintSet<jakarta.servlet.SessionTrackingMode>jakarta.servlet.FilterRegistrationgetFilterRegistration(String filterName) getInitParameter(String name) jakarta.servlet.descriptor.JspConfigDescriptorintgetMimeType(String file) intjakarta.servlet.RequestDispatchergetNamedDispatcher(String name) getRealPath(String path) jakarta.servlet.RequestDispatchergetRequestDispatcher(String path) getResource(String path) getResourceAsStream(String path) protected URLgetResourceFromLoader(String path) Tries to retrieve the designated path from our loader (class).getResourcePaths(String path) jakarta.servlet.ServletRegistrationgetServletRegistration(String servletName) jakarta.servlet.SessionCookieConfigintlistContentOfUrl(URL resource, URL base) Lists the content of the designated URL.listContentOfUrlExt(URL resource, URL base, String relResPath) Lists the content of the designated URL and thus extendslistContentOfUrl(URL, URL).voidvoidvoidremoveAttribute(String name) voidsetAttribute(String name, Object object) booleansetInitParameter(String name, String value) voidsetRequestCharacterEncoding(String encoding) voidsetResponseCharacterEncoding(String encoding) voidsetSessionTimeout(int sessionTimeout) voidsetSessionTrackingModes(Set<jakarta.servlet.SessionTrackingMode> sessionTrackingModes) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.servlet.ServletContext
setRequestCharacterEncoding, setResponseCharacterEncoding
-
Field Details
-
FILE_PROTOCOL
The protocol for a file.- See Also:
-
JAR_FILE_PROTOCOL
The protocol for a Jar-file.- See Also:
-
context
protected final jakarta.servlet.ServletContext contextThe servlet context to which to delegate to. -
loader
The class relative to which we try to load resources. -
loaderBase
The URL that is the base of our loader (class) . -
logger
The logger for logging exception messages and important proceed information.
-
-
Constructor Details
-
BaseResourceServletContext
public BaseResourceServletContext(jakarta.servlet.ServletContext context, Class<?> loader, Logger logger) throws MalformedURLException - Parameters:
context- The servlet context to which to delegate to.loader- The class relative to which we try to load resources.logger- The logger for logging exception messages and important proceed information.- Throws:
MalformedURLException- If there are problems creating the base URL, that is the URL relative to which to load resources, aMalformedURLExceptionwill be thrown.
-
-
Method Details
-
getContextPath
- Specified by:
getContextPathin interfacejakarta.servlet.ServletContext
-
getContext
- Specified by:
getContextin interfacejakarta.servlet.ServletContext
-
getMajorVersion
public int getMajorVersion()- Specified by:
getMajorVersionin interfacejakarta.servlet.ServletContext
-
getMinorVersion
public int getMinorVersion()- Specified by:
getMinorVersionin interfacejakarta.servlet.ServletContext
-
getEffectiveMajorVersion
public int getEffectiveMajorVersion()- Specified by:
getEffectiveMajorVersionin interfacejakarta.servlet.ServletContext
-
getEffectiveMinorVersion
public int getEffectiveMinorVersion()- Specified by:
getEffectiveMinorVersionin interfacejakarta.servlet.ServletContext
-
getMimeType
- Specified by:
getMimeTypein interfacejakarta.servlet.ServletContext
-
getResourcePaths
- Specified by:
getResourcePathsin interfacejakarta.servlet.ServletContext
-
getResource
- Specified by:
getResourcein interfacejakarta.servlet.ServletContext- Throws:
MalformedURLException
-
listContentOfUrl
Lists the content of the designated URL. The URL is retrieved from loading a resource relative to a class. It may be specific to the servlet container that embeds this servlet. This method does not need to delegate to the underlying context. This will be done if this method does not return valid content.Usually you do not override this method but
listContentOfUrlExt(URL, URL, String). If a file or Jar-file protocol is encountered, this implementation will usually suit your needs. In case of other protocols,listContentOfUrlExt(URL, URL, String)will be called.- Parameters:
resource- The URL identifying a resource as retrieved from our loader (class).base- The URL identifying the top-level path of our loader.- Returns:
- The content of the designated URL (usually the content of the
directory specified by the designated URL relative to the loader
URL. If the directory for the resource is empty, the empty list
will be returned, if no content can be retrieved, e.g. the resource
URL cannot be interpreted as directory,
nullwill be returned. Directories need to have a trailing slash.
-
listContentOfUrlExt
Lists the content of the designated URL and thus extendslistContentOfUrl(URL, URL). This method will be called if the URL protocol cannot be handled there. Subclasses should override this method to support further protocols.This default implementation just returns
nullindicating that the resource cannot be interpreted as directory.- Parameters:
resource- The URL identifying a resource as retrieved from our loader (class).base- The URL identifying the top-level path of our loader.relResPath- The path to the resource URL relative to the base URL. Obviously this will only be valid if the designated resource is part of the designated base.- Returns:
- The content of the designated URL (usually the content of the
directory specified by the designated URL relative to the loader
URL. If the directory for the resource is empty, the empty list
will be returned, if no content can be retrieved, e.g. the resource
URL cannot be interpreted as directory,
nullwill be returned. Directories need to have a trailing slash.
-
getChildren
Gets the children for the designated path in the designated jar-file.- Parameters:
entryPath- The entry for which to get the direct children. The path is relative to the designated jar-file.file- The jar-file from which to retrieve the children.- Returns:
- The paths of the children of the designated entry relative to the designated jar-file. Note that directories must have a trailing "/".
-
getResourceFromLoader
Tries to retrieve the designated path from our loader (class). The path is tried relatively and absolutely. If the loader does not know the designated path,nullwill be returned.- Parameters:
path- The path which to search in our loader (class).- Returns:
- The URL retrieved from our loader (class) or
nullif the loader does not know the path.
-
getResourceAsStream
- Specified by:
getResourceAsStreamin interfacejakarta.servlet.ServletContext
-
getRequestDispatcher
- Specified by:
getRequestDispatcherin interfacejakarta.servlet.ServletContext
-
getNamedDispatcher
- Specified by:
getNamedDispatcherin interfacejakarta.servlet.ServletContext
-
log
- Specified by:
login interfacejakarta.servlet.ServletContext
-
log
- Specified by:
login interfacejakarta.servlet.ServletContext
-
getRealPath
- Specified by:
getRealPathin interfacejakarta.servlet.ServletContext
-
getServerInfo
- Specified by:
getServerInfoin interfacejakarta.servlet.ServletContext
-
getInitParameter
- Specified by:
getInitParameterin interfacejakarta.servlet.ServletContext
-
getInitParameterNames
- Specified by:
getInitParameterNamesin interfacejakarta.servlet.ServletContext
-
setInitParameter
- Specified by:
setInitParameterin interfacejakarta.servlet.ServletContext
-
getAttribute
- Specified by:
getAttributein interfacejakarta.servlet.ServletContext
-
getAttributeNames
- Specified by:
getAttributeNamesin interfacejakarta.servlet.ServletContext
-
setAttribute
- Specified by:
setAttributein interfacejakarta.servlet.ServletContext
-
removeAttribute
- Specified by:
removeAttributein interfacejakarta.servlet.ServletContext
-
getServletContextName
- Specified by:
getServletContextNamein interfacejakarta.servlet.ServletContext
-
addServlet
- Specified by:
addServletin interfacejakarta.servlet.ServletContext
-
addServlet
public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, jakarta.servlet.Servlet servlet) - Specified by:
addServletin interfacejakarta.servlet.ServletContext
-
addServlet
public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends jakarta.servlet.Servlet> servletClass) - Specified by:
addServletin interfacejakarta.servlet.ServletContext
-
addJspFile
- Specified by:
addJspFilein interfacejakarta.servlet.ServletContext
-
createServlet
public <T extends jakarta.servlet.Servlet> T createServlet(Class<T> clazz) throws jakarta.servlet.ServletException - Specified by:
createServletin interfacejakarta.servlet.ServletContext- Throws:
jakarta.servlet.ServletException
-
getServletRegistration
- Specified by:
getServletRegistrationin interfacejakarta.servlet.ServletContext
-
getServletRegistrations
- Specified by:
getServletRegistrationsin interfacejakarta.servlet.ServletContext
-
addFilter
- Specified by:
addFilterin interfacejakarta.servlet.ServletContext
-
addFilter
public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, jakarta.servlet.Filter filter) - Specified by:
addFilterin interfacejakarta.servlet.ServletContext
-
addFilter
public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends jakarta.servlet.Filter> filterClass) - Specified by:
addFilterin interfacejakarta.servlet.ServletContext
-
createFilter
public <T extends jakarta.servlet.Filter> T createFilter(Class<T> clazz) throws jakarta.servlet.ServletException - Specified by:
createFilterin interfacejakarta.servlet.ServletContext- Throws:
jakarta.servlet.ServletException
-
getFilterRegistration
- Specified by:
getFilterRegistrationin interfacejakarta.servlet.ServletContext
-
getFilterRegistrations
- Specified by:
getFilterRegistrationsin interfacejakarta.servlet.ServletContext
-
getSessionCookieConfig
public jakarta.servlet.SessionCookieConfig getSessionCookieConfig()- Specified by:
getSessionCookieConfigin interfacejakarta.servlet.ServletContext
-
setSessionTrackingModes
- Specified by:
setSessionTrackingModesin interfacejakarta.servlet.ServletContext
-
getDefaultSessionTrackingModes
- Specified by:
getDefaultSessionTrackingModesin interfacejakarta.servlet.ServletContext
-
getEffectiveSessionTrackingModes
- Specified by:
getEffectiveSessionTrackingModesin interfacejakarta.servlet.ServletContext
-
addListener
- Specified by:
addListenerin interfacejakarta.servlet.ServletContext
-
addListener
- Specified by:
addListenerin interfacejakarta.servlet.ServletContext
-
addListener
- Specified by:
addListenerin interfacejakarta.servlet.ServletContext
-
createListener
public <T extends EventListener> T createListener(Class<T> clazz) throws jakarta.servlet.ServletException - Specified by:
createListenerin interfacejakarta.servlet.ServletContext- Throws:
jakarta.servlet.ServletException
-
getJspConfigDescriptor
public jakarta.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()- Specified by:
getJspConfigDescriptorin interfacejakarta.servlet.ServletContext
-
getClassLoader
- Specified by:
getClassLoaderin interfacejakarta.servlet.ServletContext
-
declareRoles
- Specified by:
declareRolesin interfacejakarta.servlet.ServletContext
-
getVirtualServerName
- Specified by:
getVirtualServerNamein interfacejakarta.servlet.ServletContext
-
getSessionTimeout
public int getSessionTimeout()- Specified by:
getSessionTimeoutin interfacejakarta.servlet.ServletContext
-
setSessionTimeout
public void setSessionTimeout(int sessionTimeout) - Specified by:
setSessionTimeoutin interfacejakarta.servlet.ServletContext
-
getRequestCharacterEncoding
- Specified by:
getRequestCharacterEncodingin interfacejakarta.servlet.ServletContext
-
setRequestCharacterEncoding
- Specified by:
setRequestCharacterEncodingin interfacejakarta.servlet.ServletContext
-
getResponseCharacterEncoding
- Specified by:
getResponseCharacterEncodingin interfacejakarta.servlet.ServletContext
-
setResponseCharacterEncoding
- Specified by:
setResponseCharacterEncodingin interfacejakarta.servlet.ServletContext
-