Class ResourceHandler
- All Implemented Interfaces:
Handler, HandlerContainer, ResourceService.WelcomeFactory, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle
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).
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractHandler
AbstractHandler.ErrorDispatchHandlerNested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener -
Field Summary
Fields inherited from class HandlerWrapper
_handler -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddoStart()Starts the managed lifecycle beans in the order they were added.Get the cacheControl header to set on all static content..Deprecated.getWelcomeFile(String pathInContext) Finds a matching welcome file for the suppliedResource.String[]voidhandle(String target, Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Handle a request.booleanbooleanbooleanGet the directory option.booleanisEtags()booleanbooleanprotected HttpContent.FactoryvoidsetAcceptRanges(boolean acceptRanges) voidsetBaseResource(Path basePath) voidsetBaseResource(Resource base) voidsetBaseResourceAsString(String baseResource) Deprecated.voidsetCacheControl(String cacheControl) Set the cacheControl header to set on all static content..voidsetDirAllowed(boolean dirAllowed) voidsetDirectoriesListed(boolean directory) Set the directory.voidsetEtags(boolean etags) voidsetGzipEquivalentFileExtensions(List<String> gzipEquivalentFileExtensions) Set file extensions that signify that a file is gzip compressed.voidsetMimeTypes(MimeTypes mimeTypes) voidsetPathInfoOnly(boolean pathInfoOnly) Set true, only the path info will be applied to the resourceBase.voidsetPrecompressedFormats(CompressedContentFormat[] precompressedFormats) voidsetRedirectWelcome(boolean redirectWelcome) voidsetResourceBase(String resourceBase) Deprecated.voidsetStyleSheet(String styleSheet) voidsetWelcomeFiles(String[] welcomeFiles) Methods inherited from class HandlerWrapper
destroy, expandChildren, getHandler, getHandlers, getTail, insertHandler, setAsParent, setHandlerMethods inherited from class AbstractHandlerContainer
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServerMethods inherited from class AbstractHandler
doError, doStop, getServerMethods inherited from class ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Container
getCachedBeans, getEventListenersMethods inherited from interface Dumpable.DumpableContainer
isDumpableMethods inherited from interface LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
-
Constructor Details
-
ResourceHandler
-
ResourceHandler
public ResourceHandler()
-
-
Method Details
-
getWelcomeFile
Description copied from interface:ResourceService.WelcomeFactoryFinds a matching welcome file for the suppliedResource.- Specified by:
getWelcomeFilein interfaceResourceService.WelcomeFactory- Parameters:
pathInContext- the path of the request- Returns:
- The path of the matching welcome file in context or null.
-
doStart
Description copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin classAbstractHandler- Throws:
Exception- If there was a problem starting. Will cause a transition to FAILED state
-
getHttpContentFactory
-
newHttpContentFactory
-
getBaseResource
- Returns:
- Returns the resourceBase.
-
getCacheControl
Get the cacheControl header to set on all static content..- Returns:
- the cacheControl header to set on all static content.
-
getGzipEquivalentFileExtensions
-
getMimeTypes
-
getResourceBase
Deprecated.- Returns:
- Returns the base resource as a string.
-
getStyleSheet
- Returns:
- Returns the stylesheet as a Resource.
-
getWelcomeFiles
-
handle
public void handle(String target, Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException, jakarta.servlet.ServletException Description copied from interface:HandlerHandle a request.- Specified by:
handlein interfaceHandler- Overrides:
handlein classHandlerWrapper- Parameters:
target- The target of the request - either a URI or a name.baseRequest- The original unwrapped request object.request- The request either as theRequestobject or a wrapper of that request.response- The response as theResponseobject or a wrapper of that request.- Throws:
IOException- if unable to handle the request or response processingjakarta.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
- 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
- Parameters:
base- The resourceBase to server content from. If null the context resource base is used.
-
setBaseResource
- Parameters:
basePath- The resourceBase to server content from. If null the context resource base is used.
-
setCacheControl
Set the cacheControl header to set on all static content..- 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
-
setPrecompressedFormats
- 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
-
setPathInfoOnly
public void setPathInfoOnly(boolean pathInfoOnly) Set true, only the path info will be applied to the resourceBase.- 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
Deprecated.- Parameters:
resourceBase- The base resource as a string.
-
setBaseResourceAsString
Deprecated.- Parameters:
baseResource- The base resource as a string.
-
setStyleSheet
- Parameters:
styleSheet- The location of the style sheet to be used as a String.
-
setWelcomeFiles
-
setBaseResource(Resource)