Class StaticHandler<A extends ExchangeContext>
- Type Parameters:
A- the exchange context type
- All Implemented Interfaces:
ExchangeHandler<A,,WebExchange<A>> ReactiveExchangeHandler<A,WebExchange<A>>
A static handler used to serve static resources resolved from a base resource.
This handler is typically used as a handler in a Web route to serve static content. It uses a configurable path parameter to determine the path of the resource to serve relative to the base path.
WebRouter router = ...
router
.route()
.path("/static/{path:.*}")
.handler(new StaticHandler<>(new FileResource("/path/to/resources/"));
- Since:
- 1.0
- Author:
- Jeremy Kuhn
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionStaticHandler(Resource baseResource) Creates a static handler resolving resources from the specified base resource using the default path parameter name and welcome page.StaticHandler(Resource baseResource, String pathParameterName) Creates a static handler resolving resources from the specified base resource using the specified path parameter name. -
Method Summary
Modifier and TypeMethodDescriptionvoidhandle(WebExchange<A> exchange) Processes the specified server exchange.voidsetPathParameterName(String pathParameterName) Sets the name of the path parameter that specifies the path of a resource relative to the base path.voidsetWelcomePage(String welcomePage) Sets the name of the welcome page file to look for when a directory resource is requested.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.inverno.mod.http.server.ExchangeHandler
deferMethods inherited from interface io.inverno.mod.http.server.ReactiveExchangeHandler
intercept
-
Field Details
-
DEFAULT_PATH_PARAMETER_NAME
The default name of the path parameter defining the path to the resource.- See Also:
-
DEFAULT_WELCOME_PAGE
The default welcome page file name:index.html.- See Also:
-
-
Constructor Details
-
StaticHandler
Creates a static handler resolving resources from the specified base resource using the default path parameter name and welcome page.
- Parameters:
baseResource- the base resource- See Also:
-
StaticHandler
Creates a static handler resolving resources from the specified base resource using the specified path parameter name.
- Parameters:
baseResource- the base resourcepathParameterName- the path parameter name- See Also:
-
-
Method Details
-
setPathParameterName
Sets the name of the path parameter that specifies the path of a resource relative to the base path.
- Parameters:
pathParameterName- a path parameter name
-
setWelcomePage
Sets the name of the welcome page file to look for when a directory resource is requested.
- Parameters:
welcomePage- a file name
-
handle
Description copied from interface:ExchangeHandlerProcesses the specified server exchange.
This method is more convenient than
ExchangeHandler.defer(io.inverno.mod.http.server.Exchange)when the handling logic does not need to be reactive.- Specified by:
handlein interfaceExchangeHandler<A extends ExchangeContext,WebExchange<A extends ExchangeContext>> - Parameters:
exchange- the exchange to process- Throws:
HttpException- if an error occurs during the processing of the exchange
-