public class ResourceHandlerBuilder extends Object implements MuHandlerBuilder<ResourceHandler>
Used to create a ResourceHandler
for serving static files.
In order to serve from the filesystem during development, and from classpath and deploy time, see
fileOrClasspath(String, String)
Constructor and Description |
---|
ResourceHandlerBuilder() |
Modifier and Type | Method and Description |
---|---|
ResourceHandler |
build()
Creates the handler
|
static ResourceHandlerBuilder |
classpathHandler(String classpathRoot)
Creates a handler that serves files from the classpath..
|
static ResourceHandlerBuilder |
fileHandler(File baseDirectory)
Creates a handler that serves files from the given directory.
|
static ResourceHandlerBuilder |
fileHandler(Path path)
Creates a handler that serves files from the given directory.
|
static ResourceHandlerBuilder |
fileHandler(String directoryPath)
Creates a handler that serves files from the given directory.
|
static ResourceHandlerBuilder |
fileOrClasspath(String fileRootIfExists,
String classpathRoot)
Creates a resource handler that serves from the file system if the directory exists; otherwise from the class path.
|
ResourceHandlerBuilder |
withDefaultFile(String defaultFile)
Specifies the file to use when a request such as
/web/ is made. |
ResourceHandlerBuilder |
withExtensionToResourceType(Map<String,ResourceType> extensionToResourceType)
Specify custom filename extension to mime-type mappings.
|
ResourceHandlerBuilder |
withPathToServeFrom(String pathToServeFrom)
Deprecated.
Please use
ContextHandlerBuilder.context(pathToServeFrom).addHandler(resourceHandler) instead. |
public ResourceHandlerBuilder withExtensionToResourceType(Map<String,ResourceType> extensionToResourceType)
ResourceType.DEFAULT_EXTENSION_MAPPINGS
are used.extensionToResourceType
- The mappings to use.@Deprecated public ResourceHandlerBuilder withPathToServeFrom(String pathToServeFrom)
ContextHandlerBuilder.context(pathToServeFrom).addHandler(resourceHandler)
instead.pathToServeFrom
- A path that static data should be served from. Defaults to /
public ResourceHandlerBuilder withDefaultFile(String defaultFile)
/web/
is made. Defaults to index.html
defaultFile
- The default file to use when a directory is requestedpublic ResourceHandler build()
build
in interface MuHandlerBuilder<ResourceHandler>
public static ResourceHandlerBuilder fileHandler(String directoryPath)
directoryPath
- The directory.public static ResourceHandlerBuilder fileHandler(File baseDirectory)
baseDirectory
- The directory.public static ResourceHandlerBuilder fileHandler(Path path)
path
- The directory.public static ResourceHandlerBuilder classpathHandler(String classpathRoot)
classpathRoot
- A classpath directory, such as /web
public static ResourceHandlerBuilder fileOrClasspath(String fileRootIfExists, String classpathRoot)
A common use case is for when you want to serve from the file path at development time (so you can update files without restarting) but at deploy time resources are packaged in an uber jar.
fileRootIfExists
- A path to a directory holding static content, which may not exist, e.g. src/main/resources/web
classpathRoot
- A classpath path to a directory holding static content, e.g. /web
Copyright © 2017–2019. All rights reserved.