Class StaticHttpHandler


  • public class StaticHttpHandler
    extends StaticHttpHandlerBase
    HttpHandler, which processes requests to a static resources.
    Author:
    Jeanfrancois Arcand, Alexey Stashok
    • Field Detail

      • docRoots

        protected final org.glassfish.grizzly.utils.ArraySet<File> docRoots
    • Constructor Detail

      • StaticHttpHandler

        public StaticHttpHandler()
        Create HttpHandler, which, by default, will handle requests to the static resources located in the current directory.
      • StaticHttpHandler

        public StaticHttpHandler​(String... docRoots)
        Create a new instance which will look for static pages located under the docRoot. If the docRoot is null - static pages won't be served by this HttpHandler
        Parameters:
        docRoots - the folder(s) where the static resource are located. If the docRoot is null - static pages won't be served by this HttpHandler
      • StaticHttpHandler

        public StaticHttpHandler​(Set<String> docRoots)
        Create a new instance which will look for static pages located under the docRoot. If the docRoot is null - static pages won't be served by this HttpHandler
        Parameters:
        docRoots - the folders where the static resource are located. If the docRoot is empty - static pages won't be served by this HttpHandler
    • Method Detail

      • getDefaultDocRoot

        public File getDefaultDocRoot()
        Return the default directory from where files will be serviced.
        Returns:
        the default directory from where file will be serviced.
      • getDocRoots

        public org.glassfish.grizzly.utils.ArraySet<File> getDocRoots()
        Return the list of directories where files will be serviced from.
        Returns:
        the list of directories where files will be serviced from.
      • addDocRoot

        public final File addDocRoot​(String docRoot)
        Add the directory to the list of directories where files will be serviced from.
        Parameters:
        docRoot - the directory to be added to the list of directories where files will be serviced from.
        Returns:
        return the File representation of the passed docRoot.
      • addDocRoot

        public final void addDocRoot​(File docRoot)
        Add the directory to the list of directories where files will be serviced from.
        Parameters:
        docRoot - the directory to be added to the list of directories where files will be serviced from.
      • removeDocRoot

        public void removeDocRoot​(File docRoot)
        Removes the directory from the list of directories where static files will be serviced from.
        Parameters:
        docRoot - the directory to remove.
      • isDirectorySlashOff

        public boolean isDirectorySlashOff()
        Returns:
        true if HTTP 301 redirect shouldn't be sent when requested static resource is a directory, or false otherwise
      • setDirectorySlashOff

        public void setDirectorySlashOff​(boolean directorySlashOff)
        If the directorySlashOff is true HTTP 301 redirect will not be sent when requested static resource is a directory.
        Parameters:
        directorySlashOff -
      • handle

        protected boolean handle​(String uri,
                                 Request request,
                                 Response response)
                          throws Exception
        Lookup a resource based on the request URI, and process it.
        Specified by:
        handle in class StaticHttpHandlerBase
        Parameters:
        uri - The request URI
        request - the Request
        response - the Response
        Returns:
        true, if the static resource has been found and processed, or false, if the static resource hasn't been found
        Throws:
        Exception