Top Description Inners Fields Methods
org.apache.catalina

public Interface WebResourceRoot

extends Lifecycle
Known Direct Implementers
org.apache.catalina.webresources.StandardRoot
Imports
java.io.InputStream, java.net.URL, java.util.List, .Set

Represents the complete set of resources for a web application. The resources for a web application comprise of multiple ResourceSets and when looking for a Resource, the ResourceSets are processed in the following order:
  1. Pre - Resources defined by the <PreResource> element in the web application's context.xml. Resources will be searched in the order they were specified.
  2. Main - The main resources for the web application - i.e. the WAR or the directory containing the expanded WAR
  3. JARs - Resource JARs as defined by the Servlet specification. JARs will be searched in the order they were added to the ResourceRoot.
  4. Post - Resources defined by the <PostResource> element in the web application's context.xml. Resources will be searched in the order they were specified.
The following conventions should be noted: This mechanism replaces and extends the following features that were present in earlier versions:

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
public static interface
WebResourceRoot.CacheStrategy

Provides a mechanism to modify the caching behaviour.

public static enum

Field Summary

Inherited from org.apache.catalina.Lifecycle:
AFTER_DESTROY_EVENTAFTER_INIT_EVENTAFTER_START_EVENTAFTER_STOP_EVENTBEFORE_DESTROY_EVENTBEFORE_INIT_EVENTBEFORE_START_EVENTBEFORE_STOP_EVENTCONFIGURE_START_EVENTCONFIGURE_STOP_EVENTPERIODIC_EVENTSTART_EVENTSTOP_EVENT

Method Summary

Modifier and TypeMethod and Description
public void
addJarResources(WebResourceSet
the resource set to use
webResourceSet
)

Adds the provided WebResourceSet to this web application as a 'Jar' resource.

public void
addPostResources(WebResourceSet
the resource set to use
webResourceSet
)

Adds the provided WebResourceSet to this web application as a 'Post' resource.

public void
addPreResources(WebResourceSet
the resource set to use
webResourceSet
)

Adds the provided WebResourceSet to this web application as a 'Pre' resource.

public void
backgroundProcess()

This method will be invoked by the context on a periodic basis and allows the implementation a method that executes periodic tasks, such as purging expired cache entries.

public void
createWebResourceSet(WebResourceRoot.ResourceSetType
The type of WebResourceSet to create
type
,
String
The path within the web application that the resources should be published at. It must start with '/'.
webAppMount
,
URL
The URL of the resource (must locate a JAR, file or directory)
url
,
String
The path within the resource where the content is to be found. It must start with '/'.
internalPath
)

Creates a new WebResourceSet for this WebResourceRoot based on the provided parameters.

