Class CLStaticHttpHandler


public class CLStaticHttpHandler extends StaticHttpHandlerBase
HttpHandler, which processes requests to a static resources resolved by a given ClassLoader.
Author:
Grizzly Team
  • Field Details

    • CHECK_NON_SLASH_TERMINATED_FOLDERS_PROP

      protected static final String CHECK_NON_SLASH_TERMINATED_FOLDERS_PROP
  • Constructor Details

    • CLStaticHttpHandler

      public CLStaticHttpHandler(ClassLoader classLoader, String... docRoots)
      Create HttpHandler, which will handle requests to the static resources resolved by the given class loader.
      Parameters:
      classLoader - ClassLoader to be used to resolve the resources
      docRoots - the doc roots (path prefixes), which will be used to find resources. Effectively each docRoot will be prepended to a resource path before passing it to ClassLoader.getResource(java.lang.String). If no docRoots are set - the resources will be searched starting from ClassLoader's root.
      Throws:
      IllegalArgumentException - if one of the docRoots doesn't end with slash ('/')
  • Method Details

    • addDocRoot

      public boolean addDocRoot(String docRoot)
      Adds doc root (path prefix), which will be used to look up resources. Effectively each registered docRoot will be prepended to a resource path before passing it to ClassLoader.getResource(java.lang.String).
      Parameters:
      docRoot -
      Returns:
      true if this docroot hasn't been registered before, or false otherwise.
      Throws:
      IllegalArgumentException - if one of the docRoots doesn't end with slash ('/')
    • removeDocRoot

      public boolean removeDocRoot(String docRoot)
      Removes docRoot from the doc root list.
      Parameters:
      docRoot -
      Returns:
      true if this docroot was found and removed from the list, or or false if this docroot was not found in the list.
    • getClassLoader

      public ClassLoader getClassLoader()
      Returns the ClassLoader used to resolve the requested HTTP resources.
    • handle

      protected boolean handle(String resourcePath, Request request, Response response) throws Exception
      Lookup a resource based on the request URI, and process it.
      Specified by:
      handle in class StaticHttpHandlerBase
      Parameters:
      resourcePath - 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