Class MethodBase

  • All Implemented Interfaces:
    org.bedework.util.logging.Logged

    public abstract class MethodBase
    extends Object
    implements org.bedework.util.logging.Logged
    Base class for servlet methods.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  MethodBase.MethodInfo
      Allow servlet to create method.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean dumpContent  
    • Constructor Summary

      Constructors 
      Constructor Description
      MethodBase()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addHeaders​(javax.servlet.http.HttpServletResponse resp)  
      abstract void doMethod​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)  
      static List<String> fixPath​(String path)
      Return a path, broken into its elements, after "." and ".." are removed.
      protected String formatHTTPDate​(Timestamp val)  
      abstract com.fasterxml.jackson.databind.ObjectMapper getMapper()  
      List<String> getResourceUri​(javax.servlet.http.HttpServletRequest req)
      Get the decoded and fixed resource URI.
      protected String hrefFromPath​(List<String> path, int start)  
      abstract void init()
      Called at each request
      protected Object readJson​(InputStream is, com.fasterxml.jackson.core.type.TypeReference tr, javax.servlet.http.HttpServletResponse resp)
      Parse the request body, and return the object.
      protected Object readJson​(InputStream is, Class cl, javax.servlet.http.HttpServletResponse resp)
      Parse the request body, and return the object.
      protected void sendJsonError​(javax.servlet.http.HttpServletResponse resp, String msg)  
      protected void sendOkJsonData​(javax.servlet.http.HttpServletResponse resp)  
      protected void sendOkJsonData​(javax.servlet.http.HttpServletResponse resp, String data)  
      protected void write​(String s, javax.servlet.http.HttpServletResponse resp)  
      protected void writeJson​(Object o, javax.servlet.http.HttpServletResponse resp)  
      • Methods inherited from interface org.bedework.util.logging.Logged

        audit, debug, debug, enableAuditLogger, enableErrorLogger, enableMetricsLogger, error, error, error, getLogger, getLogLevel, info, isAuditLoggerEnabled, isErrorLoggerEnabled, isMetricsDebugEnabled, isMetricsLoggerEnabled, metrics, setLoggerClass, setLoggerClass, setLogLevel, trace, trace, warn
    • Field Detail

      • dumpContent

        protected boolean dumpContent
    • Constructor Detail

      • MethodBase

        public MethodBase()
    • Method Detail

      • init

        public abstract void init()
                           throws javax.servlet.ServletException
        Called at each request
        Throws:
        javax.servlet.ServletException
      • getMapper

        public abstract com.fasterxml.jackson.databind.ObjectMapper getMapper()
        Returns:
        mapper used to handle json content
      • doMethod

        public abstract void doMethod​(javax.servlet.http.HttpServletRequest req,
                                      javax.servlet.http.HttpServletResponse resp)
                               throws javax.servlet.ServletException
        Parameters:
        req - the request
        resp - and response
        Throws:
        javax.servlet.ServletException
      • hrefFromPath

        protected String hrefFromPath​(List<String> path,
                                      int start)
      • write

        protected void write​(String s,
                             javax.servlet.http.HttpServletResponse resp)
                      throws javax.servlet.ServletException
        Throws:
        javax.servlet.ServletException
      • writeJson

        protected void writeJson​(Object o,
                                 javax.servlet.http.HttpServletResponse resp)
                          throws javax.servlet.ServletException
        Throws:
        javax.servlet.ServletException
      • getResourceUri

        public List<String> getResourceUri​(javax.servlet.http.HttpServletRequest req)
                                    throws javax.servlet.ServletException
        Get the decoded and fixed resource URI. This calls getServletPath() to obtain the path information. The description of that method is a little obscure in it's meaning. In a request of this form:

        "GET /ucaldav/user/douglm/calendar/1302064354993-g.ics HTTP/1.1[\r][\n]"

        getServletPath() will return

        /user/douglm/calendar/1302064354993-g.ics

        that is the context has been removed. In addition this method will URL decode the path. getRequestUrl() does neither.
        Parameters:
        req - Servlet request object
        Returns:
        List Path elements of fixed up uri
        Throws:
        javax.servlet.ServletException
      • fixPath

        public static List<String> fixPath​(String path)
                                    throws javax.servlet.ServletException
        Return a path, broken into its elements, after "." and ".." are removed. If the parameter path attempts to go above the root we return null. Other than the backslash thing why not use URI?
        Parameters:
        path - String path to be fixed
        Returns:
        String[] fixed path broken into elements
        Throws:
        javax.servlet.ServletException
      • addHeaders

        protected void addHeaders​(javax.servlet.http.HttpServletResponse resp)
                           throws javax.servlet.ServletException
        Throws:
        javax.servlet.ServletException
      • readJson

        protected Object readJson​(InputStream is,
                                  Class cl,
                                  javax.servlet.http.HttpServletResponse resp)
                           throws javax.servlet.ServletException
        Parse the request body, and return the object.
        Parameters:
        is - Input stream for content
        cl - The class we expect
        resp - for status
        Returns:
        Object Parsed body or null for no body
        Throws:
        javax.servlet.ServletException - Some error occurred.
      • readJson

        protected Object readJson​(InputStream is,
                                  com.fasterxml.jackson.core.type.TypeReference tr,
                                  javax.servlet.http.HttpServletResponse resp)
                           throws javax.servlet.ServletException
        Parse the request body, and return the object.
        Parameters:
        is - Input stream for content
        tr - For the class we expect
        resp - for status
        Returns:
        Object Parsed body or null for no body
        Throws:
        javax.servlet.ServletException - Some error occurred.
      • sendJsonError

        protected void sendJsonError​(javax.servlet.http.HttpServletResponse resp,
                                     String msg)
      • sendOkJsonData

        protected void sendOkJsonData​(javax.servlet.http.HttpServletResponse resp)
      • sendOkJsonData

        protected void sendOkJsonData​(javax.servlet.http.HttpServletResponse resp,
                                      String data)