Class ResourceHandler

All Implemented Interfaces:
Handler, HandlerContainer, ResourceService.WelcomeFactory, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, ResourceFactory

public class ResourceHandler extends HandlerWrapper implements ResourceFactory, ResourceService.WelcomeFactory
Resource Handler. This handle will serve static content and handle If-Modified-Since headers. No caching is done. Requests for resources that do not exist are let pass (Eg no 404's).
  • Constructor Details

    • ResourceHandler

      public ResourceHandler(ResourceService resourceService)
    • ResourceHandler

      public ResourceHandler()
  • Method Details

    • getWelcomeFile

      public String getWelcomeFile(String pathInContext) throws IOException
      Description copied from interface: ResourceService.WelcomeFactory
      Finds a matching welcome file for the supplied Resource.
      Specified by:
      getWelcomeFile in interface ResourceService.WelcomeFactory
      Parameters:
      pathInContext - the path of the request
      Returns:
      The path of the matching welcome file in context or null.
      Throws:
      IOException
    • doStart

      public void doStart() throws Exception
      Description copied from class: ContainerLifeCycle
      Starts the managed lifecycle beans in the order they were added.
      Overrides:
      doStart in class AbstractHandler
      Throws:
      AbstractLifeCycle.StopException - If thrown, the lifecycle will immediately be stopped.
      Exception - If there was a problem starting. Will cause a transition to FAILED state
    • getBaseResource

      public Resource getBaseResource()
      Returns:
      Returns the resourceBase.
    • getCacheControl

      public String getCacheControl()
      Returns:
      the cacheControl header to set on all static content.
    • getGzipEquivalentFileExtensions

      public List<String> getGzipEquivalentFileExtensions()
      Returns:
      file extensions that signify that a file is gzip compressed. Eg ".svgz"
    • getMimeTypes

      public MimeTypes getMimeTypes()
    • getResource

      public Resource getResource(String path) throws IOException
      Description copied from interface: ResourceFactory
      Get a Resource from a provided String.

      The behavior here is dependent on the implementation of ResourceFactory. The provided path can be resolved against a known Resource, or can be a from-scratch Resource.

      Specified by:
      getResource in interface ResourceFactory
      Parameters:
      path - The path to the resource
      Returns:
      The resource, that might not actually exist (yet).
      Throws:
      IOException - if unable to create Resource
    • getResourceBase

      public String getResourceBase()
      Returns:
      Returns the base resource as a string.
    • getStylesheet

      public Resource getStylesheet()
      Returns:
      Returns the stylesheet as a Resource.
    • getDefaultStylesheet

      public static Resource getDefaultStylesheet()
    • getWelcomeFiles

      public String[] getWelcomeFiles()
    • handle

      public void handle(String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
      Description copied from interface: Handler
      Handle a request.
      Specified by:
      handle in interface Handler
      Overrides:
      handle in class HandlerWrapper
      Parameters:
      target - The target of the request - either a URI or a name.
      baseRequest - The original unwrapped request object.
      request - The request either as the Request object or a wrapper of that request. The HttpConnection.getCurrentConnection().getHttpChannel().getRequest() method can be used access the Request object if required.
      response - The response as the Response object or a wrapper of that request. The HttpConnection.getCurrentConnection().getHttpChannel().getResponse() method can be used access the Response object if required.
      Throws:
      IOException - if unable to handle the request or response processing
      javax.servlet.ServletException - if unable to handle the request or response due to underlying servlet issue
    • isAcceptRanges

      public boolean isAcceptRanges()
      Returns:
      If true, range requests and responses are supported
    • isDirAllowed

      public boolean isDirAllowed()
      Returns:
      If true, directory listings are returned if no welcome file is found. Else 403 Forbidden.
    • isDirectoriesListed

      public boolean isDirectoriesListed()
      Get the directory option.
      Returns:
      true if directories are listed.
    • isEtags

      public boolean isEtags()
      Returns:
      True if ETag processing is done
    • getPrecompressedFormats

      public CompressedContentFormat[] getPrecompressedFormats()
      Returns:
      Precompressed resources formats that can be used to serve compressed variant of resources.
    • isPathInfoOnly

      public boolean isPathInfoOnly()
      Returns:
      true, only the path info will be applied to the resourceBase
    • isRedirectWelcome

      public boolean isRedirectWelcome()
      Returns:
      If true, welcome files are redirected rather than forwarded to.
    • setAcceptRanges

      public void setAcceptRanges(boolean acceptRanges)
      Parameters:
      acceptRanges - If true, range requests and responses are supported
    • setBaseResource

      public void setBaseResource(Resource base)
      Parameters:
      base - The resourceBase to server content from. If null the context resource base is used.
    • setCacheControl

      public void setCacheControl(String cacheControl)
      Parameters:
      cacheControl - the cacheControl header to set on all static content.
    • setDirAllowed

      public void setDirAllowed(boolean dirAllowed)
      Parameters:
      dirAllowed - If true, directory listings are returned if no welcome file is found. Else 403 Forbidden.
    • setDirectoriesListed

      public void setDirectoriesListed(boolean directory)
      Set the directory.
      Parameters:
      directory - true if directories are listed.
    • setEtags

      public void setEtags(boolean etags)
      Parameters:
      etags - True if ETag processing is done
    • setGzipEquivalentFileExtensions

      public void setGzipEquivalentFileExtensions(List<String> gzipEquivalentFileExtensions)
      Parameters:
      gzipEquivalentFileExtensions - file extensions that signify that a file is gzip compressed. Eg ".svgz"
    • setPrecompressedFormats

      public void setPrecompressedFormats(CompressedContentFormat[] precompressedFormats)
      Parameters:
      precompressedFormats - The list of precompresed formats to serve in encoded format if matching resource found. For example serve gzip encoded file if ".gz" suffixed resource is found.
    • setMimeTypes

      public void setMimeTypes(MimeTypes mimeTypes)
    • setPathInfoOnly

      public void setPathInfoOnly(boolean pathInfoOnly)
      Parameters:
      pathInfoOnly - true, only the path info will be applied to the resourceBase
    • setRedirectWelcome

      public void setRedirectWelcome(boolean redirectWelcome)
      Parameters:
      redirectWelcome - If true, welcome files are redirected rather than forwarded to. redirection is always used if the ResourceHandler is not scoped by a ContextHandler
    • setResourceBase

      public void setResourceBase(String resourceBase)
      Parameters:
      resourceBase - The base resource as a string.
    • setStylesheet

      public void setStylesheet(String stylesheet)
      Parameters:
      stylesheet - The location of the stylesheet to be used as a String.
    • setWelcomeFiles

      public void setWelcomeFiles(String[] welcomeFiles)