Package io.muserver.handlers
Class ResourceHandler
- java.lang.Object
-
- io.muserver.handlers.ResourceHandler
-
- All Implemented Interfaces:
MuHandler
public class ResourceHandler extends java.lang.Object implements MuHandler
A handler to serve static content. To create a handler, usingResourceHandlerBuilder.fileOrClasspath(String, String)
,ResourceHandlerBuilder.classpathHandler(String)
,ResourceHandlerBuilder.fileHandler(File)
or one of its variants.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ResourceHandler.Builder
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static ResourceHandler.Builder
classpathHandler(java.lang.String classpathRoot)
Deprecated.static ResourceHandler.Builder
fileHandler(java.io.File baseDirectory)
Deprecated.static ResourceHandler.Builder
fileHandler(java.lang.String directoryPath)
Deprecated.static ResourceHandler.Builder
fileHandler(java.nio.file.Path path)
Deprecated.static ResourceHandler.Builder
fileOrClasspath(java.lang.String fileRootIfExists, java.lang.String classpathRoot)
Deprecated.java.lang.String
getPathToServeFrom()
Deprecated.This is a temporary accessor which will be demised.boolean
handle(MuRequest request, MuResponse response)
Called when an HTTP request is made (unless a previous handler stopped handler processing)java.lang.String
toString()
-
-
-
Method Detail
-
handle
public boolean handle(MuRequest request, MuResponse response) throws java.io.IOException
Description copied from interface:MuHandler
Called when an HTTP request is made (unless a previous handler stopped handler processing)- Specified by:
handle
in interfaceMuHandler
- Parameters:
request
- The HTTP request.response
- The HTTP response.- Returns:
- Return
false
to continue processing the next handler (for example if writing a filter or inspector); ortrue
to stop processing (normally done if this handler sent a response). - Throws:
java.io.IOException
-
getPathToServeFrom
@Deprecated public java.lang.String getPathToServeFrom()
Deprecated.This is a temporary accessor which will be demised. Do not use this.- Returns:
- This is a temporary accessor which will be demised. Do not use this.
-
fileHandler
@Deprecated public static ResourceHandler.Builder fileHandler(java.lang.String directoryPath)
Deprecated.Creates a handler that serves files from the given directory.- Parameters:
directoryPath
- The directory.- Returns:
- A new builder.
-
fileHandler
@Deprecated public static ResourceHandler.Builder fileHandler(java.io.File baseDirectory)
Deprecated.Creates a handler that serves files from the given directory.- Parameters:
baseDirectory
- The directory.- Returns:
- A new builder.
-
fileHandler
@Deprecated public static ResourceHandler.Builder fileHandler(java.nio.file.Path path)
Deprecated.Creates a handler that serves files from the given directory.- Parameters:
path
- The directory.- Returns:
- A new builder.
-
classpathHandler
@Deprecated public static ResourceHandler.Builder classpathHandler(java.lang.String classpathRoot)
Deprecated.Creates a handler that serves files from the classpath..- Parameters:
classpathRoot
- A classpath directory, such as/web
- Returns:
- A new builder.
-
fileOrClasspath
@Deprecated public static ResourceHandler.Builder fileOrClasspath(java.lang.String fileRootIfExists, java.lang.String classpathRoot)
Deprecated.Creates a resource handler that serves from the file system if the directory exists; otherwise from the class path.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.
- Parameters:
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
- Returns:
- Returns a file-based resource handler builder or a classpath-based one.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-