Class DefaultWebApplication

java.lang.Object
cloud.piranha.core.impl.DefaultWebApplication
All Implemented Interfaces:
WebApplication, jakarta.servlet.ServletContext
Direct Known Subclasses:
MicroWebApplication, ServerWebApplication

public class DefaultWebApplication extends Object implements WebApplication
The default WebApplication.

The filters field is backed by a LinkedHashMap so we get an insertion-order key set. If you change this, be aware that methods using this field should be changed to account for that.

The servlets field is backed by a LinkedHashMap so we get an insertion-order key set. If you change this, be aware that methods using this field should be changed to account for that.

Author:
Manfred Riem ([email protected])
  • Field Details

    • SETUP

      protected static final int SETUP
      Stores the SETUP constant.
      See Also:
    • INITIALIZED_DECLARED

      protected static final int INITIALIZED_DECLARED
      Stores the INITIALIZED_DECLARED constant. This signals that web.xml, web-fragment.xml and annotations have been processed.
      See Also:
    • INITIALIZED

      protected static final int INITIALIZED
      Stores the INITIALIZED constant.
      See Also:
    • SERVICING

      protected static final int SERVICING
      Stores the SERVICING constant.
      See Also:
    • ERROR

      protected static final int ERROR
      Stores the ERROR constant.
      See Also:
    • attributes

      protected final Map<String,Object> attributes
      Stores the attributes.
    • classLoader

      protected ClassLoader classLoader
      Stores the class loader.
    • contextPath

      protected String contextPath
      Stores the context path.
    • defaultServlet

      protected jakarta.servlet.Servlet defaultServlet
      Stores the default servlet (if any).
    • distributable

      protected boolean distributable
      Stores the boolean flag indicating if the web application is distributable.
    • effectiveMajorVersion

      protected int effectiveMajorVersion
      Stores the effective major version.
    • effectiveMinorVersion

      protected int effectiveMinorVersion
      Stores the effective minor version.
    • servletContextName

      protected String servletContextName
      Stores the servlet context name.
    • virtualServerName

      protected String virtualServerName
      Stores the virtual server name.
    • responseCharacterEncoding

      protected String responseCharacterEncoding
      Stores the response character encoding.
    • status

      protected int status
      Stores the status.
    • responses

      protected final Map<jakarta.servlet.ServletResponse,jakarta.servlet.ServletRequest> responses
      Stores the active responses and the associated requests.
    • initializers

      protected final List<jakarta.servlet.ServletContainerInitializer> initializers
      Stores the servlet container initializers.
    • initParameters

      protected final Map<String,String> initParameters
      Stores the init parameters.
    • servletEnvironments

      protected final Map<String,DefaultServletEnvironment> servletEnvironments
      Stores the servlet environments
    • filters

      protected final Map<String,DefaultFilterEnvironment> filters
      Stores the filters.
    • contextAttributeListeners

      protected final List<jakarta.servlet.ServletContextAttributeListener> contextAttributeListeners
      Stores the servlet context attribute listeners.
    • declaredContextListeners

      protected final List<jakarta.servlet.ServletContextListener> declaredContextListeners
      Stores the servlet context listeners that were declared in web.xml, web-fragment.xml, or via annotations
    • contextListeners

      protected final List<jakarta.servlet.ServletContextListener> contextListeners
      Stores the servlet context listeners that were not declared in web.xml, web-fragment.xml, or via annotations
    • requestListeners

      protected final List<jakarta.servlet.ServletRequestListener> requestListeners
      Stores the servlet request listeners.
    • invocationFinder

      protected DefaultInvocationFinder invocationFinder
      Stores the invocation finder, which finds a Servlet, Filter(chain) and variants thereof to invoke for a given request path.
    • metadataComplete

      protected boolean metadataComplete
      Stores the metadata complete flag.
    • requestCharacterEncoding

      protected String requestCharacterEncoding
      Stores the request character encoding.
    • source

      protected Object source
      The source object where this web application instance originates from, i.e. the artifact this was last passed into by the container. Compare to the source object of an event.
    • tainted

      protected boolean tainted
      When we're in tainted mode, we have to throw exceptions for a large number of methods. Tainted mode is required for ServletContextListeners which have not been declared. At the moment of writing it's not clear why this tainted mode is needed.
    • webApplicationRequestMapper

      protected WebApplicationRequestMapper webApplicationRequestMapper
      Stores the web application request mapper.
    • manager

      protected WebApplicationManager manager
      Stores the web application manager.
  • Constructor Details

    • DefaultWebApplication

      public DefaultWebApplication()
      Constructor.
  • Method Details

    • addFilter

      public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends jakarta.servlet.Filter> filterClass)
      Specified by:
      addFilter in interface jakarta.servlet.ServletContext
    • addFilter

      public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, String className)
      Specified by:
      addFilter in interface jakarta.servlet.ServletContext
    • addFilter

      public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, jakarta.servlet.Filter filter)
      Specified by:
      addFilter in interface jakarta.servlet.ServletContext
    • addFilterMapping

      public Set<String> addFilterMapping(Set<jakarta.servlet.DispatcherType> dispatcherTypes, String filterName, boolean isMatchAfter, String... urlPatterns)
      Description copied from interface: WebApplication
      Add a mapping for the given filter.
      Specified by:
      addFilterMapping in interface WebApplication
      Parameters:
      dispatcherTypes - the dispatcher types. Can be null to use default DispatcherType.REQUEST.
      filterName - the filter name.
      isMatchAfter - true to call the filter this mapping applies to after declared ones, false to call it before declared ones.
      urlPatterns - the URL patterns.
      Returns:
      the possible empty set of already mapped URL patterns.
      See Also:
      • FilterRegistration.addMappingForUrlPatterns(EnumSet, boolean, String...)
    • addInitializer

      public void addInitializer(String className)
      Description copied from interface: WebApplication
      Add a servlet container initializer.
      Specified by:
      addInitializer in interface WebApplication
      Parameters:
      className - the class name.
    • addInitializer

      public void addInitializer(jakarta.servlet.ServletContainerInitializer servletContainerInitializer)
      Description copied from interface: WebApplication
      Add a servlet container initializer.
      Specified by:
      addInitializer in interface WebApplication
      Parameters:
      servletContainerInitializer - the servletContainerInitializer instance
    • addJspFile

      public jakarta.servlet.ServletRegistration.Dynamic addJspFile(String servletName, String jspFile)
      Specified by:
      addJspFile in interface jakarta.servlet.ServletContext
    • addListener

      public void addListener(String className)
      Specified by:
      addListener in interface jakarta.servlet.ServletContext
    • addListener

      public void addListener(Class<? extends EventListener> type)
      Specified by:
      addListener in interface jakarta.servlet.ServletContext
    • addListener

      public <T extends EventListener> void addListener(T listener)
      Specified by:
      addListener in interface jakarta.servlet.ServletContext
    • addResource

      public void addResource(Resource resource)
      Description copied from interface: WebApplication
      Add the resource.
      Specified by:
      addResource in interface WebApplication
      Parameters:
      resource - the resouce.
    • addServlet

      public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends jakarta.servlet.Servlet> servletClass)
      Specified by:
      addServlet in interface jakarta.servlet.ServletContext
    • addServlet

      public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, String className)
      Specified by:
      addServlet in interface jakarta.servlet.ServletContext
    • addServlet

      public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, jakarta.servlet.Servlet servlet)
      Specified by:
      addServlet in interface jakarta.servlet.ServletContext
    • addServletMapping

      public Set<String> addServletMapping(String servletName, String... urlPatterns)
      Description copied from interface: WebApplication
      Add a mapping for the given servlet.
      Specified by:
      addServletMapping in interface WebApplication
      Parameters:
      servletName - the servlet name.
      urlPatterns - the URL patterns.
      Returns:
      the possible empty set of already mapped URL patterns.
      See Also:
      • ServletRegistration.addMapping(String...)
    • removeServletMapping

      public String removeServletMapping(String urlPattern)
      Description copied from interface: WebApplication
      Remove a mapping for a servlet.
      Specified by:
      removeServletMapping in interface WebApplication
      Parameters:
      urlPattern - the URL pattern
      Returns:
      the Servlet name the pattern was mapped to, or null if no prior mapping.
    • createFilter

      public <T extends jakarta.servlet.Filter> T createFilter(Class<T> filterClass) throws jakarta.servlet.ServletException
      Specified by:
      createFilter in interface jakarta.servlet.ServletContext
      Throws:
      jakarta.servlet.ServletException
    • createListener

      public <T extends EventListener> T createListener(Class<T> clazz) throws jakarta.servlet.ServletException
      Specified by:
      createListener in interface jakarta.servlet.ServletContext
      Throws:
      jakarta.servlet.ServletException
    • createServlet

      public <T extends jakarta.servlet.Servlet> T createServlet(Class<T> servletClass) throws jakarta.servlet.ServletException
      Specified by:
      createServlet in interface jakarta.servlet.ServletContext
      Throws:
      jakarta.servlet.ServletException
    • declareRoles

      public void declareRoles(String... roles)
      Specified by:
      declareRoles in interface jakarta.servlet.ServletContext
    • destroy

      public void destroy()
      Description copied from interface: WebApplication
      Destroy the web application.
      Specified by:
      destroy in interface WebApplication
    • getAttribute

      public Object getAttribute(String name)
      Specified by:
      getAttribute in interface jakarta.servlet.ServletContext
    • getAttributeNames

      public Enumeration<String> getAttributeNames()
      Specified by:
      getAttributeNames in interface jakarta.servlet.ServletContext
    • getClassLoader

      public ClassLoader getClassLoader()
      Specified by:
      getClassLoader in interface jakarta.servlet.ServletContext
    • getContext

      public jakarta.servlet.ServletContext getContext(String uripath)
      Specified by:
      getContext in interface jakarta.servlet.ServletContext
    • getContextPath

      public String getContextPath()
      Specified by:
      getContextPath in interface jakarta.servlet.ServletContext
    • getDefaultSessionTrackingModes

      public Set<jakarta.servlet.SessionTrackingMode> getDefaultSessionTrackingModes()
      Specified by:
      getDefaultSessionTrackingModes in interface jakarta.servlet.ServletContext
    • getDefaultServlet

      public jakarta.servlet.Servlet getDefaultServlet()
      Description copied from interface: WebApplication
      Get the default servlet.
      Specified by:
      getDefaultServlet in interface WebApplication
      Returns:
      the default Servlet.
    • getEffectiveMajorVersion

      public int getEffectiveMajorVersion()
      Specified by:
      getEffectiveMajorVersion in interface jakarta.servlet.ServletContext
    • getEffectiveMinorVersion

      public int getEffectiveMinorVersion()
      Specified by:
      getEffectiveMinorVersion in interface jakarta.servlet.ServletContext
    • setEffectiveMajorVersion

      public void setEffectiveMajorVersion(int effectiveMajorVersion)
      Description copied from interface: WebApplication
      Set the effective major version.
      Specified by:
      setEffectiveMajorVersion in interface WebApplication
      Parameters:
      effectiveMajorVersion - the effective major version.
    • setEffectiveMinorVersion

      public void setEffectiveMinorVersion(int effectiveMinorVersion)
      Description copied from interface: WebApplication
      Set the effective minor version.
      Specified by:
      setEffectiveMinorVersion in interface WebApplication
      Parameters:
      effectiveMinorVersion - the effective minor version.
    • getEffectiveSessionTrackingModes

      public Set<jakarta.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes()
      Specified by:
      getEffectiveSessionTrackingModes in interface jakarta.servlet.ServletContext
    • getFilterRegistration

      public jakarta.servlet.FilterRegistration getFilterRegistration(String filterName)
      Specified by:
      getFilterRegistration in interface jakarta.servlet.ServletContext
    • getFilterRegistrations

      public Map<String,? extends jakarta.servlet.FilterRegistration> getFilterRegistrations()
      Specified by:
      getFilterRegistrations in interface jakarta.servlet.ServletContext
    • getInitParameter

      public String getInitParameter(String name)
      Specified by:
      getInitParameter in interface jakarta.servlet.ServletContext
    • getInitParameterNames

      public Enumeration<String> getInitParameterNames()
      Specified by:
      getInitParameterNames in interface jakarta.servlet.ServletContext
    • getInitializers

      public List<jakarta.servlet.ServletContainerInitializer> getInitializers()
      Description copied from interface: WebApplication
      Gets the ServletContainerInitializers
      Specified by:
      getInitializers in interface WebApplication
      Returns:
      list of ServletContainerInitializers
    • getJspConfigDescriptor

      public jakarta.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()
      Specified by:
      getJspConfigDescriptor in interface jakarta.servlet.ServletContext
    • getMajorVersion

      public int getMajorVersion()
      Returns the major version.
      Specified by:
      getMajorVersion in interface jakarta.servlet.ServletContext
      Returns:
      the major version
    • getMappings

      public Collection<String> getMappings(String servletName)
      Description copied from interface: WebApplication
      Get the mappings for a particular servlet.
      Specified by:
      getMappings in interface WebApplication
      Parameters:
      servletName - the servlet name.
      Returns:
      the possible empty set of mapped URL patterns.
      See Also:
      • ServletRegistration.getMappings()
    • getMimeType

      public String getMimeType(String filename)
      Specified by:
      getMimeType in interface jakarta.servlet.ServletContext
    • getMinorVersion

      public int getMinorVersion()
      Specified by:
      getMinorVersion in interface jakarta.servlet.ServletContext
    • getRealPath

      public String getRealPath(String path)
      Specified by:
      getRealPath in interface jakarta.servlet.ServletContext
    • getRequest

      public jakarta.servlet.ServletRequest getRequest(jakarta.servlet.ServletResponse response)
      Get the request associated with the response.
      Specified by:
      getRequest in interface WebApplication
      Parameters:
      response - the response.
      Returns:
      the request.
    • getRequestCharacterEncoding

      public String getRequestCharacterEncoding()
      Returns the default request character encoding.
      Specified by:
      getRequestCharacterEncoding in interface jakarta.servlet.ServletContext
      Returns:
      the default request character encoding
    • getResponseCharacterEncoding

      public String getResponseCharacterEncoding()
      Returns the default response character encoding.
      Specified by:
      getResponseCharacterEncoding in interface jakarta.servlet.ServletContext
      Returns:
      the default response character encoding
    • getResource

      public URL getResource(String location) throws MalformedURLException
      Get the resource.
      Specified by:
      getResource in interface jakarta.servlet.ServletContext
      Parameters:
      location - the location.
      Returns:
      the URL.
      Throws:
      MalformedURLException - when the URL is malformed.
    • getResourceAsStream

      public InputStream getResourceAsStream(String location)
      Get the resource as a stream.
      Specified by:
      getResourceAsStream in interface jakarta.servlet.ServletContext
      Parameters:
      location - the resource location
      Returns:
      the input stream, or null if not found.
    • getResourcePaths

      public Set<String> getResourcePaths(String path)
      Specified by:
      getResourcePaths in interface jakarta.servlet.ServletContext
    • getResponse

      public jakarta.servlet.ServletResponse getResponse(jakarta.servlet.ServletRequest request)
      Description copied from interface: WebApplication
      Get the response.
      Specified by:
      getResponse in interface WebApplication
      Parameters:
      request - the request.
      Returns:
      the response.
    • getServerInfo

      public String getServerInfo()
      Specified by:
      getServerInfo in interface jakarta.servlet.ServletContext
    • getServletContextName

      public String getServletContextName()
      Specified by:
      getServletContextName in interface jakarta.servlet.ServletContext
    • getServletRegistration

      public jakarta.servlet.ServletRegistration getServletRegistration(String servletName)
      Specified by:
      getServletRegistration in interface jakarta.servlet.ServletContext
    • getServletRegistrations

      public Map<String,? extends jakarta.servlet.ServletRegistration> getServletRegistrations()
      Specified by:
      getServletRegistrations in interface jakarta.servlet.ServletContext
    • getSessionCookieConfig

      public jakarta.servlet.SessionCookieConfig getSessionCookieConfig()
      Specified by:
      getSessionCookieConfig in interface jakarta.servlet.ServletContext
    • getSessionTimeout

      public int getSessionTimeout()
      Specified by:
      getSessionTimeout in interface jakarta.servlet.ServletContext
    • getVirtualServerName

      public String getVirtualServerName()
      Specified by:
      getVirtualServerName in interface jakarta.servlet.ServletContext
    • initialize

      public void initialize()
      Description copied from interface: WebApplication
      Initialize the web application.
      Specified by:
      initialize in interface WebApplication
    • initializeDeclaredFinish

      public void initializeDeclaredFinish()
      Description copied from interface: WebApplication
      Marks the end of initializing declared (web.xml, annotations) artifacts
      Specified by:
      initializeDeclaredFinish in interface WebApplication
    • initializeFinish

      public void initializeFinish()
      Finish the initialization.
      Specified by:
      initializeFinish in interface WebApplication
    • initializeFilters

      public void initializeFilters()
      Initialize the filters.
      Specified by:
      initializeFilters in interface WebApplication
    • initializeInitializers

      public void initializeInitializers()
      Initialize the servlet container initializers.
      Specified by:
      initializeInitializers in interface WebApplication
    • initializeServlets

      public void initializeServlets()
      Initialize the servlets.
      Specified by:
      initializeServlets in interface WebApplication
    • isDistributable

      public boolean isDistributable()
      Is the web application distributable.
      Specified by:
      isDistributable in interface WebApplication
      Returns:
      true if it is, false otherwise.
    • isInitialized

      public boolean isInitialized()
      Description copied from interface: WebApplication
      Is the web application initialized.
      Specified by:
      isInitialized in interface WebApplication
      Returns:
      true if it is, false otherwise.
    • isMetadataComplete

      public boolean isMetadataComplete()
      Description copied from interface: WebApplication
      Is the web application metadata complete.
      Specified by:
      isMetadataComplete in interface WebApplication
      Returns:
      true if it is, false otherwise.
    • linkRequestAndResponse

      public void linkRequestAndResponse(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response)
      Link the request and response.
      Specified by:
      linkRequestAndResponse in interface WebApplication
      Parameters:
      request - the request.
      response - the response.
    • log

      public void log(String message, Throwable throwable)
      Specified by:
      log in interface jakarta.servlet.ServletContext
    • log

      public void log(String message)
      Specified by:
      log in interface jakarta.servlet.ServletContext
    • removeAttribute

      public void removeAttribute(String name)
      Remove the attribute with the given name.
      Specified by:
      removeAttribute in interface jakarta.servlet.ServletContext
      Parameters:
      name - the name.
    • service

      public void service(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) throws jakarta.servlet.ServletException, IOException
      Description copied from interface: WebApplication
      Service the request.
      Specified by:
      service in interface WebApplication
      Parameters:
      request - the request.
      response - the response.
      Throws:
      jakarta.servlet.ServletException - when a servlet error occurs.
      IOException - when an I/O error occurs.
    • setAttribute

      public void setAttribute(String name, Object value)
      Specified by:
      setAttribute in interface jakarta.servlet.ServletContext
    • setClassLoader

      public void setClassLoader(ClassLoader classLoader)
      Description copied from interface: WebApplication
      Set the class loader.
      Specified by:
      setClassLoader in interface WebApplication
      Parameters:
      classLoader - the class loader.
    • setContextPath

      public void setContextPath(String contextPath)
      Description copied from interface: WebApplication
      Set the context path.
      Specified by:
      setContextPath in interface WebApplication
      Parameters:
      contextPath - the context path.
    • setDefaultServlet

      public void setDefaultServlet(jakarta.servlet.Servlet defaultServlet)
      Description copied from interface: WebApplication
      Set the default servlet.
      Specified by:
      setDefaultServlet in interface WebApplication
      Parameters:
      defaultServlet - the default servlet.
    • setDistributable

      public void setDistributable(boolean distributable)
      Description copied from interface: WebApplication
      Set if the web application is distributable.
      Specified by:
      setDistributable in interface WebApplication
      Parameters:
      distributable - the distributable flag.
    • setInitParameter

      public boolean setInitParameter(String name, String value)
      Specified by:
      setInitParameter in interface jakarta.servlet.ServletContext
    • setRequestCharacterEncoding

      public void setRequestCharacterEncoding(String requestCharacterEncoding)
      Specified by:
      setRequestCharacterEncoding in interface jakarta.servlet.ServletContext
    • setResponseCharacterEncoding

      public void setResponseCharacterEncoding(String responseCharacterEncoding)
      Specified by:
      setResponseCharacterEncoding in interface jakarta.servlet.ServletContext
    • setServletContextName

      public void setServletContextName(String servletContextName)
      Description copied from interface: WebApplication
      Set the servlet context name.
      Specified by:
      setServletContextName in interface WebApplication
      Parameters:
      servletContextName - the servlet context name.
    • setSessionTrackingModes

      public void setSessionTrackingModes(Set<jakarta.servlet.SessionTrackingMode> sessionTrackingModes)
      Specified by:
      setSessionTrackingModes in interface jakarta.servlet.ServletContext
    • setSessionTimeout

      public void setSessionTimeout(int sessionTimeout)
      Specified by:
      setSessionTimeout in interface jakarta.servlet.ServletContext
    • setVirtualServerName

      public void setVirtualServerName(String virtualServerName)
      Set the virtual server name.
      Parameters:
      virtualServerName - the virtual server name.
    • setWebApplicationRequestMapper

      public void setWebApplicationRequestMapper(WebApplicationRequestMapper webApplicationRequestMapper)
      Description copied from interface: WebApplication
      Set the web application request mapper.
      Specified by:
      setWebApplicationRequestMapper in interface WebApplication
      Parameters:
      webApplicationRequestMapper - the web application request mapper.
    • start

      public void start()
      Description copied from interface: WebApplication
      Start servicing.
      Specified by:
      start in interface WebApplication
    • stop

      public void stop()
      Description copied from interface: WebApplication
      Stop servicing.
      Specified by:
      stop in interface WebApplication
    • unlinkRequestAndResponse

      public void unlinkRequestAndResponse(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response)
      Description copied from interface: WebApplication
      Unlink the request and response.
      Specified by:
      unlinkRequestAndResponse in interface WebApplication
      Parameters:
      request - the request.
      response - the response.
    • getRequestDispatcher

      public DefaultServletRequestDispatcher getRequestDispatcher(String path)
      Specified by:
      getRequestDispatcher in interface jakarta.servlet.ServletContext
    • getNamedDispatcher

      public jakarta.servlet.RequestDispatcher getNamedDispatcher(String name)
      Specified by:
      getNamedDispatcher in interface jakarta.servlet.ServletContext
    • setMetadataComplete

      public void setMetadataComplete(boolean metadataComplete)
      Description copied from interface: WebApplication
      Set the metadata complete flag.
      Specified by:
      setMetadataComplete in interface WebApplication
      Parameters:
      metadataComplete - the metadata complete flag.
    • verifyRequestResponseTypes

      protected void verifyRequestResponseTypes(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) throws jakarta.servlet.ServletException
      Verify the request/response types.
      Parameters:
      request - the request.
      response - the response.
      Throws:
      jakarta.servlet.ServletException - when request or response is invalid.
    • verifyState

      protected void verifyState(int desiredStatus, String message)
      Verify the web application state.
      Parameters:
      desiredStatus - the desired status.
      message - the message.
    • getManager

      public WebApplicationManager getManager()
      Description copied from interface: WebApplication
      Get the web application manager.
      Specified by:
      getManager in interface WebApplication
      Returns:
      the web application manager.
    • setJspConfigDescriptor

      public void setJspConfigDescriptor(jakarta.servlet.descriptor.JspConfigDescriptor jspConfigDescriptor)
      Description copied from interface: WebApplication
      Set the JSP config descriptor.
      Specified by:
      setJspConfigDescriptor in interface WebApplication
      Parameters:
      jspConfigDescriptor - the descriptor.