Class EmbeddedServletService

java.lang.Object
de.aristaflow.adept2.base.service.AbstractADEPT2Service
de.aristaflow.adept2.base.servletcontainer.dynamic.EmbeddedServletService
All Implemented Interfaces:
ADEPT2Service, LogService, ServiceThreadHandling, ServletService

A servlet service deploying servlets dynamically via Servlet API 3.0. Note that all servlets have the same servlet context. The servlets need to be deployed before the servlet context has been fully initialised. Note that no undeploying may take place since this is not supported by the Servlet API 3.0.
  • Field Details

    • CONF_SERVLET_CONTEXT

      public static final String CONF_SERVLET_CONTEXT
      The configuration key with which to store a servlet context in the configuration.
      See Also:
    • CONF_SERVLET_URL

      public static final String CONF_SERVLET_URL
      The configuration key with which to store the URL of the servlet.
      See Also:
    • servlets

      protected final ConcurrentMap<Pair<String,String>,Pair<DynamicServlet,jakarta.servlet.ServletContext>> servlets
      All servlets deployed via this service.
    • sc

      protected final jakarta.servlet.ServletContext sc
      The context of the outer servlet.
    • baseUrl

      protected final URL baseUrl
      The base URL of the servlet, that is the protocol, the host, the port and usually the servlet name or the name of the corresponding deployment file.
  • Constructor Details

    • EmbeddedServletService

      public EmbeddedServletService(Configuration conf, Registry registry) throws ConfigurationException
      Creates a new embedded servlet service using Servlet API 3.0 for deploying servlets.
      Parameters:
      conf - The configuration of this service.
      registry - The registry to be used for accessing services by this service. This is provided as parameter to the constructor when creating a service.
      Throws:
      ConfigurationException - If there are problems parsing the servlet URL, a ConfigurationException will be thrown.
    • EmbeddedServletService

      protected EmbeddedServletService(Configuration conf, Registry registry, Class<?> cls) throws ConfigurationException
      Creates a new embedded servlet service using Servlet API 3.0 for deploying servlets. This constructor is for usage by subclasses.
      Parameters:
      conf - The configuration of this service.
      registry - The registry to be used for accessing services by this service. This is provided as parameter to the constructor when creating a service.
      cls - The class specifying the name of the logger of this service.
      Throws:
      ConfigurationException - If there are problems parsing the servlet URL, a ConfigurationException will be thrown.
  • Method Details

    • getBaseURL

      public URL getBaseURL()
      Description copied from interface: ServletService
      Gets the base URL (without any context information) of the underlying servlet container. This URL (or rather this URL with the corresponding servlet contexts) has to be reachable via browser.
      Specified by:
      getBaseURL in interface ServletService
      Returns:
      The base URL (without any context information) of the underlying servlet container.
    • getServletContext

      public jakarta.servlet.ServletContext getServletContext(Class<?> baseClass)
      Gets the servlet context this servlet service runs in. This should respect the designated base class, that is, it should resolve the resource paths appropriately.
      Parameters:
      baseClass - The class with which to load resources. This allows to have a WEB-INF-directory which is not at the top-level. It is expected to be besides this class. If this is null, the usual behaviour applies which is a top-level WEB-INF-directory.
      Returns:
      The servlet context this servlet service runs in.
    • deployWebApp

      public URL deployWebApp(String hierarchicalContext, DynamicServlet servlet, Map<String,Object> contextAttrs) throws ServletDeploymentException
      Description copied from interface: ServletService
      Deploys the designated servlet via this service with the designated hierarchical context having the designated servlet context attributes. Usually the base URL appended by the hierarchical context will be the actual URL of the servlet.
      This will use "/" as URL pattern.

      Note that in case of an embedded servlet service, that is this service running within a servlet context, deploying service has to take place before the surrounding servlet context has been initialised.

      Specified by:
      deployWebApp in interface ServletService
      Parameters:
      hierarchicalContext - The hierarchical context of the servlet. This corresponds to the file or directory name when deploying in the file system (no trailing "/").
      servlet - The servlet which to deploy dynamically. Make sure that the servlet name is set appropriately since this is required for undeploying.
      contextAttrs - The attributes added to the servlet context when deploying the servlet. Make sure that the keys are unique! In case of an embedded servlet service, all servlets will have the very same context. This may be null.
      Returns:
      The URL of the designated servlet, that is the base URL of the servlet container appended by the name of the web application. This URL does not contain a URL pattern specified in the servlet mapping except for the default pattern ("/").
      Throws:
      ServletDeploymentException - If there are problems deploying the designated servlet, a ServletDeploymentException having no cause will be thrown, otherwise the causing exception will be wrapped (mostly problems with URL-encoding or servlet container configuration.
    • deployWebApp

      public URL deployWebApp(String hierarchicalContext, Class<?> baseClass, DynamicServlet servlet, Map<String,String> initParams, Map<String,Object> contextAttrs, String urlMapping, boolean asyncSupported) throws ServletDeploymentException
      Description copied from interface: ServletService
      Deploys the designated servlet via this service with the designated hierarchical context having the designated servlet context attributes. Usually the base URL appended by the hierarchical context will be the actual URL of the servlet.
      This will use "/" as URL pattern.

      Note that in case of an embedded servlet service, that is this service running within a servlet context, deploying service has to take place before the surrounding servlet context has been initialised.

      Specified by:
      deployWebApp in interface ServletService
      Parameters:
      hierarchicalContext - The hierarchical context of the servlet. This corresponds to the file or directory name when deploying in the file system (no trailing "/").
      baseClass - The class with which to load resources. This allows to have a WEB-INF-directory which is not at the top-level. It is expected to be besides this class. If this is null, the usual behaviour applies which is a top-level WEB-INF-directory.
      servlet - The servlet which to deploy dynamically. Make sure that the servlet name is set appropriately since this is required for undeploying.
      initParams - The init parameters of the servlet. This may be null.
      contextAttrs - The attributes added to the servlet context when deploying the servlet. Make sure that the keys are unique! In case of an embedded servlet service, all servlets will have the very same context. This may be null.
      urlMapping - The mapping for the designated servlet. This corresponds to URL-pattern in the deployment descriptor. If this is null, the default mapping "/" will be used.
      asyncSupported - Whether the designated servlet supports asynchronous operation.
      Returns:
      The URL of the designated servlet, that is the base URL of the servlet container appended by the name of the web application. This URL does not contain a URL pattern specified in the servlet mapping except for the default pattern ("/").
      Throws:
      ServletDeploymentException - If there are problems deploying the designated servlet, a ServletDeploymentException having no cause will be thrown, otherwise the causing exception will be wrapped (mostly problems with URL-encoding or servlet container configuration.
      See Also:
      • Registration.Dynamic.setAsyncSupported(boolean)
    • undeployWebApp

      public void undeployWebApp(String hierarchicalContext, String servletName) throws ServletDeploymentException
      Description copied from interface: ServletService
      Undeploys the designated servlet deployed with the designated hierarchical context and servlet name. Note that undeploying may not work, for instance in case of an embedded servlet service.
      Specified by:
      undeployWebApp in interface ServletService
      Parameters:
      hierarchicalContext - The hierarchical context with which the servlet has been deployed.
      servletName - The name of the servlet which to undeploy.
      Throws:
      ServletDeploymentException - If there are problems undeploying the designated web application, a ServletDeploymentException will be thrown. If this is due to undeploying a non existing web application, it will have no cause, problems when stopping the servlet will have the appropriate cause.