Class ServletRegistration

java.lang.Object
org.glassfish.grizzly.servlet.Registration
org.glassfish.grizzly.servlet.ServletRegistration
All Implemented Interfaces:
Registration, Registration.Dynamic, ServletRegistration, ServletRegistration.Dynamic, Comparable<ServletRegistration>

public class ServletRegistration extends Registration implements ServletRegistration.Dynamic, Comparable<ServletRegistration>
Allows customization of a Servlet registered with the WebappContext.
Since:
2.2
  • Field Details

    • servletClass

      protected Class<? extends Servlet> servletClass
    • urlPatterns

      protected final ArraySet<String> urlPatterns
    • servlet

      protected Servlet servlet
    • loadOnStartup

      protected int loadOnStartup
    • expectationHandler

      protected ExpectationHandler expectationHandler
    • isAsyncSupported

      protected boolean isAsyncSupported
  • Constructor Details

    • ServletRegistration

      protected ServletRegistration(WebappContext ctx, String name, String servletClassName)
      Creates a new ServletRegistration associated with the specified WebappContext.
      Parameters:
      ctx - the owning WebappContext.
      name - the name of the Filter.
      servletClassName - the fully qualified class name of the Servlet implementation.
    • ServletRegistration

      protected ServletRegistration(WebappContext ctx, String name, Servlet servlet)
      Creates a new ServletRegistration associated with the specified WebappContext.
      Parameters:
      ctx - the owning WebappContext.
      name - the name of the Filter.
      servlet - the Servlet instance.
    • ServletRegistration

      protected ServletRegistration(WebappContext ctx, String name, Class<? extends Servlet> servletClass)
      Creates a new ServletRegistration associated with the specified WebappContext.
      Parameters:
      ctx - the owning WebappContext.
      name - the name of the Filter.
      servletClass - the class of the Servlet implementation.
  • Method Details

    • addMapping

      public Set<String> addMapping(String... urlPatterns)
      Adds a servlet mapping with the given URL patterns for the Servlet represented by this ServletRegistration.

      If any of the specified URL patterns are already mapped to a different Servlet, no updates will be performed.

      If this method is called multiple times, each successive call adds to the effects of the former.

      Specified by:
      addMapping in interface ServletRegistration
      Parameters:
      urlPatterns - the URL patterns of the servlet mapping
      Returns:
      the (possibly empty) Set of URL patterns that are already mapped to a different Servlet
      Throws:
      IllegalArgumentException - if urlPatterns is null or empty
      IllegalStateException - if the ServletContext from which this ServletRegistration was obtained has already been initialized
    • getMappings

      public Collection<String> getMappings()
      Gets the currently available mappings of the Servlet represented by this ServletRegistration.

      If permitted, any changes to the returned Collection must not affect this ServletRegistration.

      Specified by:
      getMappings in interface ServletRegistration
      Returns:
      a (possibly empty) Collection of the currently available mappings of the Servlet represented by this ServletRegistration
    • setLoadOnStartup

      public void setLoadOnStartup(int loadOnStartup)
      Sets the loadOnStartup priority on the Servlet represented by this dynamic ServletRegistration.

      A loadOnStartup value of greater than or equal to zero indicates to the container the initialization priority of the Servlet. In this case, the container must instantiate and initialize the Servlet during the initialization phase of the WebappContext, that is, after it has invoked all of the ServletContextListener objects configured for the WebappContext at their ServletContextListener.contextInitialized(jakarta.servlet.ServletContextEvent) method.

      If loadOnStartup is a negative integer, the container is free to instantiate and initialize the Servlet lazily.

      The default value for loadOnStartup is -1.

      A call to this method overrides any previous setting.

      Specified by:
      setLoadOnStartup in interface ServletRegistration.Dynamic
      Parameters:
      loadOnStartup - the initialization priority of the Servlet
      Throws:
      IllegalStateException - if the ServletContext from which this ServletRegistration was obtained has already been initialized
    • getExpectationHandler

      public ExpectationHandler getExpectationHandler()
      Get the ExpectationHandler responsible for processing Expect: header (for example "Expect: 100-Continue").
      Returns:
      the ExpectationHandler responsible for processing Expect: header (for example "Expect: 100-Continue").
    • setServletSecurity

      public Set<String> setServletSecurity(ServletSecurityElement constraint)
      Sets the ServletSecurityElement to be applied to the mappings defined for this ServletRegistration.

      This method applies to all mappings added to this ServletRegistration up until the point that the ServletContext from which it was obtained has been initialized.

      If a URL pattern of this ServletRegistration is an exact target of a security-constraint that was established via the portable deployment descriptor, then this method does not change the security-constraint for that pattern, and the pattern will be included in the return value.

      If a URL pattern of this ServletRegistration is an exact target of a security constraint that was established via the ServletSecurity annotation or a previous call to this method, then this method replaces the security constraint for that pattern.

      If a URL pattern of this ServletRegistration is neither the exact target of a security constraint that was established via the ServletSecurity annotation or a previous call to this method, nor the exact target of a security-constraint in the portable deployment descriptor, then this method establishes the security constraint for that pattern from the argument ServletSecurityElement.

      The returned set is not backed by the Dynamic object, so changes in the returned set are not reflected in the Dynamic object, and vice-versa.

      Specified by:
      setServletSecurity in interface ServletRegistration.Dynamic
      Parameters:
      constraint - the ServletSecurityElement to be applied to the patterns mapped to this ServletRegistration
      Returns:
      the (possibly empty) Set of URL patterns that were already the exact target of a security-constraint that was established via the portable deployment descriptor. This method has no effect on the patterns included in the returned set
    • setMultipartConfig

      public void setMultipartConfig(MultipartConfigElement multipartConfig)
      Sets the MultipartConfigElement to be applied to the mappings defined for this ServletRegistration. If this method is called multiple times, each successive call overrides the effects of the former.
      Specified by:
      setMultipartConfig in interface ServletRegistration.Dynamic
      Parameters:
      multipartConfig - the MultipartConfigElement to be applied to the patterns mapped to the registration
    • getRunAsRole

      public String getRunAsRole()
      Gets the name of the runAs role of the Servlet represented by this ServletRegistration.
      Specified by:
      getRunAsRole in interface ServletRegistration
      Returns:
      the name of the runAs role, or null if the Servlet is configured to run as its caller
    • setRunAsRole

      public void setRunAsRole(String roleName)
      Sets the name of the runAs role for this ServletRegistration.
      Specified by:
      setRunAsRole in interface ServletRegistration.Dynamic
      Parameters:
      roleName - the name of the runAs role
    • setAsyncSupported

      public void setAsyncSupported(boolean isAsyncSupported)
      Configures the Servlet or Filter represented by this dynamic Registration as supporting asynchronous operations or not.

      By default, servlet and filters do not support asynchronous operations.

      A call to this method overrides any previous setting.

      Specified by:
      setAsyncSupported in interface Registration.Dynamic
      Parameters:
      isAsyncSupported - true if the Servlet or Filter represented by this dynamic Registration supports asynchronous operations, false otherwise
    • setExpectationHandler

      public void setExpectationHandler(ExpectationHandler expectationHandler)
      Set the ExpectationHandler responsible for processing Expect: header (for example "Expect: 100-Continue").
      Parameters:
      expectationHandler - the ExpectationHandler responsible for processing Expect: header (for example "Expect: 100-Continue").
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(ServletRegistration o)
      Specified by:
      compareTo in interface Comparable<ServletRegistration>