Package org.eclipse.jetty.server.handler
Class ResourceHandler
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.server.handler.AbstractHandler
-
- org.eclipse.jetty.server.handler.AbstractHandlerContainer
-
- org.eclipse.jetty.server.handler.HandlerWrapper
-
- org.eclipse.jetty.server.handler.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).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.server.handler.AbstractHandler
AbstractHandler.ErrorDispatchHandler
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
-
Field Summary
-
Fields inherited from class org.eclipse.jetty.server.handler.HandlerWrapper
_handler
-
-
Constructor Summary
Constructors Constructor Description ResourceHandler()
ResourceHandler(ResourceService resourceService)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
doStart()
Starts the managed lifecycle beans in the order they were added.Resource
getBaseResource()
java.lang.String
getCacheControl()
static Resource
getDefaultStylesheet()
java.util.List<java.lang.String>
getGzipEquivalentFileExtensions()
MimeTypes
getMimeTypes()
CompressedContentFormat[]
getPrecompressedFormats()
Resource
getResource(java.lang.String path)
Get a Resource from a provided String.java.lang.String
getResourceBase()
Resource
getStylesheet()
java.lang.String
getWelcomeFile(java.lang.String pathInContext)
Finds a matching welcome file for the suppliedResource
.java.lang.String[]
getWelcomeFiles()
void
handle(java.lang.String target, Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
Handle a request.boolean
isAcceptRanges()
boolean
isDirAllowed()
boolean
isDirectoriesListed()
Get the directory option.boolean
isEtags()
boolean
isPathInfoOnly()
boolean
isRedirectWelcome()
void
setAcceptRanges(boolean acceptRanges)
void
setBaseResource(Resource base)
void
setCacheControl(java.lang.String cacheControl)
void
setDirAllowed(boolean dirAllowed)
void
setDirectoriesListed(boolean directory)
Set the directory.void
setEtags(boolean etags)
void
setGzipEquivalentFileExtensions(java.util.List<java.lang.String> gzipEquivalentFileExtensions)
void
setMimeTypes(MimeTypes mimeTypes)
void
setPathInfoOnly(boolean pathInfoOnly)
void
setPrecompressedFormats(CompressedContentFormat[] precompressedFormats)
void
setRedirectWelcome(boolean redirectWelcome)
void
setResourceBase(java.lang.String resourceBase)
void
setStylesheet(java.lang.String stylesheet)
void
setWelcomeFiles(java.lang.String[] welcomeFiles)
-
Methods inherited from class org.eclipse.jetty.server.handler.HandlerWrapper
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandler
-
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServer
-
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler
doError, doStop, getServer
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListeners
-
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
-
-
-
-
Constructor Detail
-
ResourceHandler
public ResourceHandler(ResourceService resourceService)
-
ResourceHandler
public ResourceHandler()
-
-
Method Detail
-
getWelcomeFile
public java.lang.String getWelcomeFile(java.lang.String pathInContext) throws java.io.IOException
Description copied from interface:ResourceService.WelcomeFactory
Finds a matching welcome file for the suppliedResource
.- Specified by:
getWelcomeFile
in interfaceResourceService.WelcomeFactory
- Parameters:
pathInContext
- the path of the request- Returns:
- The path of the matching welcome file in context or null.
- Throws:
java.io.IOException
-
doStart
public void doStart() throws java.lang.Exception
Description copied from class:ContainerLifeCycle
Starts the managed lifecycle beans in the order they were added.- Overrides:
doStart
in classAbstractHandler
- Throws:
AbstractLifeCycle.StopException
- If thrown, the lifecycle will immediately be stopped.java.lang.Exception
- If there was a problem starting. Will cause a transition to FAILED state
-
getBaseResource
public Resource getBaseResource()
- Returns:
- Returns the resourceBase.
-
getCacheControl
public java.lang.String getCacheControl()
- Returns:
- the cacheControl header to set on all static content.
-
getGzipEquivalentFileExtensions
public java.util.List<java.lang.String> getGzipEquivalentFileExtensions()
- Returns:
- file extensions that signify that a file is gzip compressed. Eg ".svgz"
-
getMimeTypes
public MimeTypes getMimeTypes()
-
getResource
public Resource getResource(java.lang.String path) throws java.io.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 interfaceResourceFactory
- Parameters:
path
- The path to the resource- Returns:
- The resource, that might not actually exist (yet).
- Throws:
java.io.IOException
- if unable to create Resource
-
getResourceBase
public java.lang.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 java.lang.String[] getWelcomeFiles()
-
handle
public void handle(java.lang.String target, Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws java.io.IOException, jakarta.servlet.ServletException
Description copied from interface:Handler
Handle a request.- Specified by:
handle
in interfaceHandler
- Overrides:
handle
in 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 theRequest
object or a wrapper of that request. The
method can be used access the Request object if required.HttpConnection.getCurrentConnection()
.getHttpChannel()
.getRequest()
response
- The response as theResponse
object or a wrapper of that request. The
method can be used access the Response object if required.HttpConnection.getCurrentConnection()
.getHttpChannel()
.getResponse()
- Throws:
java.io.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
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(java.lang.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(java.util.List<java.lang.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(java.lang.String resourceBase)
- Parameters:
resourceBase
- The base resource as a string.
-
setStylesheet
public void setStylesheet(java.lang.String stylesheet)
- Parameters:
stylesheet
- The location of the stylesheet to be used as a String.
-
setWelcomeFiles
public void setWelcomeFiles(java.lang.String[] welcomeFiles)
-
-