public void
createWebResourceSet(WebResourceRoot.ResourceSetType
The type of WebResourceSet to create
type
,
String
The path within the web application that the resources should be published at. It must start with '/'.
webAppMount
,
String
The location of the resources
base
,
String
The path within the resource to the archive where the content is to be found. If there is no archive then this should be null.
archivePath
,
String
The path within the archive (or the resource if the archivePath is null where the content is to be found. It must start with '/'.
internalPath
)

Creates a new WebResourceSet for this WebResourceRoot based on the provided parameters.

public void
deregisterTrackedResource(TrackedWebResource
the resource that was tracked
trackedResource
)

Stop tracking specified resource, once it no longer needs to free resources.

public void
gc()

Implementations may cache some information to improve performance.

public boolean

Returns:

true if symbolic links are allowed
getAllowLinking
()

Determine if this resources allow the use of symbolic links.

public String

Returns:

The strategy to use for the resources archive lookup
getArchiveIndexStrategy
()

Get the strategy to use for the resources archive lookup.

public WebResourceRoot.ArchiveIndexStrategy

Returns:

The strategy to use for the resources archive lookup
getArchiveIndexStrategyEnum
()

Get the strategy to use for the resources archive lookup.

public List<URL>

Returns:

the set of WebResourceSet#getBaseUrl() for all WebResourceSets used by this root.
getBaseUrls
()

public long

Returns:

Maximum cache size in kilobytes
getCacheMaxSize
()

Get the maximum permitted size for the cache.

public int

Returns:

Maximum size for a single cached object in kilobytes
getCacheObjectMaxSize
()

Get the maximum permitted size for a single object in the cache.

public default WebResourceRoot.CacheStrategy

Returns:

the current caching strategy or null if no strategy has been configured
getCacheStrategy
()

Obtain the current caching strategy.

public long

Returns:

TTL in milliseconds
getCacheTtl
()

Get the Time-To-Live (TTL) for cache entries.

public WebResource

Returns:

The object that represents the class loader resource at the given path
getClassLoaderResource
(String
The path of the class loader resource of interest relative to the the root of class loader resources for this web application.
path
)

Obtain the object that represents the class loader resource at the given path.

public WebResource[]

Returns:

The objects that represents the class loader resources at the given path. There will always be at least one element although that element may represent a resource that is not present.
getClassLoaderResources
(String
The path for the class loader resource of interest relative to the root of the class loader resources for the web application. It must start with '/'.
path
)

Obtain the objects that represent the class loader resource at the given path.

public Context

Returns:

the web application this WebResourceRoot is associated with.
getContext
()

public WebResourceSet[]

Returns:

the list of WebResourceSet configured to this web application as a 'Jar' resource.
getJarResources
()

public WebResourceSet[]

Returns:

the list of WebResourceSet configured to this web application as a 'Post' resource.
getPostResources
()

public WebResourceSet[]

Returns:

the list of WebResourceSet configured to this web application as a 'Pre' resource.
getPreResources
()

public WebResource

Returns:

The object that represents the resource at the given path
getResource
(String
The path for the resource of interest relative to the root of the web application. It must start with '/'.
path
)

Obtain the object that represents the resource at the given path.

public WebResource[]

Returns:

The objects that represents the resource at the given path
getResources
(String
The path for the resource of interest relative to the root of the web application. It must start with '/'.
path
)

Obtain the objects that represent the resource at the given path.

public boolean

Returns:

true if it has been enabled, otherwise false
getTrackLockedFiles
()

Has the track locked files feature been enabled?

public boolean

Returns:

true if caching is permitted for this web application.
isCachingAllowed
()

public String[]

Returns:

The list of resources. If path does not refer to a directory then a zero length array will be returned.
list
(String
The path for the resource of interest relative to the root of the web application. It must start with '/'.
path
)

Obtain the list of the names of all of the files and directories located in the specified directory.

public WebResource[]

Returns:

The list of resources. If path does not refer to a directory then a zero length array will be returned.
listResources
(String
The path for the resource of interest relative to the root of the web application. It must start with '/'.
path
)

Obtain the list of all of the WebResources in the specified directory.

public Set<String>

Returns:

The Set of resources. If path does not refer to a directory then null will be returned.
listWebAppPaths
(String
The path for the resource of interest relative to the root of the web application. It must start with '/'.
path
)

Obtain the Set of the web applications pathnames of all of the files and directories located in the specified directory.

public boolean

Returns:

true if the directory was created, otherwise false
mkdir
(String
The path for the new resource to create relative to the root of the web application. It must start with '/'.
path
)

Create a new directory at the given path.

public void
registerTrackedResource(TrackedWebResource
the resource that will be tracked
trackedResource
)

Add a specified resource to track to be able to later release resources on stop.

public void
setAllowLinking(boolean
true if symbolic links are allowed.
allowLinking
)

Configure if this resources allow the use of symbolic links.

public void
setArchiveIndexStrategy(String
The strategy to use for the resources archive lookup
archiveIndexStrategy
)

Set the strategy to use for the resources archive lookup.

public void
setCacheMaxSize(long
Maximum cache size in kilobytes
cacheMaxSize
)

Set the maximum permitted size for the cache.

public void
setCacheObjectMaxSize(int
Maximum size for a single cached object in kilobytes
cacheObjectMaxSize
)

Set the maximum permitted size for a single object in the cache.

public default void
setCacheStrategy(WebResourceRoot.CacheStrategy
The new strategy to use or null for no strategy
strategy
)

Set the current caching strategy.

public void
setCacheTtl(long
TTL in milliseconds
ttl
)

Set the Time-To-Live (TTL) for cache entries.

public void
setCachingAllowed(boolean
true to enable caching, else false
cachingAllowed
)

Set whether or not caching is permitted for this web application.

public void
setContext(Context
the associated context
context
)

Set the web application this WebResourceRoot is associated with.

public void
setTrackLockedFiles(boolean
true to enable it, false to disable it
trackLockedFiles
)

Controls whether the track locked files feature is enabled.

public boolean

Returns:

true if and only if the new Resource is written
write
(String
The path to be used for the new Resource. It is relative to the root of the web application and must start with '/'.
path
,
InputStream
The InputStream that will provide the content for the new Resource.
is
,
boolean
If true and the resource already exists it will be overwritten. If false and the resource already exists the write will fail.
overwrite
)

Create a new resource at the requested path using the provided InputStream.

Inherited from org.apache.catalina.Lifecycle:
addLifecycleListenerdestroyfindLifecycleListenersgetStategetStateNameinitremoveLifecycleListenerstartstop

Method Detail

addJarResourcesback to summary
public void addJarResources(WebResourceSet webResourceSet)

Adds the provided WebResourceSet to this web application as a 'Jar' resource.

Parameters
webResourceSet:WebResourceSet

the resource set to use

addPostResourcesback to summary
public void addPostResources(WebResourceSet webResourceSet)

Adds the provided WebResourceSet to this web application as a 'Post' resource.

Parameters
webResourceSet:WebResourceSet

the resource set to use

addPreResourcesback to summary
public void addPreResources(WebResourceSet webResourceSet)

Adds the provided WebResourceSet to this web application as a 'Pre' resource.

Parameters
webResourceSet:WebResourceSet

the resource set to use

backgroundProcessback to summary
public void backgroundProcess()

This method will be invoked by the context on a periodic basis and allows the implementation a method that executes periodic tasks, such as purging expired cache entries.

createWebResourceSetback to summary
public void createWebResourceSet(WebResourceRoot.ResourceSetType type, String webAppMount, URL url, String internalPath)

Creates a new WebResourceSet for this WebResourceRoot based on the provided parameters.

Parameters
type:WebResourceRoot.ResourceSetType

The type of WebResourceSet to create

webAppMount:String

The path within the web application that the resources should be published at. It must start with '/'.

url:URL

The URL of the resource (must locate a JAR, file or directory)

internalPath:String

The path within the resource where the content is to be found. It must start with '/'.

createWebResourceSetback to summary
public void createWebResourceSet(WebResourceRoot.ResourceSetType type, String webAppMount, String base, String archivePath, String internalPath)

Creates a new WebResourceSet for this WebResourceRoot based on the provided parameters.

Parameters
type:WebResourceRoot.ResourceSetType

The type of WebResourceSet to create

webAppMount:String

The path within the web application that the resources should be published at. It must start with '/'.

base:String

The location of the resources

archivePath:String

The path within the resource to the archive where the content is to be found. If there is no archive then this should be null.

internalPath:String

The path within the archive (or the resource if the archivePath is null where the content is to be found. It must start with '/'.

deregisterTrackedResourceback to summary
public void deregisterTrackedResource(TrackedWebResource trackedResource)

Stop tracking specified resource, once it no longer needs to free resources.

Parameters
trackedResource:TrackedWebResource

the resource that was tracked

gcback to summary
public void gc()

Implementations may cache some information to improve performance. This method triggers the clean-up of those resources.

getAllowLinkingback to summary
public boolean getAllowLinking()

Determine if this resources allow the use of symbolic links.

Returns:boolean

true if symbolic links are allowed

getArchiveIndexStrategyback to summary
public String getArchiveIndexStrategy()

Get the strategy to use for the resources archive lookup.

Returns:String

The strategy to use for the resources archive lookup

getArchiveIndexStrategyEnumback to summary
public WebResourceRoot.ArchiveIndexStrategy getArchiveIndexStrategyEnum()

Get the strategy to use for the resources archive lookup.

Returns:WebResourceRoot.ArchiveIndexStrategy

The strategy to use for the resources archive lookup

getBaseUrlsback to summary
public List<URL> getBaseUrls()
Returns:List<URL>

the set of WebResourceSet#getBaseUrl() for all WebResourceSets used by this root.

getCacheMaxSizeback to summary
public long getCacheMaxSize()

Get the maximum permitted size for the cache.

Returns:long

Maximum cache size in kilobytes

getCacheObjectMaxSizeback to summary
public int getCacheObjectMaxSize()

Get the maximum permitted size for a single object in the cache. Note that the maximum size in bytes may not exceed Integer#MAX_VALUE.

Returns:int

Maximum size for a single cached object in kilobytes

getCacheStrategyback to summary
public default WebResourceRoot.CacheStrategy getCacheStrategy()

Obtain the current caching strategy.

The default implementation returns null. Sub-classes wishing to utilise a CacheStrategy should provide an appropriate implementation.

Returns:WebResourceRoot.CacheStrategy

the current caching strategy or null if no strategy has been configured

getCacheTtlback to summary
public long getCacheTtl()

Get the Time-To-Live (TTL) for cache entries.

Returns:long

TTL in milliseconds

getClassLoaderResourceback to summary
public WebResource getClassLoaderResource(String path)

Obtain the object that represents the class loader resource at the given path. WEB-INF/classes is always searched prior to searching JAR files in WEB-INF/lib. The search order for JAR files will be consistent across subsequent calls to this method until the web application is reloaded. No guarantee is made as to what the search order for JAR files may be.

Parameters
path:String

The path of the class loader resource of interest relative to the the root of class loader resources for this web application.

Returns:WebResource

The object that represents the class loader resource at the given path

getClassLoaderResourcesback to summary
public WebResource[] getClassLoaderResources(String path)

Obtain the objects that represent the class loader resource at the given path. Note that the resource at that path may not exist. If the path does not exist, the WebResource returned will be associated with the main WebResourceSet. This will include all matches even if the resource would not normally be accessible (e.g. because it was overridden by another resource)

Parameters
path:String

The path for the class loader resource of interest relative to the root of the class loader resources for the web application. It must start with '/'.

Returns:WebResource[]

The objects that represents the class loader resources at the given path. There will always be at least one element although that element may represent a resource that is not present.

getContextback to summary
public Context getContext()
Returns:Context

the web application this WebResourceRoot is associated with.

getJarResourcesback to summary
public WebResourceSet[] getJarResources()
Returns:WebResourceSet[]

the list of WebResourceSet configured to this web application as a 'Jar' resource.

getPostResourcesback to summary
public WebResourceSet[] getPostResources()
Returns:WebResourceSet[]

the list of WebResourceSet configured to this web application as a 'Post' resource.

getPreResourcesback to summary
public WebResourceSet[] getPreResources()
Returns:WebResourceSet[]

the list of WebResourceSet configured to this web application as a 'Pre' resource.

getResourceback to summary
public WebResource getResource(String path)

Obtain the object that represents the resource at the given path. Note that the resource at that path may not exist. If the resource does not exist, the WebResource returned will be associated with the main WebResourceSet.

Parameters
path:String

The path for the resource of interest relative to the root of the web application. It must start with '/'.

Returns:WebResource

The object that represents the resource at the given path

getResourcesback to summary
public WebResource[] getResources(String path)

Obtain the objects that represent the resource at the given path. Note that the resource at that path may not exist. If the resource does not exist, the WebResource returned will be associated with the main WebResourceSet. This will include all matches even if the resource would not normally be accessible (e.g. because it was overridden by another resource)

Parameters
path:String

The path for the resource of interest relative to the root of the web application. It must start with '/'.

Returns:WebResource[]

The objects that represents the resource at the given path

getTrackLockedFilesback to summary
public boolean getTrackLockedFiles()

Has the track locked files feature been enabled?

Returns:boolean

true if it has been enabled, otherwise false

isCachingAllowedback to summary
public boolean isCachingAllowed()
Returns:boolean

true if caching is permitted for this web application.

listback to summary
public String[] list(String path)

Obtain the list of the names of all of the files and directories located in the specified directory.

Parameters
path:String

The path for the resource of interest relative to the root of the web application. It must start with '/'.

Returns:String[]

The list of resources. If path does not refer to a directory then a zero length array will be returned.

listResourcesback to summary
public WebResource[] listResources(String path)

Obtain the list of all of the WebResources in the specified directory.

Parameters
path:String

The path for the resource of interest relative to the root of the web application. It must start with '/'.

Returns:WebResource[]

The list of resources. If path does not refer to a directory then a zero length array will be returned.

listWebAppPathsback to summary
public Set<String> listWebAppPaths(String path)

Obtain the Set of the web applications pathnames of all of the files and directories located in the specified directory. Paths representing directories will end with a '/' character.

Parameters
path:String

The path for the resource of interest relative to the root of the web application. It must start with '/'.

Returns:Set<String>

The Set of resources. If path does not refer to a directory then null will be returned.

mkdirback to summary
public boolean mkdir(String path)

Create a new directory at the given path.

Parameters
path:String

The path for the new resource to create relative to the root of the web application. It must start with '/'.

Returns:boolean

true if the directory was created, otherwise false

registerTrackedResourceback to summary
public void registerTrackedResource(TrackedWebResource trackedResource)

Add a specified resource to track to be able to later release resources on stop.

Parameters
trackedResource:TrackedWebResource

the resource that will be tracked

setAllowLinkingback to summary
public void setAllowLinking(boolean allowLinking)

Configure if this resources allow the use of symbolic links.

Parameters
allowLinking:boolean

true if symbolic links are allowed.

setArchiveIndexStrategyback to summary
public void setArchiveIndexStrategy(String archiveIndexStrategy)

Set the strategy to use for the resources archive lookup.

Parameters
archiveIndexStrategy:String

The strategy to use for the resources archive lookup

setCacheMaxSizeback to summary
public void setCacheMaxSize(long cacheMaxSize)

Set the maximum permitted size for the cache.

Parameters
cacheMaxSize:long

Maximum cache size in kilobytes

setCacheObjectMaxSizeback to summary
public void setCacheObjectMaxSize(int cacheObjectMaxSize)

Set the maximum permitted size for a single object in the cache. Note that the maximum size in bytes may not exceed Integer#MAX_VALUE.

Parameters
cacheObjectMaxSize:int

Maximum size for a single cached object in kilobytes

setCacheStrategyback to summary
public default void setCacheStrategy(WebResourceRoot.CacheStrategy strategy)

Set the current caching strategy.

The default implementation is a NO-OP. Sub-classes wishing to utilise a CacheStrategy should provide an appropriate implementation.

Parameters
strategy:WebResourceRoot.CacheStrategy

The new strategy to use or null for no strategy

setCacheTtlback to summary
public void setCacheTtl(long ttl)

Set the Time-To-Live (TTL) for cache entries.

Parameters
ttl:long

TTL in milliseconds

setCachingAllowedback to summary
public void setCachingAllowed(boolean cachingAllowed)

Set whether or not caching is permitted for this web application.

Parameters
cachingAllowed:boolean

true to enable caching, else false

setContextback to summary
public void setContext(Context context)

Set the web application this WebResourceRoot is associated with.

Parameters
context:Context

the associated context

setTrackLockedFilesback to summary
public void setTrackLockedFiles(boolean trackLockedFiles)

Controls whether the track locked files feature is enabled. If enabled, all calls to methods that return objects that lock a file and need to be closed to release that lock (e.g. WebResource#getInputStream() will perform a number of additional tasks.

  • The stack trace at the point where the method was called will be recorded and associated with the returned object.
  • The returned object will be wrapped so that the point where close() (or equivalent) is called to release the resources can be detected. Tracking of the object will cease once the resources have been released.
  • All remaining locked resources on web application shutdown will be logged and then closed.
Parameters
trackLockedFiles:boolean

true to enable it, false to disable it

writeback to summary
public boolean write(String path, InputStream is, boolean overwrite)

Create a new resource at the requested path using the provided InputStream.

Parameters
path:String

The path to be used for the new Resource. It is relative to the root of the web application and must start with '/'.

is:InputStream

The InputStream that will provide the content for the new Resource.

overwrite:boolean

If true and the resource already exists it will be overwritten. If false and the resource already exists the write will fail.

Returns:boolean

true if and only if the new Resource is written

org.apache.catalina back to summary

public final Enum WebResourceRoot.ArchiveIndexStrategy

extends Enum<WebResourceRoot.ArchiveIndexStrategy>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final WebResourceRoot.ArchiveIndexStrategy
public static final WebResourceRoot.ArchiveIndexStrategy
private final boolean
public static final WebResourceRoot.ArchiveIndexStrategy
private final boolean

Constructor Summary

AccessConstructor and Description
private
ArchiveIndexStrategy(boolean usesBloom, boolean retain)

Method Summary

Modifier and TypeMethod and Description
public boolean
public boolean
public static WebResourceRoot.ArchiveIndexStrategy
public static WebResourceRoot.ArchiveIndexStrategy[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BLOOMback to summary
public static final WebResourceRoot.ArchiveIndexStrategy BLOOM
PURGEDback to summary
public static final WebResourceRoot.ArchiveIndexStrategy PURGED
retainback to summary
private final boolean retain
SIMPLEback to summary
public static final WebResourceRoot.ArchiveIndexStrategy SIMPLE
usesBloomback to summary
private final boolean usesBloom

Constructor Detail

ArchiveIndexStrategyback to summary
private ArchiveIndexStrategy(boolean usesBloom, boolean retain)

Method Detail

getRetainback to summary
public boolean getRetain()
getUsesBloomback to summary
public boolean getUsesBloom()
valueOfback to summary
public static WebResourceRoot.ArchiveIndexStrategy valueOf(String name)
valuesback to summary
public static WebResourceRoot.ArchiveIndexStrategy[] values()
org.apache.catalina back to summary

public Interface WebResourceRoot.CacheStrategy


Provides a mechanism to modify the caching behaviour.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the result should not be cached, otherwise false
noCache
(String
The path to check against the strategy to see if the result should be cached
path
)

Should the result of looking up the resource at the given path be excluded from caching?

Method Detail

noCacheback to summary
public boolean noCache(String path)

Should the result of looking up the resource at the given path be excluded from caching?

Parameters
path:String

The path to check against the strategy to see if the result should be cached

Returns:boolean

true if the result should not be cached, otherwise false

org.apache.catalina back to summary

public final Enum WebResourceRoot.ResourceSetType

extends Enum<WebResourceRoot.ResourceSetType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final WebResourceRoot.ResourceSetType
public static final WebResourceRoot.ResourceSetType
public static final WebResourceRoot.ResourceSetType
public static final WebResourceRoot.ResourceSetType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static WebResourceRoot.ResourceSetType
public static WebResourceRoot.ResourceSetType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CLASSES_JARback to summary
public static final WebResourceRoot.ResourceSetType CLASSES_JAR
POSTback to summary
public static final WebResourceRoot.ResourceSetType POST
PREback to summary
public static final WebResourceRoot.ResourceSetType PRE
RESOURCE_JARback to summary
public static final WebResourceRoot.ResourceSetType RESOURCE_JAR

Constructor Detail

ResourceSetTypeback to summary
private ResourceSetType()

Method Detail

valueOfback to summary
public static WebResourceRoot.ResourceSetType valueOf(String name)
valuesback to summary
public static WebResourceRoot.ResourceSetType[] values()