Class AbstractServlet

  • All Implemented Interfaces:
    Logable, Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
    Direct Known Subclasses:
    SASServlet

    public abstract class AbstractServlet
    extends javax.servlet.http.HttpServlet
    implements Logable
    Very straightforward servlet wrapper. This sets up logging and debug. All posts and gets are intercepted and routed to a single doIt method.



    3/23/2012: Added simple bootstrapping mechanism. This requires you set a context listener in your web.xml deployment descriptor. See the documentation in Bootstrapper for more details.

    Created by Jeff Gaynor
    on May 3, 2010 at 11:35:16 AM

    See Also:
    Serialized Form
    • Constructor Detail

      • AbstractServlet

        public AbstractServlet()
    • Method Detail

      • getInitialization

        public static Initialization getInitialization()
      • setInitialization

        public static void setInitialization​(Initialization initialization)
      • loadEnvironment

        public abstract void loadEnvironment()
                                      throws IOException
        Loads the current environment. This is *not* called automatically. Usually a user will create a custom environment and have a getter for that which checks if the environment has been set and if not, load it or if so, cast it and return the result.
        Throws:
        IOException
      • isDebugOn

        public boolean isDebugOn()
        Description copied from interface: Logable
        Query if debugging is enabled for this logger.
        Specified by:
        isDebugOn in interface Logable
        Returns:
      • setDebugOn

        public void setDebugOn​(boolean setOn)
        Description copied from interface: Logable
        Enable/disable debugging for this logger
        Specified by:
        setDebugOn in interface Logable
      • debug

        public void debug​(String x)
        Description copied from interface: Logable
        Write a debug message to the log.
        Specified by:
        debug in interface Logable
      • error

        public void error​(String x)
        Description copied from interface: Logable
        Write an error message to the log. Typically this is invoked as the last command before throwing an exception.
        Specified by:
        error in interface Logable
      • info

        public void info​(String x)
        Description copied from interface: Logable
        Write an informational message to the log
        Specified by:
        info in interface Logable
      • warn

        public void warn​(String x)
        Description copied from interface: Logable
        Write a warning to the log. This indicates a severe, but non-fatal condition exists.
        Specified by:
        warn in interface Logable
      • handleException

        protected void handleException​(ExceptionHandlerThingie exceptionHandlerThingie)
                                throws IOException,
                                       javax.servlet.ServletException
        One stop shopping for exception handling. All thrown exceptions are intercepted and run through this. Depending on their type they are wrapped or passed along. You can change this behavior if you need to.

        Note that all runtime exceptions, IOExceptions and ServletExceptions are not modified, so if you over-ride this and throw one of those exceptions you will not get extra cruft.

        Also, a response is passed along. This may be used in over-rides, but is not used in the basic implementation. If it is null, it should be ignored.

        Parameters:
        exceptionHandlerThingie -
        Throws:
        IOException
        javax.servlet.ServletException
      • setExceptionHandler

        public void setExceptionHandler​(ExceptionHandler exceptionHandler)
      • checkContentType

        protected boolean checkContentType​(String rawContentType,
                                           String contentType)
      • doPost

        public void doPost​(javax.servlet.http.HttpServletRequest httpServletRequest,
                           javax.servlet.http.HttpServletResponse httpServletResponse)
                    throws javax.servlet.ServletException,
                           IOException
        Overrides:
        doPost in class javax.servlet.http.HttpServlet
        Throws:
        javax.servlet.ServletException
        IOException
      • doGet

        public void doGet​(javax.servlet.http.HttpServletRequest httpServletRequest,
                          javax.servlet.http.HttpServletResponse httpServletResponse)
                   throws javax.servlet.ServletException,
                          IOException
        Overrides:
        doGet in class javax.servlet.http.HttpServlet
        Throws:
        javax.servlet.ServletException
        IOException
      • doPing

        protected boolean doPing​(javax.servlet.http.HttpServletRequest req,
                                 javax.servlet.http.HttpServletResponse resp)
                          throws javax.servlet.ServletException
        This returns true or false for
        Parameters:
        req -
        resp -
        Returns:
        Throws:
        javax.servlet.ServletException
      • doIt

        protected abstract void doIt​(javax.servlet.http.HttpServletRequest httpServletRequest,
                                     javax.servlet.http.HttpServletResponse httpServletResponse)
                              throws Throwable
        Throws:
        Throwable
      • init

        public void init()
                  throws javax.servlet.ServletException
        Overrides:
        init in class javax.servlet.GenericServlet
        Throws:
        javax.servlet.ServletException
      • resetState

        public void resetState()
        This nulls out the environment which should force a reload of it at the next call. Put anything else you need nulled out here. This allows you to have, e.g., an updated configuration reloaded on the fly without a tomcat restart.
      • CONST

        public static String CONST​(String key)
        Utility to get constants or code gets really wordy.
        Parameters:
        key -
        Returns:
      • printAllParameters

        protected void printAllParameters​(javax.servlet.http.HttpServletRequest request,
                                          MetaDebugUtil debugger)
        This will print all parameters to standard err for this specific debugger during trace. It gives a report on what is actually being passed in.
        Parameters:
        request -
        debugger -
      • printAllParameters

        protected void printAllParameters​(javax.servlet.http.HttpServletRequest request)
        Print all parameters to every request based on the global state of debugging. It is a low-level debugging tool and should never be used in production, since it will bloat the logs. It gives a report on what is actually being passed in.
        Parameters:
        request -
      • getRequestIPAddress

        public static String getRequestIPAddress​(javax.servlet.http.HttpServletRequest request)
        Make a valiant effort to get the IP address in the request.
        Parameters:
        request -
        Returns:
      • logOK

        public void logOK​(javax.servlet.http.HttpServletRequest request)
        For log messages that state a request from a servlet was ok. Some clients require positive reporting for the number of successful calls too, so this can be used for that.
        Parameters:
        request -
      • logOK

        public void logOK​(javax.servlet.http.HttpServletRequest request,
                          String message)
        For logging a success with a custom message. If you don't need a custom message, use logOK(HttpServletRequest).
        Parameters:
        request -
        message -