Class StaticHttpHandler
- java.lang.Object
-
- org.glassfish.grizzly.http.server.HttpHandler
-
- org.glassfish.grizzly.http.server.StaticHttpHandlerBase
-
- org.glassfish.grizzly.http.server.StaticHttpHandler
-
public class StaticHttpHandler extends StaticHttpHandlerBase
HttpHandler, which processes requests to a static resources.- Author:
- Jeanfrancois Arcand, Alexey Stashok
-
-
Constructor Summary
Constructors Constructor Description StaticHttpHandler()Create HttpHandler, which, by default, will handle requests to the static resources located in the current directory.StaticHttpHandler(String... docRoots)Create a new instance which will look for static pages located under the docRoot.StaticHttpHandler(Set<String> docRoots)Create a new instance which will look for static pages located under the docRoot.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDocRoot(File docRoot)Add the directory to the list of directories where files will be serviced from.FileaddDocRoot(String docRoot)Add the directory to the list of directories where files will be serviced from.FilegetDefaultDocRoot()Return the default directory from where files will be serviced.org.glassfish.grizzly.utils.ArraySet<File>getDocRoots()Return the list of directories where files will be serviced from.protected booleanhandle(String uri, Request request, Response response)Lookup a resource based on the request URI, and process it.booleanisDirectorySlashOff()voidremoveDocRoot(File docRoot)Removes the directory from the list of directories where static files will be serviced from.voidsetDirectorySlashOff(boolean directorySlashOff)If the directorySlashOff is true HTTP 301 redirect will not be sent when requested static resource is a directory.-
Methods inherited from class org.glassfish.grizzly.http.server.StaticHttpHandlerBase
addCachingHeaders, addToFileCache, getRelativeURI, isFileCacheEnabled, lookupFileCache, onMissingResource, pickupContentType, sendFile, service, setFileCacheEnabled
-
Methods inherited from class org.glassfish.grizzly.http.server.HttpHandler
destroy, getErrorPageGenerator, getName, getRequestExecutorProvider, getRequestURIEncoding, getSessionCookieName, getSessionManager, isAllowCustomStatusMessage, isAllowEncodedSlash, sendAcknowledgment, setAllowCustomStatusMessage, setAllowEncodedSlash, setDecodeUrl, setDispatcherHelper, setRequestURIEncoding, setRequestURIEncoding, start, updatePaths
-
-
-
-
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
Filerepresentation of the passeddocRoot.
-
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:
handlein classStaticHttpHandlerBase- Parameters:
uri- The request URIrequest- theRequestresponse- theResponse- Returns:
- true, if the static resource has been found and processed, or false, if the static resource hasn't been found
- Throws:
Exception
-
-