Class AbstractXServlet

  • All Implemented Interfaces:
    Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    @NotThreadSafe
    public abstract class AbstractXServlet
    extends javax.servlet.http.HttpServlet
    Abstract HTTP based servlet. Compared to the default HttpServlet this class uses a handler map with EHttpMethod as the key.
    The following features are added compared to the default servlet implementation:
    • It has counting statistics
    • It has timing statistics
    • It enforces a character set on the response
    • It checks for known security attacks (like httpoxy)
    • It has custom handler per HTTP method
    • It has custom filter
    • It has custom exception handler
    • It handles Post-Redirect-Get centrally.
    Note: it must be derived from HttpServlet to be usable with annotation based configuration in Jetty (was GenericServlet previously)
    Since:
    9.0.0
    Author:
    Philip Helger
    See Also:
    Serialized Form
    • Field Detail

      • REQUEST_ATTR_HANDLED_ASYNC

        public static final String REQUEST_ATTR_HANDLED_ASYNC
        Internal request attribute defining whether a request was handled asynchronously. If this attribute is not present, it means synchronous
        See Also:
        Constant Field Values
      • REQUEST_ATTR_SCOPE_CREATED

        public static final String REQUEST_ATTR_SCOPE_CREATED
        Internal request attribute defining whether a request scope was created or re-used
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractXServlet

        public AbstractXServlet()
        Constructor.
    • Method Detail

      • handlerRegistry

        @Nonnull
        @ReturnsMutableObject
        protected final XServletHandlerRegistry handlerRegistry()
        Returns:
        The handler registry for HTTP method to handler registration. Never null.
      • filterLowLevelList

        @Nonnull
        @ReturnsMutableObject
        protected final com.helger.commons.collection.impl.ICommonsList<IXServletLowLevelFilter> filterLowLevelList()
        Returns:
        The internal filter list where custom filters can be added. Never null.
      • filterHighLevelList

        @Nonnull
        @ReturnsMutableObject
        protected final com.helger.commons.collection.impl.ICommonsList<IXServletHighLevelFilter> filterHighLevelList()
        Returns:
        The internal filter list where custom filters can be added. Never null.
      • exceptionHandler

        @Nonnull
        @ReturnsMutableObject
        protected final com.helger.commons.callback.CallbackList<IXServletExceptionHandler> exceptionHandler()
        Returns:
        The internal exception handler list. Never null.
      • settings

        public final XServletSettings settings()
        Returns:
        Settings for this servlet. May not be null.
      • getServletStatusMgr

        @Nonnull
        protected final ServletStatusManager getServletStatusMgr()
        Returns:
        The servlet status manager stored in the constructor. Never null.
      • log

        public final void log​(String sMsg)
        Overrides:
        log in class javax.servlet.GenericServlet
      • log

        public final void log​(String sMsg,
                              Throwable t)
        Overrides:
        log in class javax.servlet.GenericServlet
      • init

        public final void init​(@Nonnull
                               javax.servlet.ServletConfig aSC)
                        throws javax.servlet.ServletException
        A final overload of "init". Overload "init" instead.
        Specified by:
        init in interface javax.servlet.Servlet
        Overrides:
        init in class javax.servlet.GenericServlet
        Throws:
        javax.servlet.ServletException
      • destroy

        @OverridingMethodsMustInvokeSuper
        public void destroy()
        Specified by:
        destroy in interface javax.servlet.Servlet
        Overrides:
        destroy in class javax.servlet.GenericServlet
      • logInvalidRequestSetup

        @OverrideOnDemand
        protected void logInvalidRequestSetup​(@Nonnull
                                              String sMsg,
                                              @Nonnull
                                              javax.servlet.http.HttpServletRequest aHttpRequest)
        This method logs errors, in case a HttpServletRequest object is missing basic information or uses unsupported values for e.g. HTTP version and HTTP method.
        Parameters:
        sMsg - The concrete message to emit. May not be null.
        aHttpRequest - The current HTTP request. May not be null.
      • service

        protected final void service​(@Nonnull
                                     javax.servlet.http.HttpServletRequest aHttpRequest,
                                     @Nonnull
                                     javax.servlet.http.HttpServletResponse aHttpResponse)
                              throws javax.servlet.ServletException,
                                     IOException
        Dispatches client requests to the protected service method. There's no need to override this method.
        Overrides:
        service in class javax.servlet.http.HttpServlet
        Parameters:
        aHttpRequest - the HttpServletRequest object that contains the request the client made of the servlet
        aHttpResponse - the HttpServletResponse object that contains the response the servlet returns to the client
        Throws:
        IOException - if an input or output error occurs while the servlet is handling the HTTP request
        javax.servlet.ServletException - if the HTTP request cannot be handled
        See Also:
        Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
      • service

        public final void service​(@Nonnull
                                  javax.servlet.ServletRequest req,
                                  @Nonnull
                                  javax.servlet.ServletResponse res)
                           throws javax.servlet.ServletException,
                                  IOException
        Specified by:
        service in interface javax.servlet.Servlet
        Overrides:
        service in class javax.servlet.http.HttpServlet
        Throws:
        javax.servlet.ServletException
        IOException