Top Description Inners Fields Constructors Methods
io.undertow.server.handlers.resource

public Class PathResourceManager

extends Object
implements ResourceManager
Class Inheritance
All Implemented Interfaces
io.undertow.server.handlers.resource.ResourceManager, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
io.undertow.server.handlers.resource.FileResourceManager
Imports
io.undertow.UndertowLogger, .UndertowMessages, io.undertow.util.ETag, org.jboss.logging.Logger, org.xnio.FileChangeCallback, .FileChangeEvent, .FileSystemWatcher, .OptionMap, .Xnio, java.io.File, .IOException, java.nio.file.FileSystem, .FileSystems, .Files, .LinkOption, .Path, java.util.ArrayList, .Arrays, .Collection, .List, .TreeSet

Serves files from the file system.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static interface
private static class

Field Summary

Modifier and TypeField and Description
private final boolean
protected volatile String
private final boolean
caseSensitive

Check to validate caseSensitive issues for specific case-insensitive FS.

private static final boolean
private static final long
private final PathResourceManager.ETagFunction
protected volatile FileSystem
private FileSystemWatcher
private final boolean
followLinks

Check to allow follow symbolic links

private final List<ResourceChangeListener>
private static final Logger
private static final PathResourceManager.ETagFunction
private final TreeSet<String>
safePaths

Used if followLinks == true.

private final long
transferMinSize

Size to use direct FS to network transfer (if supported by OS/JDK) instead of read/write

Constructor Summary

AccessConstructor and Description
public
public
PathResourceManager(final Path base, long transferMinSize)

public
PathResourceManager(final Path base, long transferMinSize, boolean caseSensitive)

public
PathResourceManager(final Path base, long transferMinSize, boolean followLinks, final String... safePaths)

protected
PathResourceManager(long transferMinSize, boolean caseSensitive, boolean followLinks, final String... safePaths)

protected
PathResourceManager(long transferMinSize, boolean caseSensitive, boolean followLinks, boolean allowResourceChangeListeners, final String... safePaths)

public
PathResourceManager(final Path base, long transferMinSize, boolean caseSensitive, boolean followLinks, final String... safePaths)

public
PathResourceManager(final Path base, long transferMinSize, boolean caseSensitive, boolean followLinks, boolean allowResourceChangeListeners, final String... safePaths)

private

Method Summary

Modifier and TypeMethod and Description
public static PathResourceManager.Builder
public synchronized void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public Path
protected PathResource
getFileResource(final Path file, final String path, final Path symlinkBase, String normalizedFile)

Apply security check for case insensitive file systems.

public Resource
getResource(final String
The path
p
)

Implements io.undertow.server.handlers.resource.ResourceManager.getResource.

Returns a resource for the given path.

private PathResourceManager.SymlinkResult
getSymlinkBase(final String base, final Path file)

Returns true is some element of path inside base path is a symlink.

public long
private boolean
isFileSameCase(final Path file, String normalizeFile)

Security check for case insensitive file systems.

public boolean
private boolean
isSymlinkSafe(final Path file)

Security check for followSymlinks feature.

public synchronized void
registerResourceChangeListener(ResourceChangeListener
The listener to register
listener
)

Implements io.undertow.server.handlers.resource.ResourceManager.registerResourceChangeListener.

Registers a resource change listener, if the underlying resource manager support it

public synchronized void
public PathResourceManager
setBase(final Path base)

public PathResourceManager
setBase(final File base)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowResourceChangeListenersback to summary
private final boolean allowResourceChangeListeners
baseback to summary
protected volatile String base
caseSensitiveback to summary
private final boolean caseSensitive

Check to validate caseSensitive issues for specific case-insensitive FS.

