Class Servlets


  • public class Servlets
    extends Object
    Utility class for building servlet deployments.
    Author:
    Stuart Douglas
    • Method Detail

      • defaultContainer

        public static ServletContainer defaultContainer()
        Returns the default servlet container. For most embedded use cases this will be sufficient.
        Returns:
        The default servlet container
      • newContainer

        public static ServletContainer newContainer()
        Creates a new servlet container.
        Returns:
        A new servlet container
      • deployment

        public static DeploymentInfo deployment()
        Creates a new servlet deployment info structure
        Returns:
        A new deployment info structure
      • servlet

        public static ServletInfo servlet​(Class<? extends jakarta.servlet.Servlet> servletClass)
        Creates a new servlet description with the given class. The servlet name is inferred from the simple name of the class.
        Parameters:
        servletClass - The servlet class
        Returns:
        A new servlet description
      • servlet

        public static ServletInfo servlet​(String name,
                                          Class<? extends jakarta.servlet.Servlet> servletClass)
        Creates a new servlet description with the given name and class
        Parameters:
        name - The servlet name
        servletClass - The servlet class
        Returns:
        A new servlet description
      • servlet

        public static ServletInfo servlet​(String name,
                                          Class<? extends jakarta.servlet.Servlet> servletClass,
                                          InstanceFactory<? extends jakarta.servlet.Servlet> servlet)
        Creates a new servlet description with the given name and class
        Parameters:
        name - The servlet name
        servletClass - The servlet class
        Returns:
        A new servlet description
      • filter

        public static FilterInfo filter​(Class<? extends jakarta.servlet.Filter> filterClass)
        Creates a new filter description with the given class. The filter name is inferred from the simple name of the class.
        Parameters:
        filterClass - The filter class
        Returns:
        A new filter description
      • filter

        public static FilterInfo filter​(String name,
                                        Class<? extends jakarta.servlet.Filter> filterClass)
        Creates a new filter description with the given name and class
        Parameters:
        name - The filter name
        filterClass - The filter class
        Returns:
        A new filter description
      • filter

        public static FilterInfo filter​(String name,
                                        Class<? extends jakarta.servlet.Filter> filterClass,
                                        InstanceFactory<? extends jakarta.servlet.Filter> filter)
        Creates a new filter description with the given name and class
        Parameters:
        name - The filter name
        filterClass - The filter class
        Returns:
        A new filter description
      • multipartConfig

        public static jakarta.servlet.MultipartConfigElement multipartConfig​(String location,
                                                                             long maxFileSize,
                                                                             long maxRequestSize,
                                                                             int fileSizeThreshold)
        Creates a new multipart config element
        Parameters:
        location - the directory location where files will be stored
        maxFileSize - the maximum size allowed for uploaded files
        maxRequestSize - the maximum size allowed for multipart/form-data requests
        fileSizeThreshold - the size threshold after which files will be written to disk
      • errorPage

        public static ErrorPage errorPage​(String location,
                                          Class<? extends Throwable> exceptionType)
        Create an ErrorPage instance for a given exception type
        Parameters:
        location - The location to redirect to
        exceptionType - The exception type
        Returns:
        The error page definition
      • errorPage

        public static ErrorPage errorPage​(String location,
                                          int statusCode)
        Create an ErrorPage instance for a given response code
        Parameters:
        location - The location to redirect to
        statusCode - The status code
        Returns:
        The error page definition
      • errorPage

        public static ErrorPage errorPage​(String location)
        Create an ErrorPage that corresponds to the default error page
        Parameters:
        location - The error page location
        Returns:
        The error page instance