Class ResourceServlet

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

    public abstract class ResourceServlet
    extends javax.servlet.http.HttpServlet
    Base class for serving static resources.

    Supports caching, ETags, basic content type detection, and limited gzip compression.

    See Also:
    Serialized Form
    • Constructor Detail

      • ResourceServlet

        protected ResourceServlet​(com.google.common.cache.Cache<Path,​ResourceServlet.Resource> cache,
                                  boolean refresh,
                                  boolean cacheOnClient)
    • Method Detail

      • contentType

        protected static String contentType​(String name)
      • getResourcePath

        protected abstract Path getResourcePath​(String pathInfo)
                                         throws IOException
        Get the resource path on the filesystem that should be served for this request.
        Parameters:
        pathInfo - result of HttpServletRequest.getPathInfo().
        Returns:
        path where static content can be found.
        Throws:
        IOException - if an error occurred resolving the resource.
      • shouldProcessResourceBeforeServe

        protected boolean shouldProcessResourceBeforeServe​(javax.servlet.http.HttpServletRequest req,
                                                           javax.servlet.http.HttpServletResponse rsp,
                                                           Path p)
        Indicates that resource requires some processing before being served.

        If true, the caching headers in response are set to not cache. Additionally, streaming option is disabled.

        Parameters:
        req - the HTTP servlet request
        rsp - the HTTP servlet response
        p - URL path
        Returns:
        true if the processResourceBeforeServe(HttpServletRequest, HttpServletResponse, Resource) should be called.
      • processResourceBeforeServe

        protected ResourceServlet.Resource processResourceBeforeServe​(javax.servlet.http.HttpServletRequest req,
                                                                      javax.servlet.http.HttpServletResponse rsp,
                                                                      ResourceServlet.Resource resource)
        Edits the resource before adding it to the response.
        Parameters:
        req - the HTTP servlet request
        rsp - the HTTP servlet response
      • doGet

        protected void doGet​(javax.servlet.http.HttpServletRequest req,
                             javax.servlet.http.HttpServletResponse rsp)
                      throws IOException
        Overrides:
        doGet in class javax.servlet.http.HttpServlet
        Throws:
        IOException