See Also
io.undertow.server.handlers.resource.PathResourceManager#isFileSameCase(java.nio.file.Path, String)
DEFAULT_CHANGE_LISTENERS_ALLOWEDback to summary
private static final boolean DEFAULT_CHANGE_LISTENERS_ALLOWED
DEFAULT_TRANSFER_MIN_SIZEback to summary
private static final long DEFAULT_TRANSFER_MIN_SIZE
eTagFunctionback to summary
private final PathResourceManager.ETagFunction eTagFunction
fileSystemback to summary
protected volatile FileSystem fileSystem
fileSystemWatcherback to summary
private FileSystemWatcher fileSystemWatcher
listenersback to summary
private final List<ResourceChangeListener> listeners
logback to summary
private static final Logger log
NULL_ETAG_FUNCTIONback to summary
private static final PathResourceManager.ETagFunction NULL_ETAG_FUNCTION
safePathsback to summary
private final TreeSet<String> safePaths

Used if followLinks == true. Set of paths valid to follow symbolic links. If this is empty and followLinks it true then all links will be followed

transferMinSizeback to summary
private final long transferMinSize

Size to use direct FS to network transfer (if supported by OS/JDK) instead of read/write

Constructor Detail

PathResourceManagerback to summary
public PathResourceManager(final Path base)
PathResourceManagerback to summary
public PathResourceManager(final Path base, long transferMinSize)
PathResourceManagerback to summary
public PathResourceManager(final Path base, long transferMinSize, boolean caseSensitive)
PathResourceManagerback to summary
public PathResourceManager(final Path base, long transferMinSize, boolean followLinks, final String... safePaths)
PathResourceManagerback to summary
protected PathResourceManager(long transferMinSize, boolean caseSensitive, boolean followLinks, final String... safePaths)
PathResourceManagerback to summary
protected PathResourceManager(long transferMinSize, boolean caseSensitive, boolean followLinks, boolean allowResourceChangeListeners, final String... safePaths)
PathResourceManagerback to summary
public PathResourceManager(final Path base, long transferMinSize, boolean caseSensitive, boolean followLinks, final String... safePaths)
PathResourceManagerback to summary
public PathResourceManager(final Path base, long transferMinSize, boolean caseSensitive, boolean followLinks, boolean allowResourceChangeListeners, final String... safePaths)
PathResourceManagerback to summary
private PathResourceManager(PathResourceManager.Builder builder)

Method Detail

builderback to summary
public static PathResourceManager.Builder builder()
closeback to summary
public synchronized void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
getBasePathback to summary
public Path getBasePath()
getFileResourceback to summary
protected PathResource getFileResource(final Path file, final String path, final Path symlinkBase, String normalizedFile) throws IOException

Apply security check for case insensitive file systems.

getResourceback to summary
public Resource getResource(final String p)

Implements io.undertow.server.handlers.resource.ResourceManager.getResource.

Doc from io.undertow.server.handlers.resource.ResourceManager.getResource.

Returns a resource for the given path. It is the responsibility of the called to make sure that the path in Canonicalised.

Parameters
p:String

The path

Returns:Resource

The resource representing the path, or null if no resource was found.

getSymlinkBaseback to summary
private PathResourceManager.SymlinkResult getSymlinkBase(final String base, final Path file)

Returns true is some element of path inside base path is a symlink.

getTransferMinSizeback to summary
public long getTransferMinSize()
isFileSameCaseback to summary
private boolean isFileSameCase(final Path file, String normalizeFile) throws IOException

Security check for case insensitive file systems. We make sure the case of the filename matches the case of the request. This is only a check for case sensitivity, not for non canonical . and ../ which are allowed. For example: file.getName() == "page.jsp" && file.getCanonicalFile().getName() == "page.jsp" should return true file.getName() == "page.jsp" && file.getCanonicalFile().getName() == "page.JSP" should return false file.getName() == "./page.jsp" && file.getCanonicalFile().getName() == "page.jsp" should return true

isResourceChangeListenerSupportedback to summary
public boolean isResourceChangeListenerSupported()

Implements io.undertow.server.handlers.resource.ResourceManager.isResourceChangeListenerSupported.

Returns:boolean

Doc from io.undertow.server.handlers.resource.ResourceManager.isResourceChangeListenerSupported.

true if a resource change listener is supported

Annotations
@Override
isSymlinkSafeback to summary
private boolean isSymlinkSafe(final Path file) throws IOException

Security check for followSymlinks feature. Only follows those symbolink links defined in safePaths.

registerResourceChangeListenerback to summary
public synchronized void registerResourceChangeListener(ResourceChangeListener listener)

Implements io.undertow.server.handlers.resource.ResourceManager.registerResourceChangeListener.

Doc from io.undertow.server.handlers.resource.ResourceManager.registerResourceChangeListener.

Registers a resource change listener, if the underlying resource manager support it

Parameters
listener:ResourceChangeListener

The listener to register

Annotations
@Override
removeResourceChangeListenerback to summary
public synchronized void removeResourceChangeListener(ResourceChangeListener listener)

Implements io.undertow.server.handlers.resource.ResourceManager.removeResourceChangeListener.

Doc from io.undertow.server.handlers.resource.ResourceManager.removeResourceChangeListener.

Removes a resource change listener

Annotations
@Override
setBaseback to summary
public PathResourceManager setBase(final Path base)
setBaseback to summary
public PathResourceManager setBase(final File base)
io.undertow.server.handlers.resource back to summary

public final Class PathResourceManager.Builder

extends Object
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.resource.PathResourceManager.Builder

Field Summary

Modifier and TypeField and Description
private boolean
private Path
private boolean
private PathResourceManager.ETagFunction
private boolean
private String[]
private long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public ResourceManager
public PathResourceManager.Builder
setAllowResourceChangeListeners(boolean allowResourceChangeListeners)

public PathResourceManager.Builder
setBase(Path base)

public PathResourceManager.Builder
setCaseSensitive(boolean caseSensitive)

public PathResourceManager.Builder
public PathResourceManager.Builder
setSafePaths(String[] safePaths)

public PathResourceManager.Builder
setTransferMinSize(long transferMinSize)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowResourceChangeListenersback to summary
private boolean allowResourceChangeListeners
baseback to summary
private Path base
caseSensitiveback to summary
private boolean caseSensitive
eTagFunctionback to summary
private PathResourceManager.ETagFunction eTagFunction
safePathsback to summary
private String[] safePaths
transferMinSizeback to summary
private long transferMinSize

Constructor Detail

Builderback to summary
private Builder()

Method Detail

buildback to summary
public ResourceManager build()
setAllowResourceChangeListenersback to summary
public PathResourceManager.Builder setAllowResourceChangeListeners(boolean allowResourceChangeListeners)
setBaseback to summary
public PathResourceManager.Builder setBase(Path base)
setCaseSensitiveback to summary
public PathResourceManager.Builder setCaseSensitive(boolean caseSensitive)
setETagFunctionback to summary
public PathResourceManager.Builder setETagFunction(PathResourceManager.ETagFunction eTagFunction)
setSafePathsback to summary
public PathResourceManager.Builder setSafePaths(String[] safePaths)
setTransferMinSizeback to summary
public PathResourceManager.Builder setTransferMinSize(long transferMinSize)
io.undertow.server.handlers.resource back to summary

public Interface PathResourceManager.ETagFunction


Method Summary

Modifier and TypeMethod and Description
public ETag

Returns:

ETag representing the provided path, or null
generate
(Path
Path for which to generate an ETag
path
)

Generates an ETag for the provided Path.

Method Detail

generateback to summary
public ETag generate(Path path)

Generates an ETag for the provided Path.

Parameters
path:Path

Path for which to generate an ETag

Returns:ETag

ETag representing the provided path, or null

io.undertow.server.handlers.resource back to summary

private Class PathResourceManager.SymlinkResult

extends Object
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.resource.PathResourceManager.SymlinkResult

Field Summary

Modifier and TypeField and Description
public final Path
public final boolean

Constructor Summary

AccessConstructor and Description
private
SymlinkResult(boolean requiresCheck, Path path)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

pathback to summary
public final Path path
requiresCheckback to summary
public final boolean requiresCheck

Constructor Detail

SymlinkResultback to summary
private SymlinkResult(boolean requiresCheck, Path